Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
signalapp
GitHub Repository: signalapp/Signal-iOS
Path: blob/main/SignalServiceKit/Messages/Interactions/TSInteraction.h
1 views
1
//
2
// Copyright 2017 Signal Messenger, LLC
3
// SPDX-License-Identifier: AGPL-3.0-only
4
//
5
6
#import <SignalServiceKit/BaseModel.h>
7
8
NS_ASSUME_NONNULL_BEGIN
9
10
@class DBReadTransaction;
11
@class TSThread;
12
13
typedef NS_CLOSED_ENUM(NSInteger, OWSInteractionType) {
14
OWSInteractionType_Unknown,
15
OWSInteractionType_IncomingMessage,
16
OWSInteractionType_OutgoingMessage,
17
OWSInteractionType_Error,
18
OWSInteractionType_Call,
19
OWSInteractionType_Info,
20
OWSInteractionType_TypingIndicator,
21
OWSInteractionType_ThreadDetails,
22
OWSInteractionType_UnreadIndicator,
23
OWSInteractionType_DateHeader,
24
OWSInteractionType_UnknownThreadWarning,
25
OWSInteractionType_DefaultDisappearingMessageTimer,
26
OWSInteractionType_CollapseSet,
27
};
28
29
NSString *NSStringFromOWSInteractionType(OWSInteractionType value);
30
31
@protocol OWSPreviewText <NSObject>
32
33
- (NSString *)previewTextWithTransaction:(DBReadTransaction *)transaction NS_SWIFT_NAME(previewText(transaction:));
34
35
@end
36
37
#pragma mark -
38
39
@interface TSInteraction : BaseModel
40
41
+ (instancetype)new NS_UNAVAILABLE;
42
- (instancetype)init NS_UNAVAILABLE;
43
- (void)encodeWithCoder:(NSCoder *)coder;
44
- (nullable instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER;
45
- (instancetype)initWithUniqueId:(NSString *)uniqueId NS_UNAVAILABLE;
46
- (instancetype)initWithGrdbId:(int64_t)grdbId uniqueId:(NSString *)uniqueId NS_UNAVAILABLE;
47
48
- (instancetype)initWithCustomUniqueId:(NSString *)uniqueId
49
timestamp:(uint64_t)timestamp
50
receivedAtTimestamp:(uint64_t)receivedAtTimestamp
51
thread:(TSThread *)thread NS_DESIGNATED_INITIALIZER;
52
53
- (instancetype)initWithTimestamp:(uint64_t)timestamp
54
receivedAtTimestamp:(uint64_t)receivedAtTimestamp
55
thread:(TSThread *)thread NS_DESIGNATED_INITIALIZER;
56
57
// --- CODE GENERATION MARKER
58
59
// This snippet is generated by /Scripts/sds_codegen/sds_generate.py. Do not manually edit it, instead run
60
// `sds_codegen.sh`.
61
62
// clang-format off
63
64
- (instancetype)initWithGrdbId:(int64_t)grdbId
65
uniqueId:(NSString *)uniqueId
66
receivedAtTimestamp:(uint64_t)receivedAtTimestamp
67
sortId:(uint64_t)sortId
68
timestamp:(uint64_t)timestamp
69
uniqueThreadId:(NSString *)uniqueThreadId
70
NS_DESIGNATED_INITIALIZER NS_SWIFT_NAME(init(grdbId:uniqueId:receivedAtTimestamp:sortId:timestamp:uniqueThreadId:));
71
72
// clang-format on
73
74
// --- CODE GENERATION MARKER
75
76
@property (nonatomic, readonly) NSString *uniqueThreadId;
77
78
@property (nonatomic, readonly) uint64_t sortId;
79
80
/// A generic "timestamp" for this interaction.
81
///
82
/// For incoming messages this is derived from the value of the incoming proto
83
/// `Envelope.timestamp`, and represents a client-generated timestamp from the
84
/// sender as to when they sent the message.
85
///
86
/// - Important
87
/// This property may also be set with a locally-generated value of "now" in
88
/// some codepaths, particularly for non-incoming messages and interactions like
89
/// info messages. Take care when using it.
90
///
91
/// - SeeAlso ``TSInteraction/receivedAtTimestamp``
92
/// - SeeAlso ``TSIncomingMessage/serverTimestamp``
93
/// - SeeAlso ``TSIncomingMessage/serverDeliveryTimestamp``
94
@property (nonatomic, readonly) uint64_t timestamp;
95
96
/// An always locally-generated timestamp representing when we "received" this
97
/// interaction.
98
///
99
/// - Important
100
/// For many interactions this will be the same or very close to
101
/// ``TSInteraction/timestamp``, in cases where that property is also
102
/// locally-generated when initializing or preparing to initialize the
103
/// interaction.
104
///
105
/// - SeeAlso ``TSInteraction/timestamp``
106
/// - SeeAlso ``TSIncomingMessage/serverTimestamp``
107
/// - SeeAlso ``TSIncomingMessage/serverDeliveryTimestamp``
108
@property (nonatomic, readonly) uint64_t receivedAtTimestamp;
109
110
@property (nonatomic, readonly) NSDate *receivedAtDate;
111
@property (nonatomic, readonly) NSDate *timestampDate;
112
113
@property (nonatomic, readonly) OWSInteractionType interactionType;
114
115
- (nullable TSThread *)threadWithTx:(DBReadTransaction *)tx NS_SWIFT_NAME(thread(tx:));
116
117
#pragma mark Utility Method
118
119
// "Dynamic" interactions are not messages or static events (like
120
// info messages, error messages, etc.). They are interactions
121
// created, updated and deleted by the views.
122
//
123
// These include block offers, "add to contact" offers,
124
// unseen message indicators, etc.
125
@property (nonatomic, readonly) BOOL isDynamicInteraction;
126
127
- (void)replaceSortId:(uint64_t)sortId;
128
129
#if TESTABLE_BUILD
130
- (void)replaceTimestamp:(uint64_t)timestamp transaction:(DBWriteTransaction *)transaction;
131
- (void)replaceReceivedAtTimestamp:(uint64_t)receivedAtTimestamp NS_SWIFT_NAME(replaceReceivedAtTimestamp(_:));
132
- (void)replaceReceivedAtTimestamp:(uint64_t)receivedAtTimestamp transaction:(DBWriteTransaction *)transaction;
133
#endif
134
135
@end
136
137
@interface TSInteraction (Subclass)
138
139
// Timestamps are *almost* always immutable. The one exception is for placeholder interactions.
140
// After a certain amount of time, a placeholder becomes ineligible for replacement. The would-be
141
// replacement is just inserted natively.
142
//
143
// This breaks all sorts of assumptions we have of timestamps being unique. To workaround this,
144
// we decrement the timestamp on a failed placeholder. This ensures that both the placeholder
145
// error message and the would-be replacement can coexist.
146
@property (nonatomic, assign) uint64_t timestamp;
147
148
@end
149
150
NS_ASSUME_NONNULL_END
151
152