Skip to content
Open
Changes from all commits
Commits
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
54 changes: 44 additions & 10 deletions src/Socket/messages-recv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
} from '../Defaults'
import type {
GroupParticipant,
LIDMapping,
MessageReceiptType,
MessageRelayOptions,
MessageUserReceipt,
Expand Down Expand Up @@ -359,7 +360,7 @@
return
}

let data: any

Check warning on line 363 in src/Socket/messages-recv.ts

View workflow job for this annotation

GitHub Actions / check-lint

Unexpected any. Specify a different type
try {
const payloadContent = payloadNode.content
if (Array.isArray(payloadContent)) {
Expand Down Expand Up @@ -492,7 +493,7 @@
case 'update': {
const settingsNode = getBinaryNodeChild(child, 'settings')
if (settingsNode) {
const update: Record<string, any> = {}

Check warning on line 496 in src/Socket/messages-recv.ts

View workflow job for this annotation

GitHub Actions / check-lint

Unexpected any. Specify a different type
const nameNode = getBinaryNodeChild(settingsNode, 'name')
if (nameNode?.content) update.name = nameNode.content.toString()

Expand Down Expand Up @@ -798,12 +799,19 @@
}
}

const handleGroupNotification = (fullNode: BinaryNode, child: BinaryNode, msg: Partial<WAMessage>) => {
// TODO: Support PN/LID (Here is only LID now)

const handleGroupNotification = async (fullNode: BinaryNode, child: BinaryNode, msg: Partial<WAMessage>) => {
const lidPnMappings: LIDMapping[] = []
const actingParticipantLid = fullNode.attrs.participant
const actingParticipantPn = fullNode.attrs.participant_pn
const actingParticipantUsername = fullNode.attrs.participant_username
if (
actingParticipantLid &&
actingParticipantPn &&
isLidUser(actingParticipantLid) &&
isPnUser(actingParticipantPn)
) {
lidPnMappings.push({ lid: actingParticipantLid, pn: actingParticipantPn })
}

const affectedParticipantLid = getBinaryNodeChild(child, 'participant')?.attrs?.jid || actingParticipantLid!
const affectedParticipantPn = getBinaryNodeChild(child, 'participant')?.attrs?.phone_number || actingParticipantPn!
Expand All @@ -815,6 +823,9 @@
msg.messageStubType = WAMessageStubType.GROUP_CREATE
msg.messageStubParameters = [metadata.subject]
msg.key = { participant: metadata.owner, participantAlt: metadata.ownerPn }
if (metadata.owner && metadata.ownerPn && isLidUser(metadata.owner) && isPnUser(metadata.ownerPn)) {
lidPnMappings.push({ lid: metadata.owner, pn: metadata.ownerPn })
}

ev.emit('chats.upsert', [
{
Expand Down Expand Up @@ -855,11 +866,20 @@
msg.messageStubType = WAMessageStubType[stubType as keyof typeof WAMessageStubType]

const participants = getBinaryNodeChildren(child, 'participant').map(({ attrs }) => {
// TODO: Store LID MAPPINGS
const participantJid = attrs.jid
const phoneNumber = isLidUser(participantJid) && isPnUser(attrs.phone_number) ? attrs.phone_number : undefined
const lid = isPnUser(participantJid) && isLidUser(attrs.lid) ? attrs.lid : undefined

if (participantJid && phoneNumber) {
lidPnMappings.push({ lid: participantJid, pn: phoneNumber })
} else if (participantJid && lid) {
lidPnMappings.push({ lid, pn: participantJid })
}

return {
id: attrs.jid!,
phoneNumber: isLidUser(attrs.jid) && isPnUser(attrs.phone_number) ? attrs.phone_number : undefined,
lid: isPnUser(attrs.jid) && isLidUser(attrs.lid) ? attrs.lid : undefined,
id: participantJid!,
phoneNumber,
lid,
username: attrs.participant_username || attrs.username || undefined,
admin: (attrs.type || null) as GroupParticipant['admin']
}
Expand Down Expand Up @@ -919,6 +939,10 @@
break
case 'created_membership_requests':
msg.messageStubType = WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD
if (isLidUser(affectedParticipantLid) && isPnUser(affectedParticipantPn)) {
lidPnMappings.push({ lid: affectedParticipantLid, pn: affectedParticipantPn })
}

msg.messageStubParameters = [
JSON.stringify({ lid: affectedParticipantLid, pn: affectedParticipantPn }),
'created',
Expand All @@ -927,14 +951,25 @@
break
case 'revoked_membership_requests':
const isDenied = areJidsSameUser(affectedParticipantLid, actingParticipantLid)
// TODO: LIDMAPPING SUPPORT
msg.messageStubType = WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD
if (isLidUser(affectedParticipantLid) && isPnUser(affectedParticipantPn)) {
lidPnMappings.push({ lid: affectedParticipantLid, pn: affectedParticipantPn })
}

msg.messageStubParameters = [
JSON.stringify({ lid: affectedParticipantLid, pn: affectedParticipantPn }),
isDenied ? 'revoked' : 'rejected'
]
break
}

if (lidPnMappings.length) {
await signalRepository.lidMapping
.storeLIDPNMappings(lidPnMappings)
.catch(err =>
logger.warn({ err, count: lidPnMappings.length }, 'failed to store LID-PN mappings from group notification')
)
}
Comment thread
gusquadri marked this conversation as resolved.
}

const handleDevicesNotification = async (node: BinaryNode) => {
Expand Down Expand Up @@ -1046,8 +1081,7 @@
await handleMexNotification(node)
break
case 'w:gp2':
// TODO: HANDLE PARTICIPANT_PN
handleGroupNotification(node, child!, result)
await handleGroupNotification(node, child!, result)
break
case 'mediaretry':
const event = decodeMediaRetryNode(node)
Expand Down Expand Up @@ -1218,7 +1252,7 @@
const jids = await readTcTokenIndex(authState.keys)
for (const jid of jids) tcTokenKnownJids.add(jid)
logger.debug({ count: tcTokenKnownJids.size }, 'loaded tctoken index')
} catch (err: any) {

Check warning on line 1255 in src/Socket/messages-recv.ts

View workflow job for this annotation

GitHub Actions / check-lint

Unexpected any. Specify a different type
logger.warn({ err: err?.message }, 'failed to load tctoken index')
}
})()
Expand Down Expand Up @@ -1900,7 +1934,7 @@
onNewJidStored: trackTcTokenJid
})
logger.debug({ from: ackFrom }, 'completed 463 token recovery issuance')
} catch (err: any) {

Check warning on line 1937 in src/Socket/messages-recv.ts

View workflow job for this annotation

GitHub Actions / check-lint

Unexpected any. Specify a different type
logger.debug({ from: ackFrom, err: err?.message }, 'failed 463 token recovery issuance')
} finally {
inFlight463Recoveries.delete(ackFrom)
Expand Down Expand Up @@ -2157,7 +2191,7 @@
for (const jid of survivors) tcTokenKnownJids.add(jid)

logger.debug({ mutated, remaining: survivors.size }, 'pruned expired tctokens')
} catch (err: any) {

Check warning on line 2194 in src/Socket/messages-recv.ts

View workflow job for this annotation

GitHub Actions / check-lint

Unexpected any. Specify a different type
logger.warn({ err: err?.message }, 'failed to prune expired tctokens')
}
}
Expand Down
Loading