Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incoming LID and sending LID #408

Merged
merged 26 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Socket/messages-send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,12 +312,13 @@ export const makeMessagesSocket = (config: SocketConfig) => {
const statusJid = 'status@broadcast'
const isGroup = server === 'g.us'
const isStatus = jid === statusJid
const isLid = server === 'lid'

msgId = msgId || generateMessageID()
useUserDevicesCache = useUserDevicesCache !== false

const participants: BinaryNode[] = []
const destinationJid = (!isStatus) ? jidEncode(user, isGroup ? 'g.us' : 's.whatsapp.net') : statusJid
const destinationJid = (!isStatus) ? jidEncode(user, isLid ? 'lid' : isGroup ? 'g.us' : 's.whatsapp.net') : statusJid
const binaryNodeContent: BinaryNode[] = []
const devices: JidWithDevice[] = []

Expand Down
17 changes: 15 additions & 2 deletions src/Utils/decode-wa-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Boom } from '@hapi/boom'
import { Logger } from 'pino'
import { proto } from '../../WAProto'
import { SignalRepository, WAMessageKey } from '../Types'
import { areJidsSameUser, BinaryNode, isJidBroadcast, isJidGroup, isJidStatusBroadcast, isJidUser } from '../WABinary'
import { areJidsSameUser, BinaryNode, isJidBroadcast, isJidGroup, isJidStatusBroadcast, isJidUser, isLidUser } from '../WABinary'
import { unpadRandomMax16 } from './generics'

const NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node'
Expand Down Expand Up @@ -39,6 +39,19 @@ export function decodeMessageNode(
chatId = from
}

msgType = 'chat'
author = from
} else if(isLidUser(from)) {
PurpShell marked this conversation as resolved.
Show resolved Hide resolved
if(recipient) {
if(!isMe(from)) {
throw new Boom('receipient present, but msg not from me', { data: stanza })
}

chatId = recipient
} else {
chatId = from
}

msgType = 'chat'
author = from
} else if(isJidGroup(from)) {
Expand Down Expand Up @@ -183,4 +196,4 @@ export const decryptMessageNode = (
}
}
}
}
}
4 changes: 2 additions & 2 deletions src/WABinary/decode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
const device = readByte()
const user = readString(readByte())

return jidEncode(user, 's.whatsapp.net', device, agent)
return jidEncode(user, agent == 0 ? 's.whatsapp.net' : 'lid', device)

Check failure on line 151 in src/WABinary/decode.ts

View workflow job for this annotation

GitHub Actions / check-lint

Expected '===' and instead saw '=='
}

const readString = (tag: number): string => {
Expand Down Expand Up @@ -262,4 +262,4 @@
export const decodeBinaryNode = (buff: Buffer): BinaryNode => {
const decompBuff = decompressingIfRequired(buff)
return decodeDecompressedBinaryNode(decompBuff, constants)
}
}
6 changes: 4 additions & 2 deletions src/WABinary/jid-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const SERVER_JID = '[email protected]'
export const PSA_WID = '[email protected]'
export const STORIES_JID = 'status@broadcast'

export type JidServer = 'c.us' | 'g.us' | 'broadcast' | 's.whatsapp.net' | 'call'
export type JidServer = 'c.us' | 'g.us' | 'broadcast' | 's.whatsapp.net' | 'call' | 'lid'

export type JidWithDevice = {
user: string
Expand Down Expand Up @@ -46,6 +46,8 @@ export const areJidsSameUser = (jid1: string | undefined, jid2: string | undefin
)
/** is the jid a user */
export const isJidUser = (jid: string | undefined) => (jid?.endsWith('@s.whatsapp.net'))
/** is the jid a group */
export const isLidUser = (jid: string | undefined) => (jid?.endsWith('@lid'))
/** is the jid a broadcast */
export const isJidBroadcast = (jid: string | undefined) => (jid?.endsWith('@broadcast'))
/** is the jid a group */
Expand All @@ -61,4 +63,4 @@ export const jidNormalizedUser = (jid: string | undefined) => {

const { user, server } = result
return jidEncode(user, server === 'c.us' ? 's.whatsapp.net' : server as JidServer)
}
}
Loading