Skip to content

Commit 3e6fb35

Browse files
committed
chore: cleanedup message attributes types
1 parent 3ff1528 commit 3e6fb35

File tree

3 files changed

+59
-99
lines changed

3 files changed

+59
-99
lines changed

ts/models/conversation.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2453,15 +2453,8 @@ export class ConversationModel extends Model<ConversationAttributes> {
24532453
}
24542454

24552455
private async addSingleMessage(messageAttributes: MessageAttributesOptionals) {
2456-
const voiceMessageFlags = messageAttributes.attachments?.[0]?.isVoiceMessage
2457-
? SignalService.AttachmentPointer.Flags.VOICE_MESSAGE
2458-
: undefined;
24592456
// eslint-disable-next-line no-bitwise
2460-
const flags = (messageAttributes?.flags || 0) | (voiceMessageFlags || 0);
2461-
const model = new MessageModel({
2462-
...messageAttributes,
2463-
flags,
2464-
});
2457+
const model = new MessageModel(messageAttributes);
24652458

24662459
const messageId = await model.commit(true);
24672460
model.set({ id: messageId });

ts/models/messageType.ts

Lines changed: 57 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@ import type { SignalService } from '../protobuf';
1818

1919
export type MessageModelType = 'incoming' | 'outgoing';
2020

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 = {
2625
/**
2726
* The sender/author of that message
2827
*/
@@ -45,35 +44,19 @@ export interface MessageAttributes {
4544
*/
4645
body?: string;
4746
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;
5247
expires_at?: number;
5348
expirationTimerUpdate?: ExpirationTimerUpdate;
54-
read_by: Array<string>; // we actually only care about the length of this. values are not used for anything
5549
type: MessageModelType;
5650
group_update?: MessageGroupUpdate;
5751
groupInvitation?: { url: string | undefined; name: string } | undefined;
5852
attachments?: any;
5953
conversationId: string;
6054
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;
6955
/**
7056
* timestamp is the sent_at timestamp, which is the envelope.timestamp
7157
*/
7258
timestamp?: number;
7359
status?: LastMessageStatusType;
74-
sent_to: Array<string>;
75-
sent: boolean;
76-
7760
/**
7861
* The serverId is the id on the open group server itself.
7962
* Each message sent to an open group gets a serverId.
@@ -88,22 +71,6 @@ export interface MessageAttributes {
8871
* This field is not set for a message not on an opengroup server.
8972
*/
9073
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-
10774
/**
10875
* This is used for when a user screenshots or saves an attachment you sent.
10976
* We display a small message just below the message referenced
@@ -113,8 +80,10 @@ export interface MessageAttributes {
11380
/**
11481
* For displaying a message to notifying when a request has been accepted.
11582
*/
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+
};
11887
/**
11988
* This field is used for unsending messages and used in sending update expiry, get expiries and unsend message requests.
12089
*/
@@ -131,7 +100,55 @@ export interface MessageAttributes {
131100
* 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.
132101
*/
133102
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>;
135152

136153
export interface MessageRequestResponseMsg {
137154
source: string;
@@ -160,57 +177,6 @@ export type MessageGroupUpdate = {
160177
avatarChange?: boolean;
161178
};
162179

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-
214180
/**
215181
* This function mutates optAttributes
216182
* @param optAttributes the entry object attributes to set the defaults to.

ts/test/session/unit/reactions/ReactionMessage_test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ describe('ReactionMessage', () => {
2828
beforeEach(() => {
2929
Sinon.stub(originalMessage, 'getConversation').returns({
3030
hasReactions: () => true,
31+
isPublic: () => false,
3132
sendReaction: noop,
3233
} as any);
3334

0 commit comments

Comments
 (0)