From f29c5cf2069302949ccf2cbb8cbc3f60482a275b Mon Sep 17 00:00:00 2001 From: Adhiraj Singh Date: Tue, 17 Nov 2020 17:12:14 +0530 Subject: [PATCH] Add name to presence update --- Example/example.ts | 2 +- src/WAConnection/0.Base.ts | 1 - src/WAConnection/4.Events.ts | 6 +++++- src/WAConnection/Constants.ts | 1 + 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Example/example.ts b/Example/example.ts index a58278f..0da3a98 100644 --- a/Example/example.ts +++ b/Example/example.ts @@ -53,7 +53,7 @@ async function example() { }) conn.on('chat-update', async chat => { if (chat.presences) { // receive presence updates -- composing, available, etc. - Object.keys(chat.presences).forEach(jid => console.log( `${jid}'s presence is ${chat.presences[jid].lastKnownPresence} in ${chat.jid}`)) + Object.values(chat.presences).forEach(presence => console.log( `${presence.name}'s presence is ${presence.lastKnownPresence} in ${chat.jid}`)) } // only do something when a new message is received; i.e. the unread count is updated if (!chat.count) return diff --git a/src/WAConnection/0.Base.ts b/src/WAConnection/0.Base.ts index 7b77f87..2e9835a 100644 --- a/src/WAConnection/0.Base.ts +++ b/src/WAConnection/0.Base.ts @@ -21,7 +21,6 @@ import { WAConnectOptions, MediaConnInfo, DEFAULT_ORIGIN, - TimedOutError, } from './Constants' import { EventEmitter } from 'events' import KeyedDB from '@adiwajshing/keyed-db' diff --git a/src/WAConnection/4.Events.ts b/src/WAConnection/4.Events.ts index 2991199..00aaf46 100644 --- a/src/WAConnection/4.Events.ts +++ b/src/WAConnection/4.Events.ts @@ -322,7 +322,11 @@ export class WAConnection extends Base { contact.lastSeen = unixTimestampSeconds() } contact.lastKnownPresence = update.type - const presence: WAPresenceData = { lastKnownPresence: contact.lastKnownPresence, lastSeen: contact.lastSeen } + const presence: WAPresenceData = { + lastKnownPresence: contact.lastKnownPresence, + lastSeen: contact.lastSeen, + name: contact.name || contact.vname || contact.notify + } const chat = this.chats.get(chatId) if (chat) { diff --git a/src/WAConnection/Constants.ts b/src/WAConnection/Constants.ts index e030ec6..dfce87b 100644 --- a/src/WAConnection/Constants.ts +++ b/src/WAConnection/Constants.ts @@ -180,6 +180,7 @@ export interface WAGroupModification { export interface WAPresenceData { lastKnownPresence?: Presence lastSeen?: number + name?: string } export interface WAContact extends WAPresenceData { verify?: string