fix: delivery receipts

This commit is contained in:
Adhiraj Singh
2021-11-06 16:58:46 +05:30
parent 5a33fd85a4
commit 609c925225
2 changed files with 25 additions and 17 deletions

View File

@@ -1,7 +1,7 @@
import got from "got"
import { Boom } from "@hapi/boom"
import { SocketConfig, MediaConnInfo, AnyMessageContent, MiscMessageGenerationOptions, WAMediaUploadFunction, MessageRelayOptions } from "../Types"
import { SocketConfig, MediaConnInfo, AnyMessageContent, MiscMessageGenerationOptions, WAMediaUploadFunction, MessageRelayOptions, WAMessageKey } from "../Types"
import { encodeWAMessage, generateMessageID, generateWAMessage, encryptSenderKeyMsgSignalProto, encryptSignalProto, extractDeviceJids, jidToSignalProtocolAddress, parseAndInjectE2ESession } from "../Utils"
import { BinaryNode, getBinaryNodeChild, getBinaryNodeChildren, isJidGroup, jidDecode, jidEncode, jidNormalizedUser, S_WHATSAPP_NET, BinaryNodeAttributes } from '../WABinary'
import { proto } from "../../WAProto"
@@ -77,19 +77,18 @@ export const makeMessagesSocket = (config: SocketConfig) => {
return mediaConn
}
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
const readType = privacySettings.readreceipts === 'all' ? 'read' : 'read-self'
const sendReceipt = async(jid: string, participant: string | undefined, messageIds: string[], type: 'read' | 'read-self' | undefined) => {
const node: BinaryNode = {
tag: 'receipt',
attrs: {
id: messageIds[0],
t: Date.now().toString(),
to: jid,
type: readType
},
}
if(type) {
node.attrs.type = type
}
if(participant) {
node.attrs.participant = participant
}
@@ -111,6 +110,17 @@ 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
const readType = privacySettings.readreceipts === 'all' ? 'read' : 'read-self'
return sendReceipt(jid, participant, messageIds, readType)
}
const getUSyncDevices = async(jids: string[], ignoreZeroDevices: boolean) => {
jids = Array.from(new Set(jids))
const users = jids.map<BinaryNode>(jid => ({
@@ -387,6 +397,7 @@ export const makeMessagesSocket = (config: SocketConfig) => {
...sock,
assertSession,
relayMessage,
sendDeliveryReceipt,
sendReadReceipt,
refreshMediaConn,
fetchPrivacySettings,