Add name to presence update

This commit is contained in:
Adhiraj Singh
2020-11-17 17:12:14 +05:30
parent cea702b5a3
commit f29c5cf206
4 changed files with 7 additions and 3 deletions

View File

@@ -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

View File

@@ -21,7 +21,6 @@ import {
WAConnectOptions,
MediaConnInfo,
DEFAULT_ORIGIN,
TimedOutError,
} from './Constants'
import { EventEmitter } from 'events'
import KeyedDB from '@adiwajshing/keyed-db'

View File

@@ -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) {

View File

@@ -180,6 +180,7 @@ export interface WAGroupModification {
export interface WAPresenceData {
lastKnownPresence?: Presence
lastSeen?: number
name?: string
}
export interface WAContact extends WAPresenceData {
verify?: string