fix: do not throw error on conditions not matching in lastMessage check

This commit is contained in:
Adhiraj Singh
2022-04-28 15:24:10 +05:30
parent 13ca4c5917
commit dba6d2e0cb
2 changed files with 4 additions and 12 deletions

View File

@@ -33,8 +33,8 @@ export type Chat = Omit<proto.IConversation, 'messages'> & {
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<proto.IWebMessageInfo, 'key' | 'messageTimestamp'>[]

View File

@@ -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
}