Path: blob/main/SignalServiceKit/Messages/OWSRecoverableDecryptionPlaceholder.m
1 views
//1// Copyright 2021 Signal Messenger, LLC2// SPDX-License-Identifier: AGPL-3.0-only3//45#import "OWSRecoverableDecryptionPlaceholder.h"6#import <SignalServiceKit/SignalServiceKit-Swift.h>78NS_ASSUME_NONNULL_BEGIN910@implementation OWSRecoverableDecryptionPlaceholder1112- (nullable instancetype)initWithFailedEnvelopeTimestamp:(uint64_t)timestamp13sourceAci:(AciObjC *)sourceAci14untrustedGroupId:(nullable NSData *)untrustedGroupId15transaction:(DBWriteTransaction *)writeTx16{17SignalServiceAddress *sender = [[SignalServiceAddress alloc] initWithServiceIdObjC:sourceAci];18TSThread *thread;19if (untrustedGroupId.length > 0) {20TSGroupThread *_Nullable groupThread = [TSGroupThread fetchWithGroupId:untrustedGroupId transaction:writeTx];21// If we aren't sure that the sender is a member of the reported groupId, we should fall back22// to inserting the placeholder in the contact thread.23if ([groupThread.groupMembership isFullMember:sender]) {24thread = groupThread;25}26OWSAssertDebug(thread);27}28if (!thread) {29thread = [TSContactThread getWithContactAddress:sender transaction:writeTx];30OWSAssertDebug(thread);31}32if (!thread) {33return nil;34}35TSErrorMessageBuilder *builder = [[TSErrorMessageBuilder alloc] initWithThread:thread36errorType:TSErrorMessageDecryptionFailure];37builder.timestamp = timestamp;38builder.senderAddress = sender;39return [super initErrorMessageWithBuilder:builder];40}4142- (instancetype)initWithGrdbId:(int64_t)grdbId43uniqueId:(NSString *)uniqueId44receivedAtTimestamp:(uint64_t)receivedAtTimestamp45sortId:(uint64_t)sortId46timestamp:(uint64_t)timestamp47uniqueThreadId:(NSString *)uniqueThreadId48body:(nullable NSString *)body49bodyRanges:(nullable MessageBodyRanges *)bodyRanges50contactShare:(nullable OWSContact *)contactShare51deprecated_attachmentIds:(nullable NSArray<NSString *> *)deprecated_attachmentIds52editState:(TSEditState)editState53expireStartedAt:(uint64_t)expireStartedAt54expireTimerVersion:(nullable NSNumber *)expireTimerVersion55expiresAt:(uint64_t)expiresAt56expiresInSeconds:(unsigned int)expiresInSeconds57giftBadge:(nullable OWSGiftBadge *)giftBadge58isGroupStoryReply:(BOOL)isGroupStoryReply59isPoll:(BOOL)isPoll60isSmsMessageRestoredFromBackup:(BOOL)isSmsMessageRestoredFromBackup61isViewOnceComplete:(BOOL)isViewOnceComplete62isViewOnceMessage:(BOOL)isViewOnceMessage63linkPreview:(nullable OWSLinkPreview *)linkPreview64messageSticker:(nullable MessageSticker *)messageSticker65quotedMessage:(nullable TSQuotedMessage *)quotedMessage66storedShouldStartExpireTimer:(BOOL)storedShouldStartExpireTimer67storyAuthorUuidString:(nullable NSString *)storyAuthorUuidString68storyReactionEmoji:(nullable NSString *)storyReactionEmoji69storyTimestamp:(nullable NSNumber *)storyTimestamp70wasRemotelyDeleted:(BOOL)wasRemotelyDeleted71errorType:(TSErrorMessageType)errorType72read:(BOOL)read73recipientAddress:(nullable SignalServiceAddress *)recipientAddress74sender:(nullable SignalServiceAddress *)sender75wasIdentityVerified:(BOOL)wasIdentityVerified76{77self = [super initWithGrdbId:grdbId78uniqueId:uniqueId79receivedAtTimestamp:receivedAtTimestamp80sortId:sortId81timestamp:timestamp82uniqueThreadId:uniqueThreadId83body:body84bodyRanges:bodyRanges85contactShare:contactShare86deprecated_attachmentIds:deprecated_attachmentIds87editState:editState88expireStartedAt:expireStartedAt89expireTimerVersion:expireTimerVersion90expiresAt:expiresAt91expiresInSeconds:expiresInSeconds92giftBadge:giftBadge93isGroupStoryReply:isGroupStoryReply94isPoll:isPoll95isSmsMessageRestoredFromBackup:isSmsMessageRestoredFromBackup96isViewOnceComplete:isViewOnceComplete97isViewOnceMessage:isViewOnceMessage98linkPreview:linkPreview99messageSticker:messageSticker100quotedMessage:quotedMessage101storedShouldStartExpireTimer:storedShouldStartExpireTimer102storyAuthorUuidString:storyAuthorUuidString103storyReactionEmoji:storyReactionEmoji104storyTimestamp:storyTimestamp105wasRemotelyDeleted:wasRemotelyDeleted106errorType:errorType107read:read108recipientAddress:recipientAddress109sender:sender110wasIdentityVerified:wasIdentityVerified];111112return self;113}114115// --- CODE GENERATION MARKER116117// This snippet is generated by /Scripts/sds_codegen/sds_generate.py. Do not manually edit it, instead run118// `sds_codegen.sh`.119120121// --- CODE GENERATION MARKER122123#pragma mark - Methods124125- (BOOL)supportsReplacement126{127return [self.expirationDate isAfterNow] && !self.wasRead;128}129130- (NSString *)previewTextWithTransaction:(DBReadTransaction *)transaction131{132NSString *_Nullable senderName = nil;133if (self.sender) {134senderName = [SSKEnvironment.shared.contactManagerObjcRef shortDisplayNameStringForAddress:self.sender135transaction:transaction];136}137138if (senderName) {139OWSFailDebug(@"Should not be directly surfaced to user");140NSString *formatString = OWSLocalizedString(@"ERROR_MESSAGE_DECRYPTION_FAILURE",141@"Error message for a decryption failure. Embeds {{sender short name}}.");142#pragma clang diagnostic push143#pragma clang diagnostic ignored "-Wformat-nonliteral"144return [[NSString alloc] initWithFormat:formatString, senderName];145#pragma clang diagnostic pop146} else {147OWSFailDebug(@"Should not be directly surfaced to user");148return OWSLocalizedString(149@"ERROR_MESSAGE_DECRYPTION_FAILURE_UNKNOWN_SENDER", @"Error message for a decryption failure.");150}151}152153#pragma mark - <OWSReadTracking>154155- (void)markAsReadAtTimestamp:(uint64_t)readTimestamp156thread:(TSThread *)thread157circumstance:(OWSReceiptCircumstance)circumstance158shouldClearNotifications:(BOOL)shouldClearNotifications159transaction:(DBWriteTransaction *)transaction160{161OWSLogInfo(@"Marking placeholder as read. No longer eligible for inline replacement.");162[super markAsReadAtTimestamp:readTimestamp163thread:thread164circumstance:circumstance165shouldClearNotifications:shouldClearNotifications166transaction:transaction];167}168169@end170171NS_ASSUME_NONNULL_END172173174