From dcd3997a7866c69245bb0a47fb9a380b19feffe2 Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Tue, 14 Sep 2021 15:10:01 +1000 Subject: [PATCH] fix an issue where untrusted contact's media message will never be marked as read --- .../Messages/Signal/TSIncomingMessage.m | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/SessionMessagingKit/Messages/Signal/TSIncomingMessage.m b/SessionMessagingKit/Messages/Signal/TSIncomingMessage.m index ecfc9168f..01769a1aa 100644 --- a/SessionMessagingKit/Messages/Signal/TSIncomingMessage.m +++ b/SessionMessagingKit/Messages/Signal/TSIncomingMessage.m @@ -155,18 +155,26 @@ NS_ASSUME_NONNULL_BEGIN if (_read && readTimestamp >= self.expireStartedAt) { return; } + BOOL isTrusted = YES; + TSThread* thread = [self threadWithTransaction:transaction]; + if ([thread isKindOfClass:[TSContactThread class]]) { + TSContactThread* contactThread = (TSContactThread*)thread; + isTrusted = [[LKStorage shared] getContactWithSessionID:[contactThread contactSessionID] using:transaction].isTrusted; + } BOOL areAllAttachmentsDownloaded = YES; - for (NSString *attachmentId in self.attachmentIds) { - TSAttachment *attachment = [TSAttachment fetchObjectWithUniqueID:attachmentId transaction:transaction]; - // If the attachment download failed, we can mark this message as read. - // Otherwise, this message will never be marked as read. - if ([attachment isKindOfClass:[TSAttachmentPointer class]] - && ((TSAttachmentPointer *)attachment).state == TSAttachmentPointerStateFailed) { - continue; + if (isTrusted) { + for (NSString *attachmentId in self.attachmentIds) { + TSAttachment *attachment = [TSAttachment fetchObjectWithUniqueID:attachmentId transaction:transaction]; + // If the attachment download failed, we can mark this message as read. + // Otherwise, this message will never be marked as read. + if ([attachment isKindOfClass:[TSAttachmentPointer class]] + && ((TSAttachmentPointer *)attachment).state == TSAttachmentPointerStateFailed) { + continue; + } + areAllAttachmentsDownloaded = areAllAttachmentsDownloaded && attachment.isDownloaded; + if (!areAllAttachmentsDownloaded) break; } - areAllAttachmentsDownloaded = areAllAttachmentsDownloaded && attachment.isDownloaded; - if (!areAllAttachmentsDownloaded) break; } if (!areAllAttachmentsDownloaded) {