MessageInfo

This commit is contained in:
Adhiraj
2020-07-12 19:01:14 +05:30
parent 40df8f5d00
commit dc7ed2c0c0
2 changed files with 19 additions and 1 deletions

View File

@@ -58,6 +58,7 @@ export const HKDFInfoKeys = {
}
export enum Mimetype {
jpeg = 'image/jpeg',
png = 'image/png',
mp4 = 'video/mp4',
gif = 'video/gif',
pdf = 'appliction/pdf',
@@ -74,6 +75,10 @@ export interface MessageOptions {
validateID?: boolean,
filename?: string
}
export interface MessageInfo {
reads: {jid: string, t: string}[]
deliveries: {jid: string, t: string}[]
}
export interface MessageStatusUpdate {
from: string
to: string

View File

@@ -11,6 +11,7 @@ import {
WASendMessageResponse,
WAMessageKey,
ChatModification,
MessageInfo,
} from './Constants'
import { generateMessageID, sha256, hmacSign, aesEncrypWithIV, randomBytes } from '../WAConnection/Utils'
import { WAMessageContent, WAMetric, WAFlag, WANode, WAMessage } from '../WAConnection/Constants'
@@ -21,7 +22,19 @@ export default class WhatsAppWebMessages extends WhatsAppWebBase {
/** Get the message info, who has read it, who its been delivered to */
async messageInfo (jid: string, messageID: string) {
const query = ['query', {type: 'message_info', index: messageID, jid: jid, epoch: this.msgCount.toString()}, null]
return this.queryExpecting200 (query, [22, WAFlag.ignore])
const response = (await this.queryExpecting200 (query, [22, WAFlag.ignore]))[2] as WANode[]
const info: MessageInfo = {reads: [], deliveries: []}
const reads = response.filter (node => node[0] === 'read')
if (reads[0]) {
info.reads = reads[0][2].map (item => item[1])
}
const deliveries = response.filter (node => node[0] === 'delivery')
if (reads[0]) {
info.reads = reads[0][2].map (item => item[1])
}
return info
}
/**
* Send a read receipt to the given ID for a certain message