From 9d8de789d7731f13265013a93176e11e51100b79 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Tue, 10 Sep 2019 13:43:56 +1000 Subject: [PATCH 1/6] Fixed link preview messages not being deleted in group chats. --- .../securesms/jobs/PushDecryptJob.java | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java index e23f87b8a2..2d4a6577ed 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java @@ -780,6 +780,10 @@ public class PushDecryptJob extends BaseJob implements InjectableType { } private void handleMediaMessage(@NonNull SignalServiceContent content, @NonNull IncomingMediaMessage mediaMessage, @NonNull Optional smsMessageID) throws StorageFailedException { + handleMediaMessage(content, mediaMessage, smsMessageID, null); + } + + private void handleMediaMessage(@NonNull SignalServiceContent content, @NonNull IncomingMediaMessage mediaMessage, @NonNull Optional smsMessageID, @Nullable Optional messageServerIDOrNull) throws StorageFailedException { MmsDatabase database = DatabaseFactory.getMmsDatabase(context); database.beginTransaction(); @@ -811,6 +815,9 @@ public class PushDecryptJob extends BaseJob implements InjectableType { database.endTransaction(); } + // Loki - Map message id to server id + updatePublicChatMessageWithServerID(messageServerIDOrNull, insertResult); + if (insertResult.isPresent()) { MessageNotifier.updateNotification(context, insertResult.get().getThreadId()); } @@ -963,7 +970,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType { if (lp.isPresent()) { mediaMessage.getLinkPreviews().add(lp.get()); } if (c == urlCount) { try { - handleMediaMessage(content, mediaMessage, smsMessageId); + handleMediaMessage(content, mediaMessage, smsMessageId, messageServerIDOrNull); } catch (Exception e) { // TODO: Handle } @@ -978,11 +985,8 @@ public class PushDecryptJob extends BaseJob implements InjectableType { if (smsMessageId.isPresent()) database.deleteMessage(smsMessageId.get()); - if (insertResult.isPresent() && messageServerIDOrNull.isPresent()) { - long messageID = insertResult.get().getMessageId(); - long messageServerID = messageServerIDOrNull.get(); - DatabaseFactory.getLokiMessageDatabase(context).setServerID(messageID, messageServerID); - } + // Loki - Map message id to server id + updatePublicChatMessageWithServerID(messageServerIDOrNull, insertResult); if (threadId != null) { MessageNotifier.updateNotification(context, threadId); @@ -991,6 +995,15 @@ public class PushDecryptJob extends BaseJob implements InjectableType { } } + private void updatePublicChatMessageWithServerID(@Nullable Optional messageServerIDOrNull, Optional databaseInsert) { + if (messageServerIDOrNull == null) { return; } + if (databaseInsert.isPresent() && messageServerIDOrNull.isPresent()) { + long messageID = databaseInsert.get().getMessageId(); + long messageServerID = messageServerIDOrNull.get(); + DatabaseFactory.getLokiMessageDatabase(context).setServerID(messageID, messageServerID); + } + } + private void acceptFriendRequestIfNeeded(@NonNull SignalServiceEnvelope envelope, @NonNull SignalServiceContent content) { // If we get anything other than a friend request, we can assume that we have a session with the other user if (envelope.isFriendRequest()) { return; } From c738f810b5ae7c31cc0cd8feda0a190c487ff578 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Tue, 10 Sep 2019 15:06:38 +1000 Subject: [PATCH 2/6] Fix constant group update notifications being shown --- .../thoughtcrime/securesms/groups/GroupManager.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/org/thoughtcrime/securesms/groups/GroupManager.java b/src/org/thoughtcrime/securesms/groups/GroupManager.java index 31c22d0ab1..033384dc9d 100644 --- a/src/org/thoughtcrime/securesms/groups/GroupManager.java +++ b/src/org/thoughtcrime/securesms/groups/GroupManager.java @@ -63,6 +63,16 @@ public class GroupManager { memberAddresses.add(Address.fromSerialized(TextSecurePreferences.getLocalNumber(context))); groupDatabase.create(groupId, name, new LinkedList<>(memberAddresses), null, null); + if (!mms) { + groupDatabase.updateAvatar(groupId, avatarBytes); + DatabaseFactory.getRecipientDatabase(context).setProfileSharing(groupRecipient, true); + } + + long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(groupRecipient, ThreadDatabase.DistributionTypes.CONVERSATION); + return new GroupActionResult(groupRecipient, threadId); + + /* Loki: Original Code + ================== if (!mms) { groupDatabase.updateAvatar(groupId, avatarBytes); DatabaseFactory.getRecipientDatabase(context).setProfileSharing(groupRecipient, true); @@ -71,6 +81,7 @@ public class GroupManager { long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(groupRecipient, ThreadDatabase.DistributionTypes.CONVERSATION); return new GroupActionResult(groupRecipient, threadId); } + */ } public static GroupActionResult updateGroup(@NonNull Context context, From a683c3fa9030dec00359db3c23e7031acb29d8c4 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Tue, 10 Sep 2019 15:37:26 +1000 Subject: [PATCH 3/6] Disable notification triggers on group messages. --- src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java | 3 ++- .../securesms/notifications/MessageNotifier.java | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java index 2d4a6577ed..687ba2a604 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java @@ -988,7 +988,8 @@ public class PushDecryptJob extends BaseJob implements InjectableType { // Loki - Map message id to server id updatePublicChatMessageWithServerID(messageServerIDOrNull, insertResult); - if (threadId != null) { + boolean isGroupMessage = message.getGroupInfo().isPresent(); + if (threadId != null && !isGroupMessage) { MessageNotifier.updateNotification(context, threadId); } } diff --git a/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java b/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java index 85bd474a40..418afa0d5b 100644 --- a/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java +++ b/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java @@ -388,6 +388,11 @@ public class MessageNotifier { } private static void sendInThreadNotification(Context context, Recipient recipient) { + // Keep group messages muted! + if (recipient.isGroupRecipient()) { + return; + } + if (!TextSecurePreferences.isInThreadNotifications(context) || ServiceUtil.getAudioManager(context).getRingerMode() != AudioManager.RINGER_MODE_NORMAL) { From aa560b60a982bdfa8ad46e4ef7cd8b6084683b27 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Tue, 10 Sep 2019 16:49:17 +1000 Subject: [PATCH 4/6] Stop pollers once leaving group chats. --- .../securesms/ApplicationContext.java | 63 ++++++++++++++++--- .../securesms/database/ThreadDatabase.java | 15 +++++ .../securesms/groups/GroupManager.java | 10 +++ 3 files changed, 81 insertions(+), 7 deletions(-) diff --git a/src/org/thoughtcrime/securesms/ApplicationContext.java b/src/org/thoughtcrime/securesms/ApplicationContext.java index c469f4f27b..d7888360f4 100644 --- a/src/org/thoughtcrime/securesms/ApplicationContext.java +++ b/src/org/thoughtcrime/securesms/ApplicationContext.java @@ -21,6 +21,7 @@ import android.arch.lifecycle.DefaultLifecycleObserver; import android.arch.lifecycle.LifecycleOwner; import android.arch.lifecycle.ProcessLifecycleOwner; import android.content.Context; +import android.database.ContentObserver; import android.os.AsyncTask; import android.os.Build; import android.support.annotation.NonNull; @@ -35,6 +36,7 @@ import org.jetbrains.annotations.NotNull; import org.signal.aesgcmprovider.AesGcmProvider; import org.thoughtcrime.securesms.components.TypingStatusRepository; import org.thoughtcrime.securesms.components.TypingStatusSender; +import org.thoughtcrime.securesms.database.DatabaseContentProviders; import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.dependencies.AxolotlStorageModule; import org.thoughtcrime.securesms.dependencies.InjectableType; @@ -458,7 +460,7 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc LokiGroupChat publicChat = lokiPublicChat(); boolean isChatSetUp = TextSecurePreferences.isChatSetUp(this, publicChat.getId()); if (!isChatSetUp || !publicChat.isDeletable()) { - GroupManager.createGroup(publicChat.getId(), this, new HashSet<>(), null, publicChat.getDisplayName(), false); + GroupManager.GroupActionResult result = GroupManager.createGroup(publicChat.getId(), this, new HashSet<>(), null, publicChat.getDisplayName(), false); TextSecurePreferences.markChatSetUp(this, publicChat.getId()); } } @@ -476,24 +478,71 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc } } + private void createGroupChatPollersIfNeeded() { - if (lokiPublicChatPoller == null) lokiPublicChatPoller = new LokiGroupChatPoller(this, lokiPublicChat()); + // Only add the public chat poller if we have the thread + LokiGroupChat publicChat = lokiPublicChat(); + long threadId = GroupManager.getThreadId(publicChat.getId(), this); + if (threadId >= 0 && lokiPublicChatPoller == null) { + lokiPublicChatPoller = new LokiGroupChatPoller(this, publicChat); + + // Attach a deletion listener to the thread if we have it + setupThreadDeletionListeners(threadId, () -> { + if (lokiPublicChatPoller != null) lokiPublicChatPoller.stop(); + lokiPublicChatPoller = null; + }); + } } private void createRSSFeedPollersIfNeeded() { - if (lokiNewsFeedPoller == null) lokiNewsFeedPoller = new LokiRSSFeedPoller(this, lokiNewsFeed()); - if (lokiMessengerUpdatesFeedPoller == null) lokiMessengerUpdatesFeedPoller = new LokiRSSFeedPoller(this, lokiMessengerUpdatesFeed()); + // Only add the feed poller if we have the thread + LokiRSSFeed lokiNewsFeed = lokiNewsFeed(); + long lokiNewsFeedThreadId = GroupManager.getThreadId(lokiNewsFeed.getId(), this); + if (lokiNewsFeedThreadId >= 0 && lokiNewsFeedPoller == null) { + lokiNewsFeedPoller = new LokiRSSFeedPoller(this, lokiNewsFeed); + + // Attach a deletion listener to the thread if we have it + setupThreadDeletionListeners(lokiNewsFeedThreadId, () -> { + if (lokiNewsFeedPoller != null) lokiNewsFeedPoller.stop(); + lokiNewsFeedPoller = null; + }); + } + + // This one is not stoppable + if (lokiMessengerUpdatesFeedPoller == null) { lokiMessengerUpdatesFeedPoller = new LokiRSSFeedPoller(this, lokiMessengerUpdatesFeed()); } + } + + private void setupThreadDeletionListeners(long threadId, Runnable onDelete) { + if (threadId < 0) { return; } + + ContentObserver observer = new ContentObserver(null) { + @Override + public void onChange(boolean selfChange) { + super.onChange(selfChange); + + // Stop the poller if thread doesn't exist + try { + if (!DatabaseFactory.getThreadDatabase(getApplicationContext()).hasThread(threadId)) { + onDelete.run(); + getContentResolver().unregisterContentObserver(this); + } + } catch (Exception e) { + // Failed to call delete + } + } + }; + this.getContentResolver().registerContentObserver(DatabaseContentProviders.Conversation.getUriForThread(threadId), true, observer); } public void startGroupChatPollersIfNeeded() { createGroupChatPollersIfNeeded(); - lokiPublicChatPoller.startIfNeeded(); + if (lokiPublicChatPoller != null) lokiPublicChatPoller.startIfNeeded(); } public void startRSSFeedPollersIfNeeded() { createRSSFeedPollersIfNeeded(); - lokiNewsFeedPoller.startIfNeeded(); - lokiMessengerUpdatesFeedPoller.startIfNeeded(); + if (lokiNewsFeedPoller != null) lokiNewsFeedPoller.startIfNeeded(); + if (lokiMessengerUpdatesFeedPoller != null) lokiMessengerUpdatesFeedPoller.startIfNeeded(); } // endregion } diff --git a/src/org/thoughtcrime/securesms/database/ThreadDatabase.java b/src/org/thoughtcrime/securesms/database/ThreadDatabase.java index 834ef5dd68..b6598860a8 100644 --- a/src/org/thoughtcrime/securesms/database/ThreadDatabase.java +++ b/src/org/thoughtcrime/securesms/database/ThreadDatabase.java @@ -472,6 +472,21 @@ public class ThreadDatabase extends Database { deleteAllThreads(); } + public boolean hasThread(long threadId) { + SQLiteDatabase db = databaseHelper.getReadableDatabase(); + Cursor cursor = db.query(TABLE_NAME, new String[]{ID}, ID_WHERE, new String[]{String.valueOf(threadId)}, null, null, null); + + try { + if (cursor != null && cursor.moveToFirst()) { + return true; + } + + return false; + } finally { + if (cursor != null) cursor.close(); + } + } + public long getThreadIdIfExistsFor(Recipient recipient) { SQLiteDatabase db = databaseHelper.getReadableDatabase(); String where = ADDRESS + " = ?"; diff --git a/src/org/thoughtcrime/securesms/groups/GroupManager.java b/src/org/thoughtcrime/securesms/groups/GroupManager.java index 033384dc9d..5fae394cf7 100644 --- a/src/org/thoughtcrime/securesms/groups/GroupManager.java +++ b/src/org/thoughtcrime/securesms/groups/GroupManager.java @@ -36,6 +36,16 @@ import java.util.Set; public class GroupManager { + public static long getThreadId(String id, @NonNull Context context) { + final String groupId = GroupUtil.getEncodedId(id.getBytes(), false); + return getThreadIdFromGroupId(groupId, context); + } + + public static long getThreadIdFromGroupId(String groupId, @NonNull Context context) { + final Recipient groupRecipient = Recipient.from(context, Address.fromSerialized(groupId), false); + return DatabaseFactory.getThreadDatabase(context).getThreadIdIfExistsFor(groupRecipient); + } + public static @NonNull GroupActionResult createGroup(@NonNull Context context, @NonNull Set members, @Nullable Bitmap avatar, From caff6e1da4afe8f8e5adeec91904dfd05c2e0036 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Wed, 11 Sep 2019 09:27:33 +1000 Subject: [PATCH 5/6] Fix notification edge case --- .../securesms/conversation/ConversationActivity.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java b/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java index dae5b71a9a..79b6003c5c 100644 --- a/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java +++ b/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java @@ -2101,7 +2101,11 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity Context context = ConversationActivity.this; List messageIds = DatabaseFactory.getThreadDatabase(context).setRead(params[0], false); - MessageNotifier.updateNotification(context); + // Only notify on private chats + if (!getRecipient().isGroupRecipient()) { + MessageNotifier.updateNotification(context); + } + MarkReadReceiver.process(context, messageIds); return null; From 52b55652c873f7066af2e05148952e26e8c66302 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Thu, 12 Sep 2019 09:59:15 +1000 Subject: [PATCH 6/6] Clean --- .../securesms/ApplicationContext.java | 45 +++++++++---------- .../conversation/ConversationActivity.java | 6 +-- .../securesms/database/ThreadDatabase.java | 9 ++-- .../securesms/groups/GroupManager.java | 4 +- .../securesms/jobs/PushDecryptJob.java | 15 +++---- .../notifications/MessageNotifier.java | 6 +-- 6 files changed, 37 insertions(+), 48 deletions(-) diff --git a/src/org/thoughtcrime/securesms/ApplicationContext.java b/src/org/thoughtcrime/securesms/ApplicationContext.java index d7888360f4..3570503791 100644 --- a/src/org/thoughtcrime/securesms/ApplicationContext.java +++ b/src/org/thoughtcrime/securesms/ApplicationContext.java @@ -478,16 +478,14 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc } } - 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(); - long threadId = GroupManager.getThreadId(publicChat.getId(), this); - if (threadId >= 0 && lokiPublicChatPoller == null) { + long threadID = GroupManager.getThreadId(publicChat.getId(), this); + if (threadID >= 0 && lokiPublicChatPoller == null) { lokiPublicChatPoller = new LokiGroupChatPoller(this, publicChat); - - // Attach a deletion listener to the thread if we have it - setupThreadDeletionListeners(threadId, () -> { + // Set up deletion listeners if needed + setUpThreadDeletionListeners(threadID, () -> { if (lokiPublicChatPoller != null) lokiPublicChatPoller.stop(); lokiPublicChatPoller = null; }); @@ -495,43 +493,42 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc } 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(); - long lokiNewsFeedThreadId = GroupManager.getThreadId(lokiNewsFeed.getId(), this); - if (lokiNewsFeedThreadId >= 0 && lokiNewsFeedPoller == null) { + long lokiNewsFeedThreadID = GroupManager.getThreadId(lokiNewsFeed.getId(), this); + if (lokiNewsFeedThreadID >= 0 && lokiNewsFeedPoller == null) { lokiNewsFeedPoller = new LokiRSSFeedPoller(this, lokiNewsFeed); - - // Attach a deletion listener to the thread if we have it - setupThreadDeletionListeners(lokiNewsFeedThreadId, () -> { + // Set up deletion listeners if needed + setUpThreadDeletionListeners(lokiNewsFeedThreadID, () -> { if (lokiNewsFeedPoller != null) lokiNewsFeedPoller.stop(); lokiNewsFeedPoller = null; }); } - - // This one is not stoppable - if (lokiMessengerUpdatesFeedPoller == null) { lokiMessengerUpdatesFeedPoller = new LokiRSSFeedPoller(this, lokiMessengerUpdatesFeed()); } + // The user can't delete the Loki Messenger Updates RSS feed + if (lokiMessengerUpdatesFeedPoller == null) { + lokiMessengerUpdatesFeedPoller = new LokiRSSFeedPoller(this, lokiMessengerUpdatesFeed()); + } } - private void setupThreadDeletionListeners(long threadId, Runnable onDelete) { - if (threadId < 0) { return; } - + private void setUpThreadDeletionListeners(long threadID, Runnable onDelete) { + if (threadID < 0) { return; } ContentObserver observer = new ContentObserver(null) { + @Override public void onChange(boolean selfChange) { super.onChange(selfChange); - - // Stop the poller if thread doesn't exist + // Stop the poller if thread is deleted try { - if (!DatabaseFactory.getThreadDatabase(getApplicationContext()).hasThread(threadId)) { + if (!DatabaseFactory.getThreadDatabase(getApplicationContext()).hasThread(threadID)) { onDelete.run(); getContentResolver().unregisterContentObserver(this); } } 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() { diff --git a/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java b/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java index 79b6003c5c..88c5404192 100644 --- a/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java +++ b/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java @@ -2101,10 +2101,8 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity Context context = ConversationActivity.this; List messageIds = DatabaseFactory.getThreadDatabase(context).setRead(params[0], false); - // Only notify on private chats - if (!getRecipient().isGroupRecipient()) { - MessageNotifier.updateNotification(context); - } + // Only send notifications for private chats + if (!getRecipient().isGroupRecipient()) { MessageNotifier.updateNotification(context); } MarkReadReceiver.process(context, messageIds); diff --git a/src/org/thoughtcrime/securesms/database/ThreadDatabase.java b/src/org/thoughtcrime/securesms/database/ThreadDatabase.java index b6598860a8..a4d1917174 100644 --- a/src/org/thoughtcrime/securesms/database/ThreadDatabase.java +++ b/src/org/thoughtcrime/securesms/database/ThreadDatabase.java @@ -473,14 +473,11 @@ public class ThreadDatabase extends Database { } public boolean hasThread(long threadId) { - SQLiteDatabase db = databaseHelper.getReadableDatabase(); - Cursor cursor = db.query(TABLE_NAME, new String[]{ID}, ID_WHERE, new String[]{String.valueOf(threadId)}, null, null, null); + SQLiteDatabase db = databaseHelper.getReadableDatabase(); + Cursor cursor = db.query(TABLE_NAME, new String[]{ ID }, ID_WHERE, new String[]{ String.valueOf(threadId) }, null, null, null); try { - if (cursor != null && cursor.moveToFirst()) { - return true; - } - + if (cursor != null && cursor.moveToFirst()) { return true; } return false; } finally { if (cursor != null) cursor.close(); diff --git a/src/org/thoughtcrime/securesms/groups/GroupManager.java b/src/org/thoughtcrime/securesms/groups/GroupManager.java index 5fae394cf7..e17b964d93 100644 --- a/src/org/thoughtcrime/securesms/groups/GroupManager.java +++ b/src/org/thoughtcrime/securesms/groups/GroupManager.java @@ -37,12 +37,12 @@ import java.util.Set; public class GroupManager { public static long getThreadId(String id, @NonNull Context context) { - final String groupId = GroupUtil.getEncodedId(id.getBytes(), false); + final String groupId = GroupUtil.getEncodedId(id.getBytes(), false); return getThreadIdFromGroupId(groupId, context); } public static long getThreadIdFromGroupId(String groupId, @NonNull Context context) { - final Recipient groupRecipient = Recipient.from(context, Address.fromSerialized(groupId), false); + final Recipient groupRecipient = Recipient.from(context, Address.fromSerialized(groupId), false); return DatabaseFactory.getThreadDatabase(context).getThreadIdIfExistsFor(groupRecipient); } diff --git a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java index 25be4d87d9..3554c88309 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java @@ -812,8 +812,8 @@ public class PushDecryptJob extends BaseJob implements InjectableType { database.endTransaction(); } - // Loki - Map message id to server id - updatePublicChatMessageWithServerID(messageServerIDOrNull, insertResult); + // Loki - Store message server ID + updateGroupChatMessageServerID(messageServerIDOrNull, insertResult); if (insertResult.isPresent()) { MessageNotifier.updateNotification(context, insertResult.get().getThreadId()); @@ -982,8 +982,8 @@ public class PushDecryptJob extends BaseJob implements InjectableType { if (smsMessageId.isPresent()) database.deleteMessage(smsMessageId.get()); - // Loki - Map message id to server id - updatePublicChatMessageWithServerID(messageServerIDOrNull, insertResult); + // Loki - Store message server ID + updateGroupChatMessageServerID(messageServerIDOrNull, insertResult); boolean isGroupMessage = message.getGroupInfo().isPresent(); if (threadId != null && !isGroupMessage) { @@ -993,10 +993,9 @@ public class PushDecryptJob extends BaseJob implements InjectableType { } } - private void updatePublicChatMessageWithServerID(Optional messageServerIDOrNull, Optional databaseInsert) { - if (messageServerIDOrNull == null) { return; } - if (databaseInsert.isPresent() && messageServerIDOrNull.isPresent()) { - long messageID = databaseInsert.get().getMessageId(); + private void updateGroupChatMessageServerID(Optional messageServerIDOrNull, Optional insertResult) { + if (insertResult.isPresent() && messageServerIDOrNull.isPresent()) { + long messageID = insertResult.get().getMessageId(); long messageServerID = messageServerIDOrNull.get(); DatabaseFactory.getLokiMessageDatabase(context).setServerID(messageID, messageServerID); } diff --git a/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java b/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java index 418afa0d5b..e7e6cc73ba 100644 --- a/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java +++ b/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java @@ -388,10 +388,8 @@ public class MessageNotifier { } private static void sendInThreadNotification(Context context, Recipient recipient) { - // Keep group messages muted! - if (recipient.isGroupRecipient()) { - return; - } + // Mute group chats + if (recipient.isGroupRecipient()) { return; } if (!TextSecurePreferences.isInThreadNotifications(context) || ServiceUtil.getAudioManager(context).getRingerMode() != AudioManager.RINGER_MODE_NORMAL)