renamed user.id to user.jid

This commit is contained in:
Adhiraj
2020-08-28 20:22:35 +05:30
parent 890fb726f1
commit 828be7f240
8 changed files with 22 additions and 19 deletions

View File

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

View File

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

View File

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

View File

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

View File

@@ -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<WAProfilePictureChange>)
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 })

View File

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

View File

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

View File

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