mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
Usync: Barebones Usync Protocol support (#960)
* feature(feature/usync-mex): initial commit * chore: fix merge commit * chore:lint
This commit is contained in:
44
src/WAUSync/Protocols/USyncStatusProtocol.ts
Normal file
44
src/WAUSync/Protocols/USyncStatusProtocol.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { USyncQueryProtocol } from '../../Types/USync'
|
||||
import { assertNodeErrorFree, BinaryNode } from '../../WABinary'
|
||||
|
||||
export type StatusData = {
|
||||
status?: string | null
|
||||
setAt?: Date
|
||||
}
|
||||
|
||||
export class USyncStatusProtocol implements USyncQueryProtocol {
|
||||
name = 'status'
|
||||
|
||||
getQueryElement(): BinaryNode {
|
||||
return {
|
||||
tag: 'status',
|
||||
attrs: {},
|
||||
}
|
||||
}
|
||||
|
||||
getUserElement(): null {
|
||||
return null
|
||||
}
|
||||
|
||||
parser(node: BinaryNode): StatusData | undefined {
|
||||
if(node.tag === 'status') {
|
||||
assertNodeErrorFree(node)
|
||||
let status: string | null = node?.content!.toString()
|
||||
const setAt = new Date(+(node?.attrs.t || 0) * 1000)
|
||||
if(!status) {
|
||||
if(+node.attrs?.code === 401) {
|
||||
status = ''
|
||||
} else {
|
||||
status = null
|
||||
}
|
||||
} else if(typeof status === 'string' && status.length === 0) {
|
||||
status = null
|
||||
}
|
||||
|
||||
return {
|
||||
status,
|
||||
setAt,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user