Skip to content
Merged
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
16 changes: 16 additions & 0 deletions src/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,7 @@ impl Client {
// WAWebSendUserMsgJob reads local device table only on the send
// path; WAWebDBDeviceListFanout excludes hosted devices.
let recipient_bare = self.resolve_encryption_jid(&to).await.to_non_ad();
let recipient_is_lid = recipient_bare.is_lid();

// Local registry first; network warm only on miss to avoid
// unnecessary LID-migration side effects from get_user_devices
Expand Down Expand Up @@ -1297,6 +1298,21 @@ impl Client {
!is_sender
});

// own_cached is keyed by the bot's PN, so own devices come back
// PN-addressed. The server rejects a stanza that mixes PN and LID
// participants, so align own devices to LID for a LID recipient
// (whatsmeow switches ownID to LID before fanout).
if recipient_is_lid {
let lid = own_lid.ok_or_else(|| {
anyhow!("Cannot send a LID-addressed DM before the device LID is known")
})?;
for j in all_dm_jids.iter_mut() {
if j.is_pn() && j.is_same_user_as(own_jid) {
*j = Jid::lid_device(lid.user.clone(), j.device);
}
}
}

// Same-namespace dedup only; cross-namespace overlap is avoided
// upstream via `is_self_dm_recipient`.
wacore::types::jid::sort_dedup_by_device(&mut all_dm_jids);
Expand Down
Loading