improvement: show more users in our user directory

This commit is contained in:
Timo Kösters 2021-06-12 18:40:33 +02:00
parent cd4bc520d8
commit e8f6708927
No known key found for this signature in database
GPG key ID: 24DA7517711A2BA4
3 changed files with 41 additions and 9 deletions

View file

@ -21,9 +21,6 @@ pub async fn search_users_route(
let mut users = db.users.iter().filter_map(|user_id| { let mut users = db.users.iter().filter_map(|user_id| {
// Filter out buggy users (they should not exist, but you never know...) // Filter out buggy users (they should not exist, but you never know...)
let user_id = user_id.ok()?; let user_id = user_id.ok()?;
if db.users.is_deactivated(&user_id).ok()? {
return None;
}
let user = search_users::User { let user = search_users::User {
user_id: user_id.clone(), user_id: user_id.clone(),
@ -31,11 +28,18 @@ pub async fn search_users_route(
avatar_url: db.users.avatar_url(&user_id).ok()?, 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 && user
.display_name .display_name
.as_ref() .as_ref()
.filter(|name| name.contains(&body.search_term)) .filter(|name| {
name.to_lowercase()
.contains(&body.search_term.to_lowercase())
})
.is_none() .is_none()
{ {
return None; return None;

View file

@ -289,6 +289,30 @@ impl Database {
println!("Migration: 2 -> 3 finished"); 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 // This data is probably outdated
db.rooms.edus.presenceid_presence.clear()?; db.rooms.edus.presenceid_presence.clear()?;

View file

@ -592,9 +592,8 @@ impl Rooms {
prefix.push(0xff); prefix.push(0xff);
self.roomid_pduleaves self.roomid_pduleaves
.scan_prefix(dbg!(prefix)) .scan_prefix(prefix)
.map(|(key, bytes)| { .map(|(_, bytes)| {
dbg!(key);
Ok::<_, Error>( Ok::<_, Error>(
EventId::try_from(utils::string_from_bytes(&bytes).map_err(|_| { EventId::try_from(utils::string_from_bytes(&bytes).map_err(|_| {
Error::bad_database("EventID in roomid_pduleaves is invalid unicode.") Error::bad_database("EventID in roomid_pduleaves is invalid unicode.")
@ -1195,7 +1194,6 @@ impl Rooms {
room_id: &RoomId, room_id: &RoomId,
db: &Database, db: &Database,
) -> Result<EventId> { ) -> Result<EventId> {
dbg!(&pdu_builder);
let PduBuilder { let PduBuilder {
event_type, event_type,
content, content,
@ -1583,6 +1581,12 @@ impl Rooms {
last_state: Option<Vec<Raw<AnyStrippedStateEvent>>>, last_state: Option<Vec<Raw<AnyStrippedStateEvent>>>,
db: &Database, db: &Database,
) -> Result<()> { ) -> 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(); let mut roomserver_id = room_id.as_bytes().to_vec();
roomserver_id.push(0xff); roomserver_id.push(0xff);
roomserver_id.extend_from_slice(user_id.server_name().as_bytes()); roomserver_id.extend_from_slice(user_id.server_name().as_bytes());