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
28 changes: 17 additions & 11 deletions src/client/device_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,19 @@ use super::Client;
enum UserLookupKeys {
/// User is a LID with known phone number mapping.
/// Keys: [LID, PN]
LidWithPn { lid: String, pn: String },
LidWithPn {
lid: wacore_binary::CompactString,
pn: wacore_binary::CompactString,
},
/// User is a phone number with known LID mapping.
/// Keys: [LID, PN]
PnWithLid { lid: String, pn: String },
PnWithLid {
lid: wacore_binary::CompactString,
pn: wacore_binary::CompactString,
},
/// Unknown user - no LID-PN mapping exists.
/// Could be either a LID or PN, we don't know.
Unknown { user: String },
Unknown { user: wacore_binary::CompactString },
}

impl UserLookupKeys {
Expand Down Expand Up @@ -61,26 +67,26 @@ impl Client {
/// - `PnWithLid`: User is a phone number with known LID mapping
/// - `Unknown`: No LID-PN mapping exists (could be either type)
async fn resolve_lookup_keys(&self, user: &str) -> UserLookupKeys {
// Check if user is a LID (has a phone number mapping)
// Check if user is a LID (has a phone number mapping). The `user`-derived
// key is built inline via CompactString (LID/PN are short), avoiding a
// heap String per member on every group send.
if let Some(pn) = self.lid_pn_cache.get_phone_number(user).await {
return UserLookupKeys::LidWithPn {
lid: user.to_string(),
pn,
lid: user.into(),
pn: pn.into(),
};
}

// Check if user is a PN (has a LID mapping)
if let Some(lid) = self.lid_pn_cache.get_current_lid(user).await {
return UserLookupKeys::PnWithLid {
lid,
pn: user.to_string(),
lid: lid.into(),
pn: user.into(),
};
}

// Unknown user - no mapping exists
UserLookupKeys::Unknown {
user: user.to_string(),
}
UserLookupKeys::Unknown { user: user.into() }
}

/// Get all possible lookup keys for a user (for bidirectional lookup).
Expand Down
Loading