Skip to content

Commit

Permalink
chat-utils: fix the clear chat chat mod
Browse files Browse the repository at this point in the history
  • Loading branch information
purpshell committed Oct 13, 2024
1 parent bf578c7 commit 647f8d7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
6 changes: 4 additions & 2 deletions src/Types/Chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { BufferedEventData } from './Events'
import type { LabelActionBody } from './Label'
import type { ChatLabelAssociationActionBody } from './LabelAssociation'
import type { MessageLabelAssociationActionBody } from './LabelAssociation'
import type { MinimalMessage } from './Message'
import type { MinimalMessage, WAMessageKey } from './Message'

/** privacy settings in WhatsApp Web */
export type WAPrivacyValue = 'all' | 'contacts' | 'contact_blacklist' | 'none'
Expand Down Expand Up @@ -78,7 +78,9 @@ export type ChatModification =
mute: number | null
}
| {
clear: 'all' | { messages: { id: string, fromMe?: boolean, timestamp: number }[] }
clear: boolean
} | {
deleteForMe: { deleteMedia: boolean, key: WAMessageKey, timestamp: number }
}
| {
star: {
Expand Down
38 changes: 22 additions & 16 deletions src/Utils/chat-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,23 +553,29 @@ export const chatModificationToAppPatch = (
apiVersion: 3,
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) {
if(mod.clear === 'all') {
throw new Boom('not supported')
} else {
const key = mod.clear.messages[0]
patch = {
syncAction: {
deleteMessageForMeAction: {
deleteMedia: false,
messageTimestamp: key.timestamp
}
},
index: ['deleteMessageForMe', jid, key.id, key.fromMe ? '1' : '0', '0'],
type: 'regular_high',
apiVersion: 3,
operation: OP.SET
}
patch = {
syncAction: {
clearChatAction: {} // add message range later
},
index: ['clearChat', jid, '1' /*the option here is 0 when keep starred messages is enabled*/, '0'],
type: 'regular_high',
apiVersion: 6,
operation: OP.SET
}
} else if('pin' in mod) {
patch = {
Expand Down

0 comments on commit 647f8d7

Please sign in to comment.