base: Store the display names in the memory store as well

master
Damir Jelić 2021-01-27 11:55:50 +01:00
parent 094ead9d7d
commit 442103a37e
1 changed files with 22 additions and 2 deletions

View File

@ -42,6 +42,7 @@ pub struct MemoryStore {
account_data: Arc<DashMap<String, AnyBasicEvent>>, account_data: Arc<DashMap<String, AnyBasicEvent>>,
members: Arc<DashMap<RoomId, DashMap<UserId, MemberEvent>>>, members: Arc<DashMap<RoomId, DashMap<UserId, MemberEvent>>>,
profiles: Arc<DashMap<RoomId, DashMap<UserId, MemberEventContent>>>, profiles: Arc<DashMap<RoomId, DashMap<UserId, MemberEventContent>>>,
display_names: Arc<DashMap<RoomId, DashMap<String, BTreeSet<UserId>>>>,
joined_user_ids: Arc<DashMap<RoomId, DashSet<UserId>>>, joined_user_ids: Arc<DashMap<RoomId, DashSet<UserId>>>,
invited_user_ids: Arc<DashMap<RoomId, DashSet<UserId>>>, invited_user_ids: Arc<DashMap<RoomId, DashSet<UserId>>>,
room_info: Arc<DashMap<RoomId, RoomInfo>>, room_info: Arc<DashMap<RoomId, RoomInfo>>,
@ -64,6 +65,7 @@ impl MemoryStore {
account_data: DashMap::new().into(), account_data: DashMap::new().into(),
members: DashMap::new().into(), members: DashMap::new().into(),
profiles: DashMap::new().into(), profiles: DashMap::new().into(),
display_names: DashMap::new().into(),
joined_user_ids: DashMap::new().into(), joined_user_ids: DashMap::new().into(),
invited_user_ids: DashMap::new().into(), invited_user_ids: DashMap::new().into(),
room_info: DashMap::new().into(), room_info: DashMap::new().into(),
@ -149,6 +151,15 @@ impl MemoryStore {
} }
} }
for (room, map) in &changes.ambiguity_maps {
for (display_name, display_names) in map {
self.display_names
.entry(room.clone())
.or_insert_with(DashMap::new)
.insert(display_name.clone(), display_names.clone());
}
}
for (event_type, event) in &changes.account_data { for (event_type, event) in &changes.account_data {
self.account_data self.account_data
.insert(event_type.to_string(), event.clone()); .insert(event_type.to_string(), event.clone());
@ -349,7 +360,16 @@ impl StateStore for MemoryStore {
Ok(self.get_stripped_room_infos()) Ok(self.get_stripped_room_infos())
} }
async fn get_users_with_display_name(&self, _: &RoomId, _: &str) -> Result<BTreeSet<UserId>> { async fn get_users_with_display_name(
Ok(BTreeSet::new()) &self,
room_id: &RoomId,
display_name: &str,
) -> Result<BTreeSet<UserId>> {
#[allow(clippy::map_clone)]
Ok(self
.display_names
.get(room_id)
.and_then(|d| d.get(display_name).map(|d| d.clone()))
.unwrap_or_default())
} }
} }