diff --git a/src/Types/Chat.ts b/src/Types/Chat.ts index edba11d..8bd0fe5 100644 --- a/src/Types/Chat.ts +++ b/src/Types/Chat.ts @@ -33,8 +33,8 @@ export type Chat = Omit & { archive?: boolean } /** - * the last messages in a chat, sorted reverse-chronologically - * for MD modifications, the last message in the array must be the last message recv in the chat + * the last messages in a chat, sorted reverse-chronologically. That is, the latest message should be first in the chat + * for MD modifications, the last message in the array (i.e. the earlist message) must be the last message recv in the chat * */ export type LastMessageList = Pick[] diff --git a/src/Utils/chat-utils.ts b/src/Utils/chat-utils.ts index 3521222..08112ee 100644 --- a/src/Utils/chat-utils.ts +++ b/src/Utils/chat-utils.ts @@ -447,18 +447,10 @@ export const chatModificationToAppPatch = ( ) => { const OP = proto.SyncdMutation.SyncdMutationSyncdOperation const getMessageRange = (lastMessages: LastMessageList) => { - if(!lastMessages?.length) { - throw new Boom('Expected last message to be not from me', { statusCode: 400 }) - } - const lastMsg = lastMessages[lastMessages.length - 1] - if(lastMsg.key.fromMe) { - throw new Boom('Expected last message in array to be not from me', { statusCode: 400 }) - } - const messageRange: proto.ISyncActionMessageRange = { lastMessageTimestamp: lastMsg?.messageTimestamp, - messages: lastMessages.map( + messages: lastMessages?.length ? lastMessages.map( m => { if(m.key.participant) { m.key = { ...m.key } @@ -467,7 +459,7 @@ export const chatModificationToAppPatch = ( return m } - ) + ) : undefined } return messageRange }