This commit is contained in:
Niels Andriesse 2019-09-12 09:59:15 +10:00
parent 3b242e7435
commit 52b55652c8
6 changed files with 37 additions and 48 deletions

View File

@ -478,16 +478,14 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
} }
} }
private void createGroupChatPollersIfNeeded() { private void createGroupChatPollersIfNeeded() {
// Only add the public chat poller if we have the thread // Only create the group chat pollers if their threads aren't deleted
LokiGroupChat publicChat = lokiPublicChat(); LokiGroupChat publicChat = lokiPublicChat();
long threadId = GroupManager.getThreadId(publicChat.getId(), this); long threadID = GroupManager.getThreadId(publicChat.getId(), this);
if (threadId >= 0 && lokiPublicChatPoller == null) { if (threadID >= 0 && lokiPublicChatPoller == null) {
lokiPublicChatPoller = new LokiGroupChatPoller(this, publicChat); lokiPublicChatPoller = new LokiGroupChatPoller(this, publicChat);
// Set up deletion listeners if needed
// Attach a deletion listener to the thread if we have it setUpThreadDeletionListeners(threadID, () -> {
setupThreadDeletionListeners(threadId, () -> {
if (lokiPublicChatPoller != null) lokiPublicChatPoller.stop(); if (lokiPublicChatPoller != null) lokiPublicChatPoller.stop();
lokiPublicChatPoller = null; lokiPublicChatPoller = null;
}); });
@ -495,43 +493,42 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
} }
private void createRSSFeedPollersIfNeeded() { private void createRSSFeedPollersIfNeeded() {
// Only add the feed poller if we have the thread // Only create the RSS feed pollers if their threads aren't deleted
LokiRSSFeed lokiNewsFeed = lokiNewsFeed(); LokiRSSFeed lokiNewsFeed = lokiNewsFeed();
long lokiNewsFeedThreadId = GroupManager.getThreadId(lokiNewsFeed.getId(), this); long lokiNewsFeedThreadID = GroupManager.getThreadId(lokiNewsFeed.getId(), this);
if (lokiNewsFeedThreadId >= 0 && lokiNewsFeedPoller == null) { if (lokiNewsFeedThreadID >= 0 && lokiNewsFeedPoller == null) {
lokiNewsFeedPoller = new LokiRSSFeedPoller(this, lokiNewsFeed); lokiNewsFeedPoller = new LokiRSSFeedPoller(this, lokiNewsFeed);
// Set up deletion listeners if needed
// Attach a deletion listener to the thread if we have it setUpThreadDeletionListeners(lokiNewsFeedThreadID, () -> {
setupThreadDeletionListeners(lokiNewsFeedThreadId, () -> {
if (lokiNewsFeedPoller != null) lokiNewsFeedPoller.stop(); if (lokiNewsFeedPoller != null) lokiNewsFeedPoller.stop();
lokiNewsFeedPoller = null; lokiNewsFeedPoller = null;
}); });
} }
// The user can't delete the Loki Messenger Updates RSS feed
// This one is not stoppable if (lokiMessengerUpdatesFeedPoller == null) {
if (lokiMessengerUpdatesFeedPoller == null) { lokiMessengerUpdatesFeedPoller = new LokiRSSFeedPoller(this, lokiMessengerUpdatesFeed()); } lokiMessengerUpdatesFeedPoller = new LokiRSSFeedPoller(this, lokiMessengerUpdatesFeed());
}
} }
private void setupThreadDeletionListeners(long threadId, Runnable onDelete) { private void setUpThreadDeletionListeners(long threadID, Runnable onDelete) {
if (threadId < 0) { return; } if (threadID < 0) { return; }
ContentObserver observer = new ContentObserver(null) { ContentObserver observer = new ContentObserver(null) {
@Override @Override
public void onChange(boolean selfChange) { public void onChange(boolean selfChange) {
super.onChange(selfChange); super.onChange(selfChange);
// Stop the poller if thread is deleted
// Stop the poller if thread doesn't exist
try { try {
if (!DatabaseFactory.getThreadDatabase(getApplicationContext()).hasThread(threadId)) { if (!DatabaseFactory.getThreadDatabase(getApplicationContext()).hasThread(threadID)) {
onDelete.run(); onDelete.run();
getContentResolver().unregisterContentObserver(this); getContentResolver().unregisterContentObserver(this);
} }
} catch (Exception e) { } catch (Exception e) {
// Failed to call delete // TODO: Handle
} }
} }
}; };
this.getContentResolver().registerContentObserver(DatabaseContentProviders.Conversation.getUriForThread(threadId), true, observer); this.getContentResolver().registerContentObserver(DatabaseContentProviders.Conversation.getUriForThread(threadID), true, observer);
} }
public void startGroupChatPollersIfNeeded() { public void startGroupChatPollersIfNeeded() {

View File

@ -2101,10 +2101,8 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
Context context = ConversationActivity.this; Context context = ConversationActivity.this;
List<MarkedMessageInfo> messageIds = DatabaseFactory.getThreadDatabase(context).setRead(params[0], false); List<MarkedMessageInfo> messageIds = DatabaseFactory.getThreadDatabase(context).setRead(params[0], false);
// Only notify on private chats // Only send notifications for private chats
if (!getRecipient().isGroupRecipient()) { if (!getRecipient().isGroupRecipient()) { MessageNotifier.updateNotification(context); }
MessageNotifier.updateNotification(context);
}
MarkReadReceiver.process(context, messageIds); MarkReadReceiver.process(context, messageIds);

View File

@ -477,10 +477,7 @@ public class ThreadDatabase extends Database {
Cursor cursor = db.query(TABLE_NAME, new String[]{ ID }, ID_WHERE, new String[]{ String.valueOf(threadId) }, null, null, null); Cursor cursor = db.query(TABLE_NAME, new String[]{ ID }, ID_WHERE, new String[]{ String.valueOf(threadId) }, null, null, null);
try { try {
if (cursor != null && cursor.moveToFirst()) { if (cursor != null && cursor.moveToFirst()) { return true; }
return true;
}
return false; return false;
} finally { } finally {
if (cursor != null) cursor.close(); if (cursor != null) cursor.close();

View File

@ -812,8 +812,8 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
database.endTransaction(); database.endTransaction();
} }
// Loki - Map message id to server id // Loki - Store message server ID
updatePublicChatMessageWithServerID(messageServerIDOrNull, insertResult); updateGroupChatMessageServerID(messageServerIDOrNull, insertResult);
if (insertResult.isPresent()) { if (insertResult.isPresent()) {
MessageNotifier.updateNotification(context, insertResult.get().getThreadId()); MessageNotifier.updateNotification(context, insertResult.get().getThreadId());
@ -982,8 +982,8 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
if (smsMessageId.isPresent()) database.deleteMessage(smsMessageId.get()); if (smsMessageId.isPresent()) database.deleteMessage(smsMessageId.get());
// Loki - Map message id to server id // Loki - Store message server ID
updatePublicChatMessageWithServerID(messageServerIDOrNull, insertResult); updateGroupChatMessageServerID(messageServerIDOrNull, insertResult);
boolean isGroupMessage = message.getGroupInfo().isPresent(); boolean isGroupMessage = message.getGroupInfo().isPresent();
if (threadId != null && !isGroupMessage) { if (threadId != null && !isGroupMessage) {
@ -993,10 +993,9 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
} }
} }
private void updatePublicChatMessageWithServerID(Optional<Long> messageServerIDOrNull, Optional<InsertResult> databaseInsert) { private void updateGroupChatMessageServerID(Optional<Long> messageServerIDOrNull, Optional<InsertResult> insertResult) {
if (messageServerIDOrNull == null) { return; } if (insertResult.isPresent() && messageServerIDOrNull.isPresent()) {
if (databaseInsert.isPresent() && messageServerIDOrNull.isPresent()) { long messageID = insertResult.get().getMessageId();
long messageID = databaseInsert.get().getMessageId();
long messageServerID = messageServerIDOrNull.get(); long messageServerID = messageServerIDOrNull.get();
DatabaseFactory.getLokiMessageDatabase(context).setServerID(messageID, messageServerID); DatabaseFactory.getLokiMessageDatabase(context).setServerID(messageID, messageServerID);
} }

View File

@ -388,10 +388,8 @@ public class MessageNotifier {
} }
private static void sendInThreadNotification(Context context, Recipient recipient) { private static void sendInThreadNotification(Context context, Recipient recipient) {
// Keep group messages muted! // Mute group chats
if (recipient.isGroupRecipient()) { if (recipient.isGroupRecipient()) { return; }
return;
}
if (!TextSecurePreferences.isInThreadNotifications(context) || if (!TextSecurePreferences.isInThreadNotifications(context) ||
ServiceUtil.getAudioManager(context).getRingerMode() != AudioManager.RINGER_MODE_NORMAL) ServiceUtil.getAudioManager(context).getRingerMode() != AudioManager.RINGER_MODE_NORMAL)