chat-utils: fix the clear chat chat mod

This commit is contained in:
Rajeh Taher
2024-10-14 02:52:23 +03:00
parent bf578c79e7
commit 647f8d767f
2 changed files with 26 additions and 18 deletions

View File

@@ -4,7 +4,7 @@ import type { BufferedEventData } from './Events'
import type { LabelActionBody } from './Label' import type { LabelActionBody } from './Label'
import type { ChatLabelAssociationActionBody } from './LabelAssociation' import type { ChatLabelAssociationActionBody } from './LabelAssociation'
import type { MessageLabelAssociationActionBody } from './LabelAssociation' import type { MessageLabelAssociationActionBody } from './LabelAssociation'
import type { MinimalMessage } from './Message' import type { MinimalMessage, WAMessageKey } from './Message'
/** privacy settings in WhatsApp Web */ /** privacy settings in WhatsApp Web */
export type WAPrivacyValue = 'all' | 'contacts' | 'contact_blacklist' | 'none' export type WAPrivacyValue = 'all' | 'contacts' | 'contact_blacklist' | 'none'
@@ -78,7 +78,9 @@ export type ChatModification =
mute: number | null mute: number | null
} }
| { | {
clear: 'all' | { messages: { id: string, fromMe?: boolean, timestamp: number }[] } clear: boolean
} | {
deleteForMe: { deleteMedia: boolean, key: WAMessageKey, timestamp: number }
} }
| { | {
star: { star: {

View File

@@ -553,23 +553,29 @@ export const chatModificationToAppPatch = (
apiVersion: 3, apiVersion: 3,
operation: OP.SET operation: OP.SET
} }
} else if('deleteForMe' in mod) {
const { timestamp, key, deleteMedia } = mod.deleteForMe
patch = {
syncAction: {
deleteMessageForMeAction: {
deleteMedia,
messageTimestamp: timestamp
}
},
index: ['deleteMessageForMe', jid, key.id!, key.fromMe ? '1' : '0', '0'],
type: 'regular_high',
apiVersion: 3,
operation: OP.SET
}
} else if('clear' in mod) { } else if('clear' in mod) {
if(mod.clear === 'all') { patch = {
throw new Boom('not supported') syncAction: {
} else { clearChatAction: {} // add message range later
const key = mod.clear.messages[0] },
patch = { index: ['clearChat', jid, '1' /*the option here is 0 when keep starred messages is enabled*/, '0'],
syncAction: { type: 'regular_high',
deleteMessageForMeAction: { apiVersion: 6,
deleteMedia: false, operation: OP.SET
messageTimestamp: key.timestamp
}
},
index: ['deleteMessageForMe', jid, key.id, key.fromMe ? '1' : '0', '0'],
type: 'regular_high',
apiVersion: 3,
operation: OP.SET
}
} }
} else if('pin' in mod) { } else if('pin' in mod) {
patch = { patch = {