From e8f67089272bb9bf57130972c0031b5c28599df7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20K=C3=B6sters?= Date: Sat, 12 Jun 2021 18:40:33 +0200 Subject: [PATCH] improvement: show more users in our user directory --- src/client_server/user_directory.rs | 14 +++++++++----- src/database.rs | 24 ++++++++++++++++++++++++ src/database/rooms.rs | 12 ++++++++---- 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/src/client_server/user_directory.rs b/src/client_server/user_directory.rs index 0ddc7e8..d7c16d7 100644 --- a/src/client_server/user_directory.rs +++ b/src/client_server/user_directory.rs @@ -21,9 +21,6 @@ pub async fn search_users_route( let mut users = db.users.iter().filter_map(|user_id| { // Filter out buggy users (they should not exist, but you never know...) let user_id = user_id.ok()?; - if db.users.is_deactivated(&user_id).ok()? { - return None; - } let user = search_users::User { user_id: user_id.clone(), @@ -31,11 +28,18 @@ pub async fn search_users_route( avatar_url: db.users.avatar_url(&user_id).ok()?, }; - if !user.user_id.to_string().contains(&body.search_term) + if !user + .user_id + .to_string() + .to_lowercase() + .contains(&body.search_term.to_lowercase()) && user .display_name .as_ref() - .filter(|name| name.contains(&body.search_term)) + .filter(|name| { + name.to_lowercase() + .contains(&body.search_term.to_lowercase()) + }) .is_none() { return None; diff --git a/src/database.rs b/src/database.rs index e00bdcd..2846928 100644 --- a/src/database.rs +++ b/src/database.rs @@ -289,6 +289,30 @@ impl Database { println!("Migration: 2 -> 3 finished"); } + + if db.globals.database_version()? < 4 { + // Add federated users to db as deactivated + for our_user in db.users.iter() { + let our_user = our_user?; + if db.users.is_deactivated(&our_user)? { + continue; + } + for room in db.rooms.rooms_joined(&our_user) { + for user in db.rooms.room_members(&room?) { + let user = user?; + if user.server_name() != db.globals.server_name() { + println!("Migration: Creating user {}", user); + db.users.create(&user, None)?; + } + } + } + } + + db.globals.bump_database_version(4)?; + + println!("Migration: 3 -> 4 finished"); + } + // This data is probably outdated db.rooms.edus.presenceid_presence.clear()?; diff --git a/src/database/rooms.rs b/src/database/rooms.rs index 736ff4d..0820395 100644 --- a/src/database/rooms.rs +++ b/src/database/rooms.rs @@ -592,9 +592,8 @@ impl Rooms { prefix.push(0xff); self.roomid_pduleaves - .scan_prefix(dbg!(prefix)) - .map(|(key, bytes)| { - dbg!(key); + .scan_prefix(prefix) + .map(|(_, bytes)| { Ok::<_, Error>( EventId::try_from(utils::string_from_bytes(&bytes).map_err(|_| { Error::bad_database("EventID in roomid_pduleaves is invalid unicode.") @@ -1195,7 +1194,6 @@ impl Rooms { room_id: &RoomId, db: &Database, ) -> Result { - dbg!(&pdu_builder); let PduBuilder { event_type, content, @@ -1583,6 +1581,12 @@ impl Rooms { last_state: Option>>, db: &Database, ) -> Result<()> { + // Keep track what remote users exist by adding them as "deactivated" users + if user_id.server_name() != db.globals.server_name() { + db.users.create(user_id, None)?; + // TODO: displayname, avatar url + } + let mut roomserver_id = room_id.as_bytes().to_vec(); roomserver_id.push(0xff); roomserver_id.extend_from_slice(user_id.server_name().as_bytes());