mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
feat: add sanity check for chat modifications
This commit is contained in:
@@ -420,9 +420,19 @@ export const chatModificationToAppPatch = (
|
|||||||
lastMessages: Pick<proto.IWebMessageInfo, 'key' | 'messageTimestamp'>[]
|
lastMessages: Pick<proto.IWebMessageInfo, 'key' | 'messageTimestamp'>[]
|
||||||
) => {
|
) => {
|
||||||
const OP = proto.SyncdMutation.SyncdMutationSyncdOperation
|
const OP = proto.SyncdMutation.SyncdMutationSyncdOperation
|
||||||
const messageRange: proto.ISyncActionMessageRange = {
|
const getMessageRange = () => {
|
||||||
lastMessageTimestamp: lastMessages[lastMessages.length-1]?.messageTimestamp,
|
if(!lastMessages?.length) {
|
||||||
messages: lastMessages
|
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
|
||||||
|
}
|
||||||
|
return messageRange
|
||||||
}
|
}
|
||||||
let patch: WAPatchCreate
|
let patch: WAPatchCreate
|
||||||
if('mute' in mod) {
|
if('mute' in mod) {
|
||||||
@@ -443,7 +453,7 @@ export const chatModificationToAppPatch = (
|
|||||||
syncAction: {
|
syncAction: {
|
||||||
archiveChatAction: {
|
archiveChatAction: {
|
||||||
archived: !!mod.archive,
|
archived: !!mod.archive,
|
||||||
messageRange
|
messageRange: getMessageRange()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
index: ['archive', jid],
|
index: ['archive', jid],
|
||||||
@@ -456,7 +466,7 @@ export const chatModificationToAppPatch = (
|
|||||||
syncAction: {
|
syncAction: {
|
||||||
markChatAsReadAction: {
|
markChatAsReadAction: {
|
||||||
read: mod.markRead,
|
read: mod.markRead,
|
||||||
messageRange
|
messageRange: getMessageRange()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
index: ['markChatAsRead', jid],
|
index: ['markChatAsRead', jid],
|
||||||
|
|||||||
Reference in New Issue
Block a user