refactor: message decoding

1. removes redundant receipt (was exactly the same as delivery receipt without the timestamp)
2. decodeWAMessage now returns a proper message struct
3. each message stanza results in exactly one message decoded
This commit is contained in:
Adhiraj Singh
2022-01-06 23:27:14 +05:30
parent 0b5d772b08
commit 6a2cb5a413
3 changed files with 51 additions and 124 deletions

View File

@@ -73,7 +73,10 @@ export const makeMessagesSocket = (config: SocketConfig) => {
}
return mediaConn
}
/**
* generic send receipt function
* used for receipts of phone call, read, delivery etc.
* */
const sendReceipt = async(jid: string, participant: string | undefined, messageIds: string[], type: 'read' | 'read-self' | undefined) => {
const node: BinaryNode = {
tag: 'receipt',
@@ -107,10 +110,6 @@ export const makeMessagesSocket = (config: SocketConfig) => {
await sendNode(node)
}
const sendDeliveryReceipt = (jid: string, participant: string | undefined, messageIds: string[]) => {
return sendReceipt(jid, participant, messageIds, undefined)
}
const sendReadReceipt = async(jid: string, participant: string | undefined, messageIds: string[]) => {
const privacySettings = await fetchPrivacySettings()
// based on privacy settings, we have to change the read type
@@ -424,7 +423,7 @@ export const makeMessagesSocket = (config: SocketConfig) => {
...sock,
assertSessions,
relayMessage,
sendDeliveryReceipt,
sendReceipt,
sendReadReceipt,
refreshMediaConn,
waUploadToServer,