From 9d8de789d7731f13265013a93176e11e51100b79 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Tue, 10 Sep 2019 13:43:56 +1000 Subject: [PATCH] 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; }