diff --git a/keyserver/src/responders/message-responders.js b/keyserver/src/responders/message-responders.js --- a/keyserver/src/responders/message-responders.js +++ b/keyserver/src/responders/message-responders.js @@ -78,7 +78,7 @@ throw new ServerError('invalid_parameters'); } - const messageData: TextMessageData = { + let messageData: TextMessageData = { type: messageTypes.TEXT, threadID, creatorID: viewer.id, @@ -86,7 +86,7 @@ text, }; if (localID) { - messageData.localID = localID; + messageData = { ...messageData, localID }; } const rawMessageInfos = await createMessages(viewer, [messageData]); diff --git a/lib/shared/message-utils.js b/lib/shared/message-utils.js --- a/lib/shared/message-utils.js +++ b/lib/shared/message-utils.js @@ -263,6 +263,9 @@ time, media: photoMedia, }: ImagesMessageData); + if (localID) { + messageData = { ...messageData, localID }; + } } else { messageData = ({ type: messageTypes.MULTIMEDIA, @@ -271,9 +274,9 @@ time, media: input.media, }: MediaMessageData); - } - if (localID) { - messageData.localID = localID; + if (localID) { + messageData = { ...messageData, localID }; + } } return messageData; } diff --git a/lib/shared/messages/multimedia-message-spec.js b/lib/shared/messages/multimedia-message-spec.js --- a/lib/shared/messages/multimedia-message-spec.js +++ b/lib/shared/messages/multimedia-message-spec.js @@ -92,7 +92,7 @@ `media_infos must be defined`, ); - const rawMessageInfo: RawImagesMessageInfo | RawMediaMessageInfo = + let rawMessageInfo: RawImagesMessageInfo | RawMediaMessageInfo = messageType === messageTypes.IMAGES ? { type: messageTypes.IMAGES, @@ -113,10 +113,16 @@ }; if (clientDBMessageInfo.local_id) { - rawMessageInfo.localID = clientDBMessageInfo.local_id; + rawMessageInfo = { + ...rawMessageInfo, + localID: clientDBMessageInfo.local_id, + }; } if (clientDBMessageInfo.id !== clientDBMessageInfo.local_id) { - rawMessageInfo.id = clientDBMessageInfo.id; + rawMessageInfo = { + ...rawMessageInfo, + id: clientDBMessageInfo.id, + }; } return rawMessageInfo; }, @@ -150,7 +156,7 @@ creator: RelativeUserInfo, ): ?(MediaMessageInfo | ImagesMessageInfo) { if (rawMessageInfo.type === messageTypes.IMAGES) { - const messageInfo: ImagesMessageInfo = { + let messageInfo: ImagesMessageInfo = { type: messageTypes.IMAGES, threadID: rawMessageInfo.threadID, creator, @@ -158,14 +164,14 @@ media: rawMessageInfo.media, }; if (rawMessageInfo.id) { - messageInfo.id = rawMessageInfo.id; + messageInfo = { ...messageInfo, id: rawMessageInfo.id }; } if (rawMessageInfo.localID) { - messageInfo.localID = rawMessageInfo.localID; + messageInfo = { ...messageInfo, localID: rawMessageInfo.localID }; } return messageInfo; } else if (rawMessageInfo.type === messageTypes.MULTIMEDIA) { - const messageInfo: MediaMessageInfo = { + let messageInfo: MediaMessageInfo = { type: messageTypes.MULTIMEDIA, threadID: rawMessageInfo.threadID, creator, @@ -173,10 +179,10 @@ media: rawMessageInfo.media, }; if (rawMessageInfo.id) { - messageInfo.id = rawMessageInfo.id; + messageInfo = { ...messageInfo, id: rawMessageInfo.id }; } if (rawMessageInfo.localID) { - messageInfo.localID = rawMessageInfo.localID; + messageInfo = { ...messageInfo, localID: rawMessageInfo.localID }; } return messageInfo; } diff --git a/lib/shared/messages/text-message-spec.js b/lib/shared/messages/text-message-spec.js --- a/lib/shared/messages/text-message-spec.js +++ b/lib/shared/messages/text-message-spec.js @@ -100,7 +100,7 @@ row: Object, params: RawMessageInfoFromServerDBRowParams, ): RawTextMessageInfo { - const rawTextMessageInfo: RawTextMessageInfo = { + let rawTextMessageInfo: RawTextMessageInfo = { type: messageTypes.TEXT, id: row.id.toString(), threadID: row.threadID.toString(), @@ -109,7 +109,7 @@ text: row.content, }; if (params.localID) { - rawTextMessageInfo.localID = params.localID; + rawTextMessageInfo = { ...rawTextMessageInfo, localID: params.localID }; } return rawTextMessageInfo; }, @@ -117,7 +117,7 @@ rawMessageInfoFromClientDB( clientDBMessageInfo: ClientDBMessageInfo, ): RawTextMessageInfo { - const rawTextMessageInfo: RawTextMessageInfo = { + let rawTextMessageInfo: RawTextMessageInfo = { type: messageTypes.TEXT, threadID: clientDBMessageInfo.thread, time: parseInt(clientDBMessageInfo.time), @@ -125,10 +125,16 @@ text: clientDBMessageInfo.content ?? '', }; if (clientDBMessageInfo.local_id) { - rawTextMessageInfo.localID = clientDBMessageInfo.local_id; + rawTextMessageInfo = { + ...rawTextMessageInfo, + localID: clientDBMessageInfo.local_id, + }; } if (clientDBMessageInfo.id !== clientDBMessageInfo.local_id) { - rawTextMessageInfo.id = clientDBMessageInfo.id; + rawTextMessageInfo = { + ...rawTextMessageInfo, + id: clientDBMessageInfo.id, + }; } return rawTextMessageInfo; }, @@ -137,7 +143,7 @@ rawMessageInfo: RawTextMessageInfo, creator: RelativeUserInfo, ): TextMessageInfo { - const messageInfo: TextMessageInfo = { + let messageInfo: TextMessageInfo = { type: messageTypes.TEXT, threadID: rawMessageInfo.threadID, creator, @@ -145,10 +151,10 @@ text: rawMessageInfo.text, }; if (rawMessageInfo.id) { - messageInfo.id = rawMessageInfo.id; + messageInfo = { ...messageInfo, id: rawMessageInfo.id }; } if (rawMessageInfo.localID) { - messageInfo.localID = rawMessageInfo.localID; + messageInfo = { ...messageInfo, localID: rawMessageInfo.localID }; } return messageInfo; }, diff --git a/lib/types/messages/images.js b/lib/types/messages/images.js --- a/lib/types/messages/images.js +++ b/lib/types/messages/images.js @@ -4,25 +4,25 @@ import type { RelativeUserInfo } from '../user-types.js'; export type ImagesMessageData = { - type: 14, - localID?: string, // for optimistic creations. included by new clients - threadID: string, - creatorID: string, - time: number, - media: $ReadOnlyArray, + +type: 14, + +localID?: string, // for optimistic creations. included by new clients + +threadID: string, + +creatorID: string, + +time: number, + +media: $ReadOnlyArray, }; export type RawImagesMessageInfo = { ...ImagesMessageData, - id?: string, // null if local copy without ID yet + +id?: string, // null if local copy without ID yet }; export type ImagesMessageInfo = { - type: 14, - id?: string, // null if local copy without ID yet - localID?: string, // for optimistic creations - threadID: string, - creator: RelativeUserInfo, - time: number, // millisecond timestamp - media: $ReadOnlyArray, + +type: 14, + +id?: string, // null if local copy without ID yet + +localID?: string, // for optimistic creations + +threadID: string, + +creator: RelativeUserInfo, + +time: number, // millisecond timestamp + +media: $ReadOnlyArray, }; diff --git a/lib/types/messages/media.js b/lib/types/messages/media.js --- a/lib/types/messages/media.js +++ b/lib/types/messages/media.js @@ -4,27 +4,27 @@ import type { RelativeUserInfo } from '../user-types.js'; export type MediaMessageData = { - type: 15, - localID?: string, // for optimistic creations. included by new clients - threadID: string, - creatorID: string, - time: number, - media: $ReadOnlyArray, + +type: 15, + +localID?: string, // for optimistic creations. included by new clients + +threadID: string, + +creatorID: string, + +time: number, + +media: $ReadOnlyArray, }; export type RawMediaMessageInfo = { ...MediaMessageData, - id?: string, // null if local copy without ID yet + +id?: string, // null if local copy without ID yet }; export type MediaMessageInfo = { - type: 15, - id?: string, // null if local copy without ID yet - localID?: string, // for optimistic creations - threadID: string, - creator: RelativeUserInfo, - time: number, // millisecond timestamp - media: $ReadOnlyArray, + +type: 15, + +id?: string, // null if local copy without ID yet + +localID?: string, // for optimistic creations + +threadID: string, + +creator: RelativeUserInfo, + +time: number, // millisecond timestamp + +media: $ReadOnlyArray, }; export type MediaMessageServerDBContent = diff --git a/lib/types/messages/text.js b/lib/types/messages/text.js --- a/lib/types/messages/text.js +++ b/lib/types/messages/text.js @@ -3,25 +3,25 @@ import type { RelativeUserInfo } from '../user-types.js'; export type TextMessageData = { - type: 0, - localID?: string, // for optimistic creations. included by new clients - threadID: string, - creatorID: string, - time: number, - text: string, + +type: 0, + +localID?: string, // for optimistic creations. included by new clients + +threadID: string, + +creatorID: string, + +time: number, + +text: string, }; export type RawTextMessageInfo = { ...TextMessageData, - id?: string, // null if local copy without ID yet + +id?: string, // null if local copy without ID yet }; export type TextMessageInfo = { - type: 0, - id?: string, // null if local copy without ID yet - localID?: string, // for optimistic creations - threadID: string, - creator: RelativeUserInfo, - time: number, // millisecond timestamp - text: string, + +type: 0, + +id?: string, // null if local copy without ID yet + +localID?: string, // for optimistic creations + +threadID: string, + +creator: RelativeUserInfo, + +time: number, // millisecond timestamp + +text: string, };