@@ -18,11 +18,10 @@ import type { SignalService } from '../protobuf';
18
18
19
19
export type MessageModelType = 'incoming' | 'outgoing' ;
20
20
21
- export interface MessageAttributes {
22
- /**
23
- * the local if of this message (i.e. an id only used locally)
24
- */
25
- id : string ;
21
+ /**
22
+ * The shared attributes that are for both (MessageAttributes & MessageAttributesOptionals) optionals.
23
+ */
24
+ type SharedMessageAttributes = {
26
25
/**
27
26
* The sender/author of that message
28
27
*/
@@ -45,35 +44,19 @@ export interface MessageAttributes {
45
44
*/
46
45
body ?: string ;
47
46
expirationType ?: DisappearingMessageType ;
48
- /** in seconds, 0 means no expiration */
49
- expireTimer : number ;
50
- /** when the expireTimer above started to count, in milliseconds */
51
- expirationStartTimestamp : number ;
52
47
expires_at ?: number ;
53
48
expirationTimerUpdate ?: ExpirationTimerUpdate ;
54
- read_by : Array < string > ; // we actually only care about the length of this. values are not used for anything
55
49
type : MessageModelType ;
56
50
group_update ?: MessageGroupUpdate ;
57
51
groupInvitation ?: { url : string | undefined ; name : string } | undefined ;
58
52
attachments ?: any ;
59
53
conversationId : string ;
60
54
errors ?: string ;
61
- hasAttachments : 1 | 0 ;
62
- hasFileAttachments : 1 | 0 ;
63
- hasVisualMediaAttachments : 1 | 0 ;
64
- /**
65
- * 1 means unread, 0 or anything else is read.
66
- * You can use the values from READ_MESSAGE_STATE.unread and READ_MESSAGE_STATE.read
67
- */
68
- unread : number ;
69
55
/**
70
56
* timestamp is the sent_at timestamp, which is the envelope.timestamp
71
57
*/
72
58
timestamp ?: number ;
73
59
status ?: LastMessageStatusType ;
74
- sent_to : Array < string > ;
75
- sent : boolean ;
76
-
77
60
/**
78
61
* The serverId is the id on the open group server itself.
79
62
* Each message sent to an open group gets a serverId.
@@ -88,22 +71,6 @@ export interface MessageAttributes {
88
71
* This field is not set for a message not on an opengroup server.
89
72
*/
90
73
serverTimestamp ?: number ;
91
-
92
- /**
93
- * sentSync set to true means we just triggered the sync message for this Private Chat message.
94
- * We did not yet get the message sent confirmation, it was just added to the Outgoing MessageQueue
95
- */
96
- sentSync : boolean ;
97
-
98
- /**
99
- * synced set to true means that this message was successfully sent by our current device to our other devices.
100
- * It is set to true when the MessageQueue did effectively sent our sync message without errors.
101
- */
102
- synced : boolean ;
103
- sync : boolean ;
104
-
105
- direction : MessageModelType ;
106
-
107
74
/**
108
75
* This is used for when a user screenshots or saves an attachment you sent.
109
76
* We display a small message just below the message referenced
@@ -113,8 +80,10 @@ export interface MessageAttributes {
113
80
/**
114
81
* For displaying a message to notifying when a request has been accepted.
115
82
*/
116
- messageRequestResponse ?: MessageRequestResponseMsg ;
117
-
83
+ messageRequestResponse ?: {
84
+ // keeping it as a object in case we ever add a field here.
85
+ // Note: we had isApproved field, but it was unused so I got rid of it
86
+ } ;
118
87
/**
119
88
* This field is used for unsending messages and used in sending update expiry, get expiries and unsend message requests.
120
89
*/
@@ -131,7 +100,55 @@ export interface MessageAttributes {
131
100
* This is used when a user has performed an interaction (hiding, leaving, etc.) on a conversation. At the moment, this is only used for showing interaction errors.
132
101
*/
133
102
interactionNotification ?: InteractionNotificationType ;
134
- }
103
+ } ;
104
+
105
+ type NotSharedMessageAttributes = {
106
+ /**
107
+ * The local if of this message (i.e. an id only used locally).
108
+ * Added on commit() if unset before that
109
+ */
110
+ id : string ;
111
+ /** in seconds, 0 means no expiration */
112
+ expireTimer : number ;
113
+ /** when the expireTimer above started to count, in milliseconds */
114
+ expirationStartTimestamp : number ;
115
+ read_by : Array < string > ; // we actually only care about the length of this. values are not used for anything
116
+
117
+ hasAttachments : 1 | 0 ;
118
+ hasFileAttachments : 1 | 0 ;
119
+ hasVisualMediaAttachments : 1 | 0 ;
120
+ /**
121
+ * 1 means unread, 0 or anything else is read.
122
+ * You can use the values from READ_MESSAGE_STATE.unread and READ_MESSAGE_STATE.read
123
+ */
124
+ unread : number ;
125
+
126
+ sent_to : Array < string > ;
127
+ sent : boolean ;
128
+
129
+ /**
130
+ * `sentSync` is set to true means we just triggered the sync message for this Private Chat message.
131
+ * We did not yet get the message sent confirmation, it was just added to the Outgoing MessageQueue
132
+ */
133
+ sentSync : boolean ;
134
+
135
+ /**
136
+ * `synced` is set to true means that this message was successfully sent by our current device to our other devices.
137
+ * It is set to true when the MessageQueue did effectively sent our sync message without errors.
138
+ */
139
+ synced : boolean ;
140
+ sync : boolean ;
141
+ direction : MessageModelType ;
142
+ } ;
143
+
144
+ export type MessageAttributes = SharedMessageAttributes & NotSharedMessageAttributes ;
145
+
146
+ /**
147
+ * The attributes of a message as they can be used to construct a message before the first commit().
148
+ * Most of those are optionals, but a few are required.
149
+ */
150
+ export type MessageAttributesOptionals = SharedMessageAttributes &
151
+ Partial < NotSharedMessageAttributes > ;
135
152
136
153
export interface MessageRequestResponseMsg {
137
154
source : string ;
@@ -160,57 +177,6 @@ export type MessageGroupUpdate = {
160
177
avatarChange ?: boolean ;
161
178
} ;
162
179
163
- export interface MessageAttributesOptionals {
164
- id ?: string ;
165
- source : string ;
166
- quote ?: any ;
167
- received_at ?: number ;
168
- sent_at ?: number ;
169
- preview ?: any ;
170
- reaction ?: Reaction ;
171
- reacts ?: ReactionList ;
172
- reactsIndex ?: number ;
173
- body ?: string ;
174
- expirationType ?: DisappearingMessageType ;
175
- expireTimer ?: number ;
176
- expirationStartTimestamp ?: number ;
177
- expires_at ?: number ;
178
- expirationTimerUpdate ?: ExpirationTimerUpdate ;
179
- read_by ?: Array < string > ; // we actually only care about the length of this. values are not used for anything
180
- type : MessageModelType ;
181
- group_update ?: MessageGroupUpdate ;
182
- groupInvitation ?: { url : string | undefined ; name : string } | undefined ;
183
- attachments ?: any ;
184
- conversationId : string ;
185
- errors ?: any ;
186
- flags ?: number ;
187
- hasAttachments ?: 1 | 0 ;
188
- hasFileAttachments ?: 1 | 0 ;
189
- hasVisualMediaAttachments ?: 1 | 0 ;
190
- dataExtractionNotification ?: DataExtractionNotificationMsg ;
191
- messageRequestResponse ?: {
192
- // keeping it as a object in case we ever add a field here.
193
- // Note: we had isApproved field, but it was unused so I got rid of it
194
- } ;
195
- unread ?: number ;
196
- group ?: any ;
197
- timestamp ?: number ;
198
- status ?: LastMessageStatusType ;
199
- sent_to ?: Array < string > ;
200
- sent ?: boolean ;
201
- serverId ?: number ;
202
- serverTimestamp ?: number ;
203
- isPublic ?: boolean ;
204
- sentSync ?: boolean ;
205
- synced ?: boolean ;
206
- sync ?: boolean ;
207
- direction ?: MessageModelType ;
208
- messageHash ?: string ;
209
- isDeleted ?: boolean ;
210
- callNotificationType ?: CallNotificationType ;
211
- interactionNotification ?: InteractionNotificationType ;
212
- }
213
-
214
180
/**
215
181
* This function mutates optAttributes
216
182
* @param optAttributes the entry object attributes to set the defaults to.
0 commit comments