From 828be7f2400b0593587eb9cb0c1348f44b97ee22 Mon Sep 17 00:00:00 2001 From: Adhiraj Date: Fri, 28 Aug 2020 20:22:35 +0530 Subject: [PATCH] renamed user.id to user.jid --- Example/example.ts | 2 +- src/WAConnection/1.Validation.ts | 4 ++-- src/WAConnection/3.Connect.ts | 2 +- src/WAConnection/4.Events.ts | 4 ++-- src/WAConnection/5.User.ts | 6 +++--- src/WAConnection/6.MessagesSend.ts | 6 +++--- src/WAConnection/8.Groups.ts | 2 +- src/WAConnection/Constants.ts | 15 +++++++++------ 8 files changed, 22 insertions(+), 19 deletions(-) diff --git a/Example/example.ts b/Example/example.ts index 683ea6f..26cca3e 100644 --- a/Example/example.ts +++ b/Example/example.ts @@ -29,7 +29,7 @@ async function example() { const unread = await conn.loadAllUnreadMessages () - console.log('oh hello ' + conn.user.name + ' (' + conn.user.id + ')') + console.log('oh hello ' + conn.user.name + ' (' + conn.user.jid + ')') console.log('you have ' + conn.chats.all().length + ' chats') console.log ('you have ' + unread.length + ' unread messages') diff --git a/src/WAConnection/1.Validation.ts b/src/WAConnection/1.Validation.ts index 7bd2585..1a4bd3e 100644 --- a/src/WAConnection/1.Validation.ts +++ b/src/WAConnection/1.Validation.ts @@ -61,7 +61,7 @@ export class WAConnection extends Base { this.lastSeen = new Date() // set last seen to right now }) // load profile picture - .then (() => this.query({ json: ['query', 'ProfilePicThumb', this.user.id], waitForOpen: false, expect200: false })) + .then (() => this.query({ json: ['query', 'ProfilePicThumb', this.user.jid], waitForOpen: false, expect200: false })) .then (response => this.user.imgUrl = response?.eurl || '') } /** @@ -92,7 +92,7 @@ export class WAConnection extends Base { private validateNewConnection(json) { // set metadata: one's WhatsApp ID [cc][number]@s.whatsapp.net, name on WhatsApp, info about the phone const onValidationSuccess = () => ({ - id: Utils.whatsappID(json.wid), + jid: Utils.whatsappID(json.wid), name: json.pushname, phone: json.phone, imgUrl: null diff --git a/src/WAConnection/3.Connect.ts b/src/WAConnection/3.Connect.ts index 087db26..7c52781 100644 --- a/src/WAConnection/3.Connect.ts +++ b/src/WAConnection/3.Connect.ts @@ -238,7 +238,7 @@ export class WAConnection extends Base { await delay try { const shouldUseReconnect = this.lastDisconnectReason !== DisconnectReason.replaced && this.lastDisconnectReason !== DisconnectReason.unknown && this.user - const reconnectID = shouldUseReconnect ? this.user.id.replace ('@s.whatsapp.net', '@c.us') : null + const reconnectID = shouldUseReconnect ? this.user.jid.replace ('@s.whatsapp.net', '@c.us') : null await this.connect ({ timeoutMs: 30000, retryOnNetworkErrors: true, reconnectID }) this.cancelReconnect = null diff --git a/src/WAConnection/4.Events.ts b/src/WAConnection/4.Events.ts index e6b3b6c..e46b107 100644 --- a/src/WAConnection/4.Events.ts +++ b/src/WAConnection/4.Events.ts @@ -132,7 +132,7 @@ export class WAConnection extends Base { } /** Get the URL to download the profile picture of a person/group */ async getProfilePicture(jid: string | null) { - const response = await this.query({ json: ['query', 'ProfilePicThumb', jid || this.user.id] }) + const response = await this.query({ json: ['query', 'ProfilePicThumb', jid || this.user.jid] }) return response.eurl as string } /** Set the callback for message status updates (when a message is delivered, read etc.) */ @@ -245,7 +245,7 @@ export class WAConnection extends Base { this.emit ('group-participants-remove', { jid, actor, participants}) // mark the chat read only if you left the group - if (participants.includes(this.user.id)) { + if (participants.includes(this.user.jid)) { chat.read_only = 'true' this.emit ('chat-update', { jid, read_only: chat.read_only }) } diff --git a/src/WAConnection/5.User.ts b/src/WAConnection/5.User.ts index e5ebe4e..2562168 100644 --- a/src/WAConnection/5.User.ts +++ b/src/WAConnection/5.User.ts @@ -34,7 +34,7 @@ export class WAConnection extends Base { requestPresenceUpdate = async (jid: string) => this.query({json: ['action', 'presence', 'subscribe', jid]}) /** Query the status of the person (see groupMetadata() for groups) */ async getStatus (jid?: string) { - const status: { status: string } = await this.query({json: ['query', 'Status', jid || this.user.id]}) + const status: { status: string } = await this.query({json: ['query', 'Status', jid || this.user.jid]}) return status } async setStatus (status: string) { @@ -47,7 +47,7 @@ export class WAConnection extends Base { ] ] ) - this.emit ('user-status-update', { jid: this.user.id, status }) + this.emit ('user-status-update', { jid: this.user.jid, status }) return response } /** Get your contacts */ @@ -122,7 +122,7 @@ export class WAConnection extends Base { ] ] const response = await (this.setQuery ([query], [WAMetric.picture, 136], tag) as Promise) - if (jid === this.user.id) this.user.imgUrl = response.eurl + if (jid === this.user.jid) this.user.imgUrl = response.eurl else if (this.chats.get(jid)) { this.chats.get(jid).imgUrl = response.eurl this.emit ('chat-update', { jid, imgUrl: response.eurl }) diff --git a/src/WAConnection/6.MessagesSend.ts b/src/WAConnection/6.MessagesSend.ts index 7c1ad08..27d9308 100644 --- a/src/WAConnection/6.MessagesSend.ts +++ b/src/WAConnection/6.MessagesSend.ts @@ -150,7 +150,7 @@ export class WAConnection extends Base { if (options.contextInfo) message[key].contextInfo = options.contextInfo if (quoted) { - const participant = quoted.key.fromMe ? this.user.id : (quoted.key.participant || quoted.key.remoteJid) + const participant = quoted.key.fromMe ? this.user.jid : (quoted.key.participant || quoted.key.remoteJid) message[key].contextInfo = message[key].contextInfo || { } message[key].contextInfo.participant = participant @@ -174,7 +174,7 @@ export class WAConnection extends Base { message: message, messageTimestamp: timestamp, messageStubParameters: [], - participant: id.includes('@g.us') ? this.user.id : null, + participant: id.includes('@g.us') ? this.user.jid : null, status: WA_MESSAGE_STATUS_TYPE.PENDING } return messageJSON as WAMessage @@ -182,7 +182,7 @@ export class WAConnection extends Base { /** Relay (send) a WAMessage; more advanced functionality to send a built WA Message, you may want to stick with sendMessage() */ async relayWAMessage(message: WAMessage) { const json = ['action', {epoch: this.msgCount.toString(), type: 'relay'}, [['message', null, message]]] - const flag = message.key.remoteJid === this.user.id ? WAFlag.acknowledge : WAFlag.ignore // acknowledge when sending message to oneself + const flag = message.key.remoteJid === this.user.jid ? WAFlag.acknowledge : WAFlag.ignore // acknowledge when sending message to oneself await this.query({json, binaryTags: [WAMetric.message, flag], tag: message.key.id}) await this.chatAddMessageAppropriate (message) } diff --git a/src/WAConnection/8.Groups.ts b/src/WAConnection/8.Groups.ts index 06be771..81fe088 100644 --- a/src/WAConnection/8.Groups.ts +++ b/src/WAConnection/8.Groups.ts @@ -10,7 +10,7 @@ export class WAConnection extends Base { const json: WANode = [ 'group', { - author: this.user.id, + author: this.user.jid, id: tag, type: type, jid: jid, diff --git a/src/WAConnection/Constants.ts b/src/WAConnection/Constants.ts index 9bd778e..09213d4 100644 --- a/src/WAConnection/Constants.ts +++ b/src/WAConnection/Constants.ts @@ -113,12 +113,6 @@ export interface AuthenticationCredentialsBrowser { WAToken2: string } export type AnyAuthenticationCredentials = AuthenticationCredentialsBrowser | AuthenticationCredentialsBase64 | AuthenticationCredentials -export interface WAUser { - id: string - name: string - phone: string - imgUrl: string -} export interface WAGroupCreateResponse { status: number @@ -145,12 +139,21 @@ export interface WAGroupModification { } export interface WAContact { + /** name of the contact, the contact has set on their own on WA */ notify?: string jid: string + /** I have no idea */ + vname?: string + /** name of the contact, you have saved on your WA */ name?: string index?: string + /** short name for the contact */ short?: string } +export interface WAUser extends WAContact { + phone: any + imgUrl?: string +} export interface WAChat { jid: string