feat(tctoken): complete lifecycle (TIER 1 + 2 + 3 of upstream PR)
feat(tctoken): complete lifecycle (TIER 1 + 2 + 3 of upstream PR)
This commit is contained in:
+42
-2
@@ -98,6 +98,24 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
||||
|
||||
let privacySettings: { [_: string]: string } | undefined
|
||||
|
||||
/**
|
||||
* Server-assigned AB props that gate tctoken-related protocol behavior.
|
||||
* Defaults match WA Web (safe — avoids spurious error 463 if the prop never
|
||||
* arrives). Populated from `fetchProps()` on connection.
|
||||
*
|
||||
* - `privacyTokenOn1to1` (AB prop 10518 / `privacy_token_sending_on_all_1_on_1_messages`):
|
||||
* include tctoken in 1:1 messages.
|
||||
* - `profilePicPrivacyToken` (AB prop 9666 / `profile_scraping_privacy_token_in_photo_iq`):
|
||||
* include tctoken in profile picture IQs.
|
||||
* - `lidTrustedTokenIssueToLid` (AB prop 14303 / `lid_trusted_token_issue_to_lid`):
|
||||
* issue privacy tokens to the contact's LID instead of the PN.
|
||||
*/
|
||||
const serverProps = {
|
||||
privacyTokenOn1to1: true,
|
||||
profilePicPrivacyToken: true,
|
||||
lidTrustedTokenIssueToLid: false
|
||||
}
|
||||
|
||||
let syncState: SyncState = SyncState.Connecting
|
||||
|
||||
/** this mutex ensures that messages from the same chat are processed in order, while allowing parallel processing of messages from different chats */
|
||||
@@ -791,7 +809,10 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
||||
me && (normalizedJid === jidNormalizedUser(me.id) || (me.lid && normalizedJid === jidNormalizedUser(me.lid)))
|
||||
let content: BinaryNode[] | undefined = baseContent
|
||||
|
||||
if (isUserJid && !isSelf) {
|
||||
// Gate inclusion on AB prop 9666 (profile_scraping_privacy_token_in_photo_iq).
|
||||
// WA Web defaults to true; if the server flips it off, we mirror that to
|
||||
// avoid divergence with the spec-compliant client.
|
||||
if (serverProps.profilePicPrivacyToken && isUserJid && !isSelf) {
|
||||
content = await buildTcTokenFromJid({
|
||||
authState,
|
||||
jid: normalizedJid,
|
||||
@@ -1093,7 +1114,25 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
||||
props = reduceBinaryNodeToDictionary(propsNode, 'prop')
|
||||
}
|
||||
|
||||
logger.debug('fetched props')
|
||||
// Extract protocol-relevant AB props (defaults match WA Web; see serverProps doc).
|
||||
// We accept both numeric IDs and human-readable names so the parser is resilient
|
||||
// to upstream renaming and to future-versioned WA Web servers.
|
||||
const privacyTokenProp = props['10518'] ?? props['privacy_token_sending_on_all_1_on_1_messages']
|
||||
if (privacyTokenProp !== undefined) {
|
||||
serverProps.privacyTokenOn1to1 = privacyTokenProp === 'true' || privacyTokenProp === '1'
|
||||
}
|
||||
|
||||
const profilePicProp = props['9666'] ?? props['profile_scraping_privacy_token_in_photo_iq']
|
||||
if (profilePicProp !== undefined) {
|
||||
serverProps.profilePicPrivacyToken = profilePicProp === 'true' || profilePicProp === '1'
|
||||
}
|
||||
|
||||
const lidIssueProp = props['14303'] ?? props['lid_trusted_token_issue_to_lid']
|
||||
if (lidIssueProp !== undefined) {
|
||||
serverProps.lidTrustedTokenIssueToLid = lidIssueProp === 'true' || lidIssueProp === '1'
|
||||
}
|
||||
|
||||
logger.debug({ serverProps }, 'fetched props')
|
||||
|
||||
return props
|
||||
}
|
||||
@@ -1611,6 +1650,7 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
||||
|
||||
return {
|
||||
...sock,
|
||||
serverProps,
|
||||
createCallLink,
|
||||
getBotListV2,
|
||||
messageMutex,
|
||||
|
||||
Reference in New Issue
Block a user