iris_chat_protocol/protocol_engine/
roster_helpers.rs1use super::*;
2
3impl ProtocolEngine {
4 pub fn has_device_roster_entry_for_owner(
5 &self,
6 owner_pubkey: PublicKey,
7 device_pubkey: PublicKey,
8 ) -> bool {
9 let owner = ndr_owner(owner_pubkey);
10 let device = ndr_device(device_pubkey);
11 self.has_verified_device_owner_claim(owner, device)
12 && self
13 .session_manager
14 .snapshot()
15 .users
16 .into_iter()
17 .find(|user| user.owner_pubkey == owner)
18 .and_then(|user| user.roster)
19 .is_some_and(|roster| roster.get_device(&device).is_some())
20 }
21}
22
23pub(super) fn should_replace_provisional_local_roster(
24 snapshot: &SessionManagerSnapshot,
25 owner_pubkey: PublicKey,
26 local_device_pubkey: NdrDevicePubkey,
27 incoming_roster: &DeviceRoster,
28) -> bool {
29 let incoming_devices = incoming_roster.devices();
30 if incoming_devices.len() <= 1
31 || !incoming_devices
32 .iter()
33 .any(|entry| entry.device_pubkey == local_device_pubkey)
34 {
35 return false;
36 }
37
38 let Some(current_roster) = snapshot
39 .users
40 .iter()
41 .find(|user| user.owner_pubkey == ndr_owner(owner_pubkey))
42 .and_then(|user| user.roster.as_ref())
43 else {
44 return false;
45 };
46 let current_devices = current_roster.devices();
47 current_devices.len() == 1
48 && current_devices[0].device_pubkey == local_device_pubkey
49 && current_roster.created_at > incoming_roster.created_at
50}