Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
signalapp
GitHub Repository: signalapp/Signal-iOS
Path: blob/main/SignalServiceKit/Messages/OWSRecoverableDecryptionPlaceholder.m
1 views
1
//
2
// Copyright 2021 Signal Messenger, LLC
3
// SPDX-License-Identifier: AGPL-3.0-only
4
//
5
6
#import "OWSRecoverableDecryptionPlaceholder.h"
7
#import <SignalServiceKit/SignalServiceKit-Swift.h>
8
9
NS_ASSUME_NONNULL_BEGIN
10
11
@implementation OWSRecoverableDecryptionPlaceholder
12
13
- (nullable instancetype)initWithFailedEnvelopeTimestamp:(uint64_t)timestamp
14
sourceAci:(AciObjC *)sourceAci
15
untrustedGroupId:(nullable NSData *)untrustedGroupId
16
transaction:(DBWriteTransaction *)writeTx
17
{
18
SignalServiceAddress *sender = [[SignalServiceAddress alloc] initWithServiceIdObjC:sourceAci];
19
TSThread *thread;
20
if (untrustedGroupId.length > 0) {
21
TSGroupThread *_Nullable groupThread = [TSGroupThread fetchWithGroupId:untrustedGroupId transaction:writeTx];
22
// If we aren't sure that the sender is a member of the reported groupId, we should fall back
23
// to inserting the placeholder in the contact thread.
24
if ([groupThread.groupMembership isFullMember:sender]) {
25
thread = groupThread;
26
}
27
OWSAssertDebug(thread);
28
}
29
if (!thread) {
30
thread = [TSContactThread getWithContactAddress:sender transaction:writeTx];
31
OWSAssertDebug(thread);
32
}
33
if (!thread) {
34
return nil;
35
}
36
TSErrorMessageBuilder *builder = [[TSErrorMessageBuilder alloc] initWithThread:thread
37
errorType:TSErrorMessageDecryptionFailure];
38
builder.timestamp = timestamp;
39
builder.senderAddress = sender;
40
return [super initErrorMessageWithBuilder:builder];
41
}
42
43
- (instancetype)initWithGrdbId:(int64_t)grdbId
44
uniqueId:(NSString *)uniqueId
45
receivedAtTimestamp:(uint64_t)receivedAtTimestamp
46
sortId:(uint64_t)sortId
47
timestamp:(uint64_t)timestamp
48
uniqueThreadId:(NSString *)uniqueThreadId
49
body:(nullable NSString *)body
50
bodyRanges:(nullable MessageBodyRanges *)bodyRanges
51
contactShare:(nullable OWSContact *)contactShare
52
deprecated_attachmentIds:(nullable NSArray<NSString *> *)deprecated_attachmentIds
53
editState:(TSEditState)editState
54
expireStartedAt:(uint64_t)expireStartedAt
55
expireTimerVersion:(nullable NSNumber *)expireTimerVersion
56
expiresAt:(uint64_t)expiresAt
57
expiresInSeconds:(unsigned int)expiresInSeconds
58
giftBadge:(nullable OWSGiftBadge *)giftBadge
59
isGroupStoryReply:(BOOL)isGroupStoryReply
60
isPoll:(BOOL)isPoll
61
isSmsMessageRestoredFromBackup:(BOOL)isSmsMessageRestoredFromBackup
62
isViewOnceComplete:(BOOL)isViewOnceComplete
63
isViewOnceMessage:(BOOL)isViewOnceMessage
64
linkPreview:(nullable OWSLinkPreview *)linkPreview
65
messageSticker:(nullable MessageSticker *)messageSticker
66
quotedMessage:(nullable TSQuotedMessage *)quotedMessage
67
storedShouldStartExpireTimer:(BOOL)storedShouldStartExpireTimer
68
storyAuthorUuidString:(nullable NSString *)storyAuthorUuidString
69
storyReactionEmoji:(nullable NSString *)storyReactionEmoji
70
storyTimestamp:(nullable NSNumber *)storyTimestamp
71
wasRemotelyDeleted:(BOOL)wasRemotelyDeleted
72
errorType:(TSErrorMessageType)errorType
73
read:(BOOL)read
74
recipientAddress:(nullable SignalServiceAddress *)recipientAddress
75
sender:(nullable SignalServiceAddress *)sender
76
wasIdentityVerified:(BOOL)wasIdentityVerified
77
{
78
self = [super initWithGrdbId:grdbId
79
uniqueId:uniqueId
80
receivedAtTimestamp:receivedAtTimestamp
81
sortId:sortId
82
timestamp:timestamp
83
uniqueThreadId:uniqueThreadId
84
body:body
85
bodyRanges:bodyRanges
86
contactShare:contactShare
87
deprecated_attachmentIds:deprecated_attachmentIds
88
editState:editState
89
expireStartedAt:expireStartedAt
90
expireTimerVersion:expireTimerVersion
91
expiresAt:expiresAt
92
expiresInSeconds:expiresInSeconds
93
giftBadge:giftBadge
94
isGroupStoryReply:isGroupStoryReply
95
isPoll:isPoll
96
isSmsMessageRestoredFromBackup:isSmsMessageRestoredFromBackup
97
isViewOnceComplete:isViewOnceComplete
98
isViewOnceMessage:isViewOnceMessage
99
linkPreview:linkPreview
100
messageSticker:messageSticker
101
quotedMessage:quotedMessage
102
storedShouldStartExpireTimer:storedShouldStartExpireTimer
103
storyAuthorUuidString:storyAuthorUuidString
104
storyReactionEmoji:storyReactionEmoji
105
storyTimestamp:storyTimestamp
106
wasRemotelyDeleted:wasRemotelyDeleted
107
errorType:errorType
108
read:read
109
recipientAddress:recipientAddress
110
sender:sender
111
wasIdentityVerified:wasIdentityVerified];
112
113
return self;
114
}
115
116
// --- CODE GENERATION MARKER
117
118
// This snippet is generated by /Scripts/sds_codegen/sds_generate.py. Do not manually edit it, instead run
119
// `sds_codegen.sh`.
120
121
122
// --- CODE GENERATION MARKER
123
124
#pragma mark - Methods
125
126
- (BOOL)supportsReplacement
127
{
128
return [self.expirationDate isAfterNow] && !self.wasRead;
129
}
130
131
- (NSString *)previewTextWithTransaction:(DBReadTransaction *)transaction
132
{
133
NSString *_Nullable senderName = nil;
134
if (self.sender) {
135
senderName = [SSKEnvironment.shared.contactManagerObjcRef shortDisplayNameStringForAddress:self.sender
136
transaction:transaction];
137
}
138
139
if (senderName) {
140
OWSFailDebug(@"Should not be directly surfaced to user");
141
NSString *formatString = OWSLocalizedString(@"ERROR_MESSAGE_DECRYPTION_FAILURE",
142
@"Error message for a decryption failure. Embeds {{sender short name}}.");
143
#pragma clang diagnostic push
144
#pragma clang diagnostic ignored "-Wformat-nonliteral"
145
return [[NSString alloc] initWithFormat:formatString, senderName];
146
#pragma clang diagnostic pop
147
} else {
148
OWSFailDebug(@"Should not be directly surfaced to user");
149
return OWSLocalizedString(
150
@"ERROR_MESSAGE_DECRYPTION_FAILURE_UNKNOWN_SENDER", @"Error message for a decryption failure.");
151
}
152
}
153
154
#pragma mark - <OWSReadTracking>
155
156
- (void)markAsReadAtTimestamp:(uint64_t)readTimestamp
157
thread:(TSThread *)thread
158
circumstance:(OWSReceiptCircumstance)circumstance
159
shouldClearNotifications:(BOOL)shouldClearNotifications
160
transaction:(DBWriteTransaction *)transaction
161
{
162
OWSLogInfo(@"Marking placeholder as read. No longer eligible for inline replacement.");
163
[super markAsReadAtTimestamp:readTimestamp
164
thread:thread
165
circumstance:circumstance
166
shouldClearNotifications:shouldClearNotifications
167
transaction:transaction];
168
}
169
170
@end
171
172
NS_ASSUME_NONNULL_END
173
174