Path: blob/main/SignalServiceKit/Messages/Interactions/OWSDisappearingConfigurationUpdateInfoMessage.m
1 views
//1// Copyright 2018 Signal Messenger, LLC2// SPDX-License-Identifier: AGPL-3.0-only3//45#import "OWSDisappearingConfigurationUpdateInfoMessage.h"6#import <SignalServiceKit/SignalServiceKit-Swift.h>78NS_ASSUME_NONNULL_BEGIN910@interface OWSDisappearingConfigurationUpdateInfoMessage ()1112@property (nonatomic, readonly, nullable) NSString *createdByRemoteName;13@property (nonatomic, readonly) uint32_t configurationDurationSeconds;1415/// This property is set for legacy messages, but always set to `false` for new16/// messages.17@property (nonatomic, readonly) BOOL createdInExistingGroup;1819@end2021#pragma mark -2223@implementation OWSDisappearingConfigurationUpdateInfoMessage2425- (NSUInteger)hash26{27NSUInteger result = [super hash];28result ^= self.configurationDurationSeconds;29result ^= self.configurationIsEnabled;30result ^= self.createdByRemoteName.hash;31result ^= self.createdInExistingGroup;32return result;33}3435- (BOOL)isEqual:(id)other36{37if (![super isEqual:other]) {38return NO;39}40OWSDisappearingConfigurationUpdateInfoMessage *typedOther = (OWSDisappearingConfigurationUpdateInfoMessage *)other;41if (self.configurationDurationSeconds != typedOther.configurationDurationSeconds) {42return NO;43}44if (self.configurationIsEnabled != typedOther.configurationIsEnabled) {45return NO;46}47if (![NSObject isObject:self.createdByRemoteName equalToObject:typedOther.createdByRemoteName]) {48return NO;49}50if (self.createdInExistingGroup != typedOther.createdInExistingGroup) {51return NO;52}53return YES;54}5556- (instancetype)initWithContactThread:(TSContactThread *)contactThread57timestamp:(uint64_t)timestamp58isConfigurationEnabled:(BOOL)isConfigurationEnabled59configurationDurationSeconds:(uint32_t)configurationDurationSeconds60createdByRemoteName:(nullable NSString *)remoteName61{62self = [super initWithThread:contactThread63timestamp:timestamp64serverGuid:nil65messageType:TSInfoMessageTypeDisappearingMessagesUpdate66expireTimerVersion:nil67expiresInSeconds:068infoMessageUserInfo:nil];69if (!self) {70return self;71}7273_configurationIsEnabled = isConfigurationEnabled;74_configurationDurationSeconds = configurationDurationSeconds;75_createdByRemoteName = remoteName;7677_createdInExistingGroup = false;7879return self;80}8182// --- CODE GENERATION MARKER8384// This snippet is generated by /Scripts/sds_codegen/sds_generate.py. Do not manually edit it, instead run85// `sds_codegen.sh`.8687// clang-format off8889- (instancetype)initWithGrdbId:(int64_t)grdbId90uniqueId:(NSString *)uniqueId91receivedAtTimestamp:(uint64_t)receivedAtTimestamp92sortId:(uint64_t)sortId93timestamp:(uint64_t)timestamp94uniqueThreadId:(NSString *)uniqueThreadId95body:(nullable NSString *)body96bodyRanges:(nullable MessageBodyRanges *)bodyRanges97contactShare:(nullable OWSContact *)contactShare98deprecated_attachmentIds:(nullable NSArray<NSString *> *)deprecated_attachmentIds99editState:(TSEditState)editState100expireStartedAt:(uint64_t)expireStartedAt101expireTimerVersion:(nullable NSNumber *)expireTimerVersion102expiresAt:(uint64_t)expiresAt103expiresInSeconds:(unsigned int)expiresInSeconds104giftBadge:(nullable OWSGiftBadge *)giftBadge105isGroupStoryReply:(BOOL)isGroupStoryReply106isPoll:(BOOL)isPoll107isSmsMessageRestoredFromBackup:(BOOL)isSmsMessageRestoredFromBackup108isViewOnceComplete:(BOOL)isViewOnceComplete109isViewOnceMessage:(BOOL)isViewOnceMessage110linkPreview:(nullable OWSLinkPreview *)linkPreview111messageSticker:(nullable MessageSticker *)messageSticker112quotedMessage:(nullable TSQuotedMessage *)quotedMessage113storedShouldStartExpireTimer:(BOOL)storedShouldStartExpireTimer114storyAuthorUuidString:(nullable NSString *)storyAuthorUuidString115storyReactionEmoji:(nullable NSString *)storyReactionEmoji116storyTimestamp:(nullable NSNumber *)storyTimestamp117wasRemotelyDeleted:(BOOL)wasRemotelyDeleted118customMessage:(nullable NSString *)customMessage119infoMessageUserInfo:(nullable NSDictionary<InfoMessageUserInfoKey, id> *)infoMessageUserInfo120messageType:(TSInfoMessageType)messageType121read:(BOOL)read122serverGuid:(nullable NSString *)serverGuid123unregisteredAddress:(nullable SignalServiceAddress *)unregisteredAddress124configurationDurationSeconds:(unsigned int)configurationDurationSeconds125configurationIsEnabled:(BOOL)configurationIsEnabled126createdByRemoteName:(nullable NSString *)createdByRemoteName127createdInExistingGroup:(BOOL)createdInExistingGroup128{129self = [super initWithGrdbId:grdbId130uniqueId:uniqueId131receivedAtTimestamp:receivedAtTimestamp132sortId:sortId133timestamp:timestamp134uniqueThreadId:uniqueThreadId135body:body136bodyRanges:bodyRanges137contactShare:contactShare138deprecated_attachmentIds:deprecated_attachmentIds139editState:editState140expireStartedAt:expireStartedAt141expireTimerVersion:expireTimerVersion142expiresAt:expiresAt143expiresInSeconds:expiresInSeconds144giftBadge:giftBadge145isGroupStoryReply:isGroupStoryReply146isPoll:isPoll147isSmsMessageRestoredFromBackup:isSmsMessageRestoredFromBackup148isViewOnceComplete:isViewOnceComplete149isViewOnceMessage:isViewOnceMessage150linkPreview:linkPreview151messageSticker:messageSticker152quotedMessage:quotedMessage153storedShouldStartExpireTimer:storedShouldStartExpireTimer154storyAuthorUuidString:storyAuthorUuidString155storyReactionEmoji:storyReactionEmoji156storyTimestamp:storyTimestamp157wasRemotelyDeleted:wasRemotelyDeleted158customMessage:customMessage159infoMessageUserInfo:infoMessageUserInfo160messageType:messageType161read:read162serverGuid:serverGuid163unregisteredAddress:unregisteredAddress];164165if (!self) {166return self;167}168169_configurationDurationSeconds = configurationDurationSeconds;170_configurationIsEnabled = configurationIsEnabled;171_createdByRemoteName = createdByRemoteName;172_createdInExistingGroup = createdInExistingGroup;173174[self sdsFinalizeDisappearingConfigurationUpdateInfoMessage];175176return self;177}178179// clang-format on180181// --- CODE GENERATION MARKER182183- (void)sdsFinalizeDisappearingConfigurationUpdateInfoMessage184{185// At most one should be set186OWSAssertDebug(!self.createdByRemoteName || !self.createdInExistingGroup);187}188189- (BOOL)shouldUseReceiptDateForSorting190{191// Use the timestamp, not the "received at" timestamp to sort,192// since we're creating these interactions after the fact and back-dating them.193return NO;194}195196- (NSString *)infoMessagePreviewTextWithTransaction:(DBReadTransaction *)transaction197{198DisappearingMessageToken *newToken =199[[DisappearingMessageToken alloc] initWithIsEnabled:self.configurationIsEnabled200durationSeconds:self.configurationDurationSeconds];201return [[self class] legacyDisappearingMessageUpdateDescriptionWithToken:newToken202wasAddedToExistingGroup:self.createdInExistingGroup203updaterName:self.createdByRemoteName];204}205206@end207208NS_ASSUME_NONNULL_END209210211