feat: implement tc token handling

TC token is required in certain cases to receive presence updates on chats
This commit is contained in:
Adhiraj Singh
2022-12-11 15:48:26 +05:30
parent a5d263d31b
commit 572d0f1dd6
2 changed files with 30 additions and 2 deletions

View File

@@ -494,14 +494,27 @@ export const makeChatsSocket = (config: SocketConfig) => {
}
}
const presenceSubscribe = (toJid: string) => (
/**
* @param toJid the jid to subscribe to
* @param tcToken token for subscription, use if present
*/
const presenceSubscribe = (toJid: string, tcToken?: Buffer) => (
sendNode({
tag: 'presence',
attrs: {
to: toJid,
id: generateMessageTag(),
type: 'subscribe'
}
},
content: tcToken
? [
{
tag: 'tctoken',
attrs: { },
content: tcToken
}
]
: undefined
})
)

View File

@@ -268,6 +268,21 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
const from = jidNormalizedUser(node.attrs.from)
switch (nodeType) {
case 'privacy_token':
const tokenList = getBinaryNodeChildren(child, 'token')
for(const { attrs, content } of tokenList) {
const jid = attrs.jid
ev.emit('chats.update', [
{
id: jid,
tcToken: content as Buffer
}
])
logger.debug({ jid }, 'got privacy token update')
}
break
case 'w:gp2':
handleGroupNotification(node.attrs.participant, child, result)
break