Usync: Barebones Usync Protocol support (#960)

* feature(feature/usync-mex): initial commit

* chore: fix merge commit

* chore:lint
This commit is contained in:
Rajeh Taher
2024-12-22 23:38:41 +02:00
committed by GitHub
parent 8333a25fca
commit f1f49ad2c8
14 changed files with 525 additions and 147 deletions

View 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,
}
}
}
}