From df36d5e539be1cbcad9a03916c68e29d66c542fa Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Tue, 17 Sep 2019 10:36:34 +1000 Subject: [PATCH] Handle case where GIF fetch fails --- .../securesms/jobs/PushDecryptJob.java | 40 +++++++++++-------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java index 41fbee2b18..286ceab5bb 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java @@ -946,14 +946,14 @@ public class PushDecryptJob extends BaseJob implements InjectableType { } else { notifyTypingStoppedFromIncomingMessage(recipient, content.getSender(), content.getSenderDevice()); - IncomingTextMessage textMessage = new IncomingTextMessage(Address.fromSerialized(content.getSender()), + IncomingTextMessage _textMessage = new IncomingTextMessage(Address.fromSerialized(content.getSender()), content.getSenderDevice(), message.getTimestamp(), body, message.getGroupInfo(), message.getExpiresInSeconds() * 1000L, content.isNeedsReceipt()); - textMessage = new IncomingEncryptedMessage(textMessage, body); + IncomingEncryptedMessage textMessage = new IncomingEncryptedMessage(_textMessage, body); List urls = LinkPreviewUtil.findWhitelistedUrls(body); int urlCount = urls.size(); @@ -992,28 +992,34 @@ public class PushDecryptJob extends BaseJob implements InjectableType { // TODO: Handle } } else { - // TODO: Handle + handleTextMessage(message, textMessage, smsMessageId, messageServerIDOrNull); } })); } else { - Optional insertResult = database.insertMessageInbox(textMessage); - - if (insertResult.isPresent()) threadId = insertResult.get().getThreadId(); - else threadId = null; - - if (smsMessageId.isPresent()) database.deleteMessage(smsMessageId.get()); - - // Loki - Store message server ID - updateGroupChatMessageServerID(messageServerIDOrNull, insertResult); - - boolean isGroupMessage = message.getGroupInfo().isPresent(); - if (threadId != null && !isGroupMessage) { - MessageNotifier.updateNotification(context, threadId); - } + handleTextMessage(message, textMessage, smsMessageId, messageServerIDOrNull); } } } + private void handleTextMessage(@NonNull SignalServiceDataMessage message, @NonNull IncomingTextMessage textMessage, @NonNull Optional smsMessageId, @NonNull Optional messageServerIDOrNull) { + SmsDatabase database = DatabaseFactory.getSmsDatabase(context); + Optional insertResult = database.insertMessageInbox(textMessage); + + Long threadId; + if (insertResult.isPresent()) threadId = insertResult.get().getThreadId(); + else threadId = null; + + if (smsMessageId.isPresent()) database.deleteMessage(smsMessageId.get()); + + // Loki - Store message server ID + updateGroupChatMessageServerID(messageServerIDOrNull, insertResult); + + boolean isGroupMessage = message.getGroupInfo().isPresent(); + if (threadId != null && !isGroupMessage) { + MessageNotifier.updateNotification(context, threadId); + } + } + private void updateGroupChatMessageServerID(Optional messageServerIDOrNull, Optional insertResult) { if (insertResult.isPresent() && messageServerIDOrNull.isPresent()) { long messageID = insertResult.get().getMessageId();