feat: add support for FB and Interop JID encoding/decoding and empty strings (#2189)
This commit is contained in:
@@ -167,6 +167,29 @@ export const decodeDecompressedBinaryNode = (
|
|||||||
return jidEncode(user, server, device)
|
return jidEncode(user, server, device)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const readFbJid = () => {
|
||||||
|
const user = readString(readByte()!)
|
||||||
|
const device = readInt(2)
|
||||||
|
const server = readString(readByte()!)
|
||||||
|
return `${user}:${device}@${server}`
|
||||||
|
}
|
||||||
|
|
||||||
|
const readInteropJid = () => {
|
||||||
|
const user = readString(readByte()!)
|
||||||
|
const device = readInt(2)
|
||||||
|
const integrator = readInt(2)
|
||||||
|
|
||||||
|
let server = 'interop'
|
||||||
|
const beforeServer = indexRef.index
|
||||||
|
try {
|
||||||
|
server = readString(readByte()!)
|
||||||
|
} catch (err) {
|
||||||
|
indexRef.index = beforeServer
|
||||||
|
}
|
||||||
|
|
||||||
|
return `${integrator}-${user}:${device}@${server}`
|
||||||
|
}
|
||||||
|
|
||||||
const readString = (tag: number): string => {
|
const readString = (tag: number): string => {
|
||||||
if (tag >= 1 && tag < SINGLE_BYTE_TOKENS.length) {
|
if (tag >= 1 && tag < SINGLE_BYTE_TOKENS.length) {
|
||||||
return SINGLE_BYTE_TOKENS[tag] || ''
|
return SINGLE_BYTE_TOKENS[tag] || ''
|
||||||
@@ -188,6 +211,10 @@ export const decodeDecompressedBinaryNode = (
|
|||||||
return readStringFromChars(readInt(4))
|
return readStringFromChars(readInt(4))
|
||||||
case TAGS.JID_PAIR:
|
case TAGS.JID_PAIR:
|
||||||
return readJidPair()
|
return readJidPair()
|
||||||
|
case TAGS.FB_JID:
|
||||||
|
return readFbJid()
|
||||||
|
case TAGS.INTEROP_JID:
|
||||||
|
return readInteropJid()
|
||||||
case TAGS.AD_JID:
|
case TAGS.AD_JID:
|
||||||
return readAdJid()
|
return readAdJid()
|
||||||
case TAGS.HEX_8:
|
case TAGS.HEX_8:
|
||||||
|
|||||||
@@ -182,6 +182,11 @@ const encodeBinaryNodeInner = (
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (str === '') {
|
||||||
|
writeStringRaw(str)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const tokenIndex = TOKEN_MAP[str]
|
const tokenIndex = TOKEN_MAP[str]
|
||||||
if (tokenIndex) {
|
if (tokenIndex) {
|
||||||
if (typeof tokenIndex.dict === 'number') {
|
if (typeof tokenIndex.dict === 'number') {
|
||||||
@@ -193,7 +198,7 @@ const encodeBinaryNodeInner = (
|
|||||||
writePackedBytes(str, 'nibble')
|
writePackedBytes(str, 'nibble')
|
||||||
} else if (isHex(str)) {
|
} else if (isHex(str)) {
|
||||||
writePackedBytes(str, 'hex')
|
writePackedBytes(str, 'hex')
|
||||||
} else if (str) {
|
} else {
|
||||||
const decodedJid = jidDecode(str)
|
const decodedJid = jidDecode(str)
|
||||||
if (decodedJid) {
|
if (decodedJid) {
|
||||||
writeJid(decodedJid)
|
writeJid(decodedJid)
|
||||||
|
|||||||
Reference in New Issue
Block a user