Path: blob/main/SignalServiceKit/Messages/Interactions/TSInteraction.h
1 views
//1// Copyright 2017 Signal Messenger, LLC2// SPDX-License-Identifier: AGPL-3.0-only3//45#import <SignalServiceKit/BaseModel.h>67NS_ASSUME_NONNULL_BEGIN89@class DBReadTransaction;10@class TSThread;1112typedef NS_CLOSED_ENUM(NSInteger, OWSInteractionType) {13OWSInteractionType_Unknown,14OWSInteractionType_IncomingMessage,15OWSInteractionType_OutgoingMessage,16OWSInteractionType_Error,17OWSInteractionType_Call,18OWSInteractionType_Info,19OWSInteractionType_TypingIndicator,20OWSInteractionType_ThreadDetails,21OWSInteractionType_UnreadIndicator,22OWSInteractionType_DateHeader,23OWSInteractionType_UnknownThreadWarning,24OWSInteractionType_DefaultDisappearingMessageTimer,25OWSInteractionType_CollapseSet,26};2728NSString *NSStringFromOWSInteractionType(OWSInteractionType value);2930@protocol OWSPreviewText <NSObject>3132- (NSString *)previewTextWithTransaction:(DBReadTransaction *)transaction NS_SWIFT_NAME(previewText(transaction:));3334@end3536#pragma mark -3738@interface TSInteraction : BaseModel3940+ (instancetype)new NS_UNAVAILABLE;41- (instancetype)init NS_UNAVAILABLE;42- (void)encodeWithCoder:(NSCoder *)coder;43- (nullable instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER;44- (instancetype)initWithUniqueId:(NSString *)uniqueId NS_UNAVAILABLE;45- (instancetype)initWithGrdbId:(int64_t)grdbId uniqueId:(NSString *)uniqueId NS_UNAVAILABLE;4647- (instancetype)initWithCustomUniqueId:(NSString *)uniqueId48timestamp:(uint64_t)timestamp49receivedAtTimestamp:(uint64_t)receivedAtTimestamp50thread:(TSThread *)thread NS_DESIGNATED_INITIALIZER;5152- (instancetype)initWithTimestamp:(uint64_t)timestamp53receivedAtTimestamp:(uint64_t)receivedAtTimestamp54thread:(TSThread *)thread NS_DESIGNATED_INITIALIZER;5556// --- CODE GENERATION MARKER5758// This snippet is generated by /Scripts/sds_codegen/sds_generate.py. Do not manually edit it, instead run59// `sds_codegen.sh`.6061// clang-format off6263- (instancetype)initWithGrdbId:(int64_t)grdbId64uniqueId:(NSString *)uniqueId65receivedAtTimestamp:(uint64_t)receivedAtTimestamp66sortId:(uint64_t)sortId67timestamp:(uint64_t)timestamp68uniqueThreadId:(NSString *)uniqueThreadId69NS_DESIGNATED_INITIALIZER NS_SWIFT_NAME(init(grdbId:uniqueId:receivedAtTimestamp:sortId:timestamp:uniqueThreadId:));7071// clang-format on7273// --- CODE GENERATION MARKER7475@property (nonatomic, readonly) NSString *uniqueThreadId;7677@property (nonatomic, readonly) uint64_t sortId;7879/// A generic "timestamp" for this interaction.80///81/// For incoming messages this is derived from the value of the incoming proto82/// `Envelope.timestamp`, and represents a client-generated timestamp from the83/// sender as to when they sent the message.84///85/// - Important86/// This property may also be set with a locally-generated value of "now" in87/// some codepaths, particularly for non-incoming messages and interactions like88/// info messages. Take care when using it.89///90/// - SeeAlso ``TSInteraction/receivedAtTimestamp``91/// - SeeAlso ``TSIncomingMessage/serverTimestamp``92/// - SeeAlso ``TSIncomingMessage/serverDeliveryTimestamp``93@property (nonatomic, readonly) uint64_t timestamp;9495/// An always locally-generated timestamp representing when we "received" this96/// interaction.97///98/// - Important99/// For many interactions this will be the same or very close to100/// ``TSInteraction/timestamp``, in cases where that property is also101/// locally-generated when initializing or preparing to initialize the102/// interaction.103///104/// - SeeAlso ``TSInteraction/timestamp``105/// - SeeAlso ``TSIncomingMessage/serverTimestamp``106/// - SeeAlso ``TSIncomingMessage/serverDeliveryTimestamp``107@property (nonatomic, readonly) uint64_t receivedAtTimestamp;108109@property (nonatomic, readonly) NSDate *receivedAtDate;110@property (nonatomic, readonly) NSDate *timestampDate;111112@property (nonatomic, readonly) OWSInteractionType interactionType;113114- (nullable TSThread *)threadWithTx:(DBReadTransaction *)tx NS_SWIFT_NAME(thread(tx:));115116#pragma mark Utility Method117118// "Dynamic" interactions are not messages or static events (like119// info messages, error messages, etc.). They are interactions120// created, updated and deleted by the views.121//122// These include block offers, "add to contact" offers,123// unseen message indicators, etc.124@property (nonatomic, readonly) BOOL isDynamicInteraction;125126- (void)replaceSortId:(uint64_t)sortId;127128#if TESTABLE_BUILD129- (void)replaceTimestamp:(uint64_t)timestamp transaction:(DBWriteTransaction *)transaction;130- (void)replaceReceivedAtTimestamp:(uint64_t)receivedAtTimestamp NS_SWIFT_NAME(replaceReceivedAtTimestamp(_:));131- (void)replaceReceivedAtTimestamp:(uint64_t)receivedAtTimestamp transaction:(DBWriteTransaction *)transaction;132#endif133134@end135136@interface TSInteraction (Subclass)137138// Timestamps are *almost* always immutable. The one exception is for placeholder interactions.139// After a certain amount of time, a placeholder becomes ineligible for replacement. The would-be140// replacement is just inserted natively.141//142// This breaks all sorts of assumptions we have of timestamps being unique. To workaround this,143// we decrement the timestamp on a failed placeholder. This ensures that both the placeholder144// error message and the would-be replacement can coexist.145@property (nonatomic, assign) uint64_t timestamp;146147@end148149NS_ASSUME_NONNULL_END150151152