Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
signalapp
GitHub Repository: signalapp/Signal-iOS
Path: blob/main/SignalServiceKit/Messages/Interactions/OWSDisappearingConfigurationUpdateInfoMessage.m
1 views
1
//
2
// Copyright 2018 Signal Messenger, LLC
3
// SPDX-License-Identifier: AGPL-3.0-only
4
//
5
6
#import "OWSDisappearingConfigurationUpdateInfoMessage.h"
7
#import <SignalServiceKit/SignalServiceKit-Swift.h>
8
9
NS_ASSUME_NONNULL_BEGIN
10
11
@interface OWSDisappearingConfigurationUpdateInfoMessage ()
12
13
@property (nonatomic, readonly, nullable) NSString *createdByRemoteName;
14
@property (nonatomic, readonly) uint32_t configurationDurationSeconds;
15
16
/// This property is set for legacy messages, but always set to `false` for new
17
/// messages.
18
@property (nonatomic, readonly) BOOL createdInExistingGroup;
19
20
@end
21
22
#pragma mark -
23
24
@implementation OWSDisappearingConfigurationUpdateInfoMessage
25
26
- (NSUInteger)hash
27
{
28
NSUInteger result = [super hash];
29
result ^= self.configurationDurationSeconds;
30
result ^= self.configurationIsEnabled;
31
result ^= self.createdByRemoteName.hash;
32
result ^= self.createdInExistingGroup;
33
return result;
34
}
35
36
- (BOOL)isEqual:(id)other
37
{
38
if (![super isEqual:other]) {
39
return NO;
40
}
41
OWSDisappearingConfigurationUpdateInfoMessage *typedOther = (OWSDisappearingConfigurationUpdateInfoMessage *)other;
42
if (self.configurationDurationSeconds != typedOther.configurationDurationSeconds) {
43
return NO;
44
}
45
if (self.configurationIsEnabled != typedOther.configurationIsEnabled) {
46
return NO;
47
}
48
if (![NSObject isObject:self.createdByRemoteName equalToObject:typedOther.createdByRemoteName]) {
49
return NO;
50
}
51
if (self.createdInExistingGroup != typedOther.createdInExistingGroup) {
52
return NO;
53
}
54
return YES;
55
}
56
57
- (instancetype)initWithContactThread:(TSContactThread *)contactThread
58
timestamp:(uint64_t)timestamp
59
isConfigurationEnabled:(BOOL)isConfigurationEnabled
60
configurationDurationSeconds:(uint32_t)configurationDurationSeconds
61
createdByRemoteName:(nullable NSString *)remoteName
62
{
63
self = [super initWithThread:contactThread
64
timestamp:timestamp
65
serverGuid:nil
66
messageType:TSInfoMessageTypeDisappearingMessagesUpdate
67
expireTimerVersion:nil
68
expiresInSeconds:0
69
infoMessageUserInfo:nil];
70
if (!self) {
71
return self;
72
}
73
74
_configurationIsEnabled = isConfigurationEnabled;
75
_configurationDurationSeconds = configurationDurationSeconds;
76
_createdByRemoteName = remoteName;
77
78
_createdInExistingGroup = false;
79
80
return self;
81
}
82
83
// --- CODE GENERATION MARKER
84
85
// This snippet is generated by /Scripts/sds_codegen/sds_generate.py. Do not manually edit it, instead run
86
// `sds_codegen.sh`.
87
88
// clang-format off
89
90
- (instancetype)initWithGrdbId:(int64_t)grdbId
91
uniqueId:(NSString *)uniqueId
92
receivedAtTimestamp:(uint64_t)receivedAtTimestamp
93
sortId:(uint64_t)sortId
94
timestamp:(uint64_t)timestamp
95
uniqueThreadId:(NSString *)uniqueThreadId
96
body:(nullable NSString *)body
97
bodyRanges:(nullable MessageBodyRanges *)bodyRanges
98
contactShare:(nullable OWSContact *)contactShare
99
deprecated_attachmentIds:(nullable NSArray<NSString *> *)deprecated_attachmentIds
100
editState:(TSEditState)editState
101
expireStartedAt:(uint64_t)expireStartedAt
102
expireTimerVersion:(nullable NSNumber *)expireTimerVersion
103
expiresAt:(uint64_t)expiresAt
104
expiresInSeconds:(unsigned int)expiresInSeconds
105
giftBadge:(nullable OWSGiftBadge *)giftBadge
106
isGroupStoryReply:(BOOL)isGroupStoryReply
107
isPoll:(BOOL)isPoll
108
isSmsMessageRestoredFromBackup:(BOOL)isSmsMessageRestoredFromBackup
109
isViewOnceComplete:(BOOL)isViewOnceComplete
110
isViewOnceMessage:(BOOL)isViewOnceMessage
111
linkPreview:(nullable OWSLinkPreview *)linkPreview
112
messageSticker:(nullable MessageSticker *)messageSticker
113
quotedMessage:(nullable TSQuotedMessage *)quotedMessage
114
storedShouldStartExpireTimer:(BOOL)storedShouldStartExpireTimer
115
storyAuthorUuidString:(nullable NSString *)storyAuthorUuidString
116
storyReactionEmoji:(nullable NSString *)storyReactionEmoji
117
storyTimestamp:(nullable NSNumber *)storyTimestamp
118
wasRemotelyDeleted:(BOOL)wasRemotelyDeleted
119
customMessage:(nullable NSString *)customMessage
120
infoMessageUserInfo:(nullable NSDictionary<InfoMessageUserInfoKey, id> *)infoMessageUserInfo
121
messageType:(TSInfoMessageType)messageType
122
read:(BOOL)read
123
serverGuid:(nullable NSString *)serverGuid
124
unregisteredAddress:(nullable SignalServiceAddress *)unregisteredAddress
125
configurationDurationSeconds:(unsigned int)configurationDurationSeconds
126
configurationIsEnabled:(BOOL)configurationIsEnabled
127
createdByRemoteName:(nullable NSString *)createdByRemoteName
128
createdInExistingGroup:(BOOL)createdInExistingGroup
129
{
130
self = [super initWithGrdbId:grdbId
131
uniqueId:uniqueId
132
receivedAtTimestamp:receivedAtTimestamp
133
sortId:sortId
134
timestamp:timestamp
135
uniqueThreadId:uniqueThreadId
136
body:body
137
bodyRanges:bodyRanges
138
contactShare:contactShare
139
deprecated_attachmentIds:deprecated_attachmentIds
140
editState:editState
141
expireStartedAt:expireStartedAt
142
expireTimerVersion:expireTimerVersion
143
expiresAt:expiresAt
144
expiresInSeconds:expiresInSeconds
145
giftBadge:giftBadge
146
isGroupStoryReply:isGroupStoryReply
147
isPoll:isPoll
148
isSmsMessageRestoredFromBackup:isSmsMessageRestoredFromBackup
149
isViewOnceComplete:isViewOnceComplete
150
isViewOnceMessage:isViewOnceMessage
151
linkPreview:linkPreview
152
messageSticker:messageSticker
153
quotedMessage:quotedMessage
154
storedShouldStartExpireTimer:storedShouldStartExpireTimer
155
storyAuthorUuidString:storyAuthorUuidString
156
storyReactionEmoji:storyReactionEmoji
157
storyTimestamp:storyTimestamp
158
wasRemotelyDeleted:wasRemotelyDeleted
159
customMessage:customMessage
160
infoMessageUserInfo:infoMessageUserInfo
161
messageType:messageType
162
read:read
163
serverGuid:serverGuid
164
unregisteredAddress:unregisteredAddress];
165
166
if (!self) {
167
return self;
168
}
169
170
_configurationDurationSeconds = configurationDurationSeconds;
171
_configurationIsEnabled = configurationIsEnabled;
172
_createdByRemoteName = createdByRemoteName;
173
_createdInExistingGroup = createdInExistingGroup;
174
175
[self sdsFinalizeDisappearingConfigurationUpdateInfoMessage];
176
177
return self;
178
}
179
180
// clang-format on
181
182
// --- CODE GENERATION MARKER
183
184
- (void)sdsFinalizeDisappearingConfigurationUpdateInfoMessage
185
{
186
// At most one should be set
187
OWSAssertDebug(!self.createdByRemoteName || !self.createdInExistingGroup);
188
}
189
190
- (BOOL)shouldUseReceiptDateForSorting
191
{
192
// Use the timestamp, not the "received at" timestamp to sort,
193
// since we're creating these interactions after the fact and back-dating them.
194
return NO;
195
}
196
197
- (NSString *)infoMessagePreviewTextWithTransaction:(DBReadTransaction *)transaction
198
{
199
DisappearingMessageToken *newToken =
200
[[DisappearingMessageToken alloc] initWithIsEnabled:self.configurationIsEnabled
201
durationSeconds:self.configurationDurationSeconds];
202
return [[self class] legacyDisappearingMessageUpdateDescriptionWithToken:newToken
203
wasAddedToExistingGroup:self.createdInExistingGroup
204
updaterName:self.createdByRemoteName];
205
}
206
207
@end
208
209
NS_ASSUME_NONNULL_END
210
211