improvement: upgrade ruma and implement blurhashes

next
Timo Kösters 2021-07-15 23:17:58 +02:00
parent 0fcefa4125
commit f5273f7eb1
No known key found for this signature in database
GPG Key ID: 24DA7517711A2BA4
22 changed files with 98 additions and 30 deletions

18
Cargo.lock generated
View File

@ -2015,6 +2015,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma" name = "ruma"
version = "0.2.0" version = "0.2.0"
source = "git+https://github.com/ruma/ruma?rev=c29c2b16ec114fa655e2b70bdd53c82e35859005#c29c2b16ec114fa655e2b70bdd53c82e35859005"
dependencies = [ dependencies = [
"assign", "assign",
"js_int", "js_int",
@ -2035,6 +2036,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-api" name = "ruma-api"
version = "0.17.1" version = "0.17.1"
source = "git+https://github.com/ruma/ruma?rev=c29c2b16ec114fa655e2b70bdd53c82e35859005#c29c2b16ec114fa655e2b70bdd53c82e35859005"
dependencies = [ dependencies = [
"bytes", "bytes",
"http", "http",
@ -2050,6 +2052,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-api-macros" name = "ruma-api-macros"
version = "0.17.1" version = "0.17.1"
source = "git+https://github.com/ruma/ruma?rev=c29c2b16ec114fa655e2b70bdd53c82e35859005#c29c2b16ec114fa655e2b70bdd53c82e35859005"
dependencies = [ dependencies = [
"proc-macro-crate", "proc-macro-crate",
"proc-macro2", "proc-macro2",
@ -2060,6 +2063,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-appservice-api" name = "ruma-appservice-api"
version = "0.3.0" version = "0.3.0"
source = "git+https://github.com/ruma/ruma?rev=c29c2b16ec114fa655e2b70bdd53c82e35859005#c29c2b16ec114fa655e2b70bdd53c82e35859005"
dependencies = [ dependencies = [
"ruma-api", "ruma-api",
"ruma-common", "ruma-common",
@ -2073,6 +2077,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-client-api" name = "ruma-client-api"
version = "0.11.0" version = "0.11.0"
source = "git+https://github.com/ruma/ruma?rev=c29c2b16ec114fa655e2b70bdd53c82e35859005#c29c2b16ec114fa655e2b70bdd53c82e35859005"
dependencies = [ dependencies = [
"assign", "assign",
"bytes", "bytes",
@ -2092,6 +2097,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-common" name = "ruma-common"
version = "0.5.4" version = "0.5.4"
source = "git+https://github.com/ruma/ruma?rev=c29c2b16ec114fa655e2b70bdd53c82e35859005#c29c2b16ec114fa655e2b70bdd53c82e35859005"
dependencies = [ dependencies = [
"indexmap", "indexmap",
"js_int", "js_int",
@ -2106,6 +2112,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-events" name = "ruma-events"
version = "0.23.2" version = "0.23.2"
source = "git+https://github.com/ruma/ruma?rev=c29c2b16ec114fa655e2b70bdd53c82e35859005#c29c2b16ec114fa655e2b70bdd53c82e35859005"
dependencies = [ dependencies = [
"indoc", "indoc",
"js_int", "js_int",
@ -2121,6 +2128,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-events-macros" name = "ruma-events-macros"
version = "0.23.2" version = "0.23.2"
source = "git+https://github.com/ruma/ruma?rev=c29c2b16ec114fa655e2b70bdd53c82e35859005#c29c2b16ec114fa655e2b70bdd53c82e35859005"
dependencies = [ dependencies = [
"proc-macro-crate", "proc-macro-crate",
"proc-macro2", "proc-macro2",
@ -2131,6 +2139,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-federation-api" name = "ruma-federation-api"
version = "0.2.0" version = "0.2.0"
source = "git+https://github.com/ruma/ruma?rev=c29c2b16ec114fa655e2b70bdd53c82e35859005#c29c2b16ec114fa655e2b70bdd53c82e35859005"
dependencies = [ dependencies = [
"js_int", "js_int",
"ruma-api", "ruma-api",
@ -2145,6 +2154,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-identifiers" name = "ruma-identifiers"
version = "0.19.4" version = "0.19.4"
source = "git+https://github.com/ruma/ruma?rev=c29c2b16ec114fa655e2b70bdd53c82e35859005#c29c2b16ec114fa655e2b70bdd53c82e35859005"
dependencies = [ dependencies = [
"paste", "paste",
"rand 0.8.4", "rand 0.8.4",
@ -2158,6 +2168,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-identifiers-macros" name = "ruma-identifiers-macros"
version = "0.19.4" version = "0.19.4"
source = "git+https://github.com/ruma/ruma?rev=c29c2b16ec114fa655e2b70bdd53c82e35859005#c29c2b16ec114fa655e2b70bdd53c82e35859005"
dependencies = [ dependencies = [
"quote", "quote",
"ruma-identifiers-validation", "ruma-identifiers-validation",
@ -2167,10 +2178,12 @@ dependencies = [
[[package]] [[package]]
name = "ruma-identifiers-validation" name = "ruma-identifiers-validation"
version = "0.4.0" version = "0.4.0"
source = "git+https://github.com/ruma/ruma?rev=c29c2b16ec114fa655e2b70bdd53c82e35859005#c29c2b16ec114fa655e2b70bdd53c82e35859005"
[[package]] [[package]]
name = "ruma-identity-service-api" name = "ruma-identity-service-api"
version = "0.2.0" version = "0.2.0"
source = "git+https://github.com/ruma/ruma?rev=c29c2b16ec114fa655e2b70bdd53c82e35859005#c29c2b16ec114fa655e2b70bdd53c82e35859005"
dependencies = [ dependencies = [
"js_int", "js_int",
"ruma-api", "ruma-api",
@ -2183,6 +2196,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-push-gateway-api" name = "ruma-push-gateway-api"
version = "0.2.0" version = "0.2.0"
source = "git+https://github.com/ruma/ruma?rev=c29c2b16ec114fa655e2b70bdd53c82e35859005#c29c2b16ec114fa655e2b70bdd53c82e35859005"
dependencies = [ dependencies = [
"js_int", "js_int",
"ruma-api", "ruma-api",
@ -2197,6 +2211,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-serde" name = "ruma-serde"
version = "0.4.1" version = "0.4.1"
source = "git+https://github.com/ruma/ruma?rev=c29c2b16ec114fa655e2b70bdd53c82e35859005#c29c2b16ec114fa655e2b70bdd53c82e35859005"
dependencies = [ dependencies = [
"bytes", "bytes",
"form_urlencoded", "form_urlencoded",
@ -2210,6 +2225,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-serde-macros" name = "ruma-serde-macros"
version = "0.4.1" version = "0.4.1"
source = "git+https://github.com/ruma/ruma?rev=c29c2b16ec114fa655e2b70bdd53c82e35859005#c29c2b16ec114fa655e2b70bdd53c82e35859005"
dependencies = [ dependencies = [
"proc-macro-crate", "proc-macro-crate",
"proc-macro2", "proc-macro2",
@ -2220,6 +2236,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-signatures" name = "ruma-signatures"
version = "0.8.0" version = "0.8.0"
source = "git+https://github.com/ruma/ruma?rev=c29c2b16ec114fa655e2b70bdd53c82e35859005#c29c2b16ec114fa655e2b70bdd53c82e35859005"
dependencies = [ dependencies = [
"base64 0.13.0", "base64 0.13.0",
"ed25519-dalek", "ed25519-dalek",
@ -2236,6 +2253,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-state-res" name = "ruma-state-res"
version = "0.2.0" version = "0.2.0"
source = "git+https://github.com/ruma/ruma?rev=c29c2b16ec114fa655e2b70bdd53c82e35859005#c29c2b16ec114fa655e2b70bdd53c82e35859005"
dependencies = [ dependencies = [
"itertools 0.10.1", "itertools 0.10.1",
"js_int", "js_int",

View File

@ -18,8 +18,8 @@ edition = "2018"
rocket = { version = "0.5.0-rc.1", features = ["tls"] } # Used to handle requests rocket = { version = "0.5.0-rc.1", features = ["tls"] } # Used to handle requests
# Used for matrix spec type definitions and helpers # Used for matrix spec type definitions and helpers
#ruma = { git = "https://github.com/ruma/ruma", rev = "174555857ef90d49e4b9a672be9e2fe0acdc2687", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] } ruma = { git = "https://github.com/ruma/ruma", rev = "c29c2b16ec114fa655e2b70bdd53c82e35859005", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] }
ruma = { path = "../ruma/crates/ruma", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] } #ruma = { path = "../ruma/crates/ruma", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] }
# Used for long polling and federation sender, should be the same as rocket::tokio # Used for long polling and federation sender, should be the same as rocket::tokio
tokio = "1.2.0" tokio = "1.2.0"

View File

@ -283,6 +283,7 @@ pub async fn register_route(
avatar_url: None, avatar_url: None,
is_direct: None, is_direct: None,
third_party_invite: None, third_party_invite: None,
blurhash: None,
}) })
.expect("event is valid, we just created it"), .expect("event is valid, we just created it"),
unsigned: None, unsigned: None,
@ -446,6 +447,7 @@ pub async fn register_route(
avatar_url: None, avatar_url: None,
is_direct: None, is_direct: None,
third_party_invite: None, third_party_invite: None,
blurhash: None,
}) })
.expect("event is valid, we just created it"), .expect("event is valid, we just created it"),
unsigned: None, unsigned: None,
@ -466,6 +468,7 @@ pub async fn register_route(
avatar_url: None, avatar_url: None,
is_direct: None, is_direct: None,
third_party_invite: None, third_party_invite: None,
blurhash: None,
}) })
.expect("event is valid, we just created it"), .expect("event is valid, we just created it"),
unsigned: None, unsigned: None,
@ -578,7 +581,7 @@ pub async fn change_password_route(
db.flush().await?; db.flush().await?;
Ok(change_password::Response.into()) Ok(change_password::Response {}.into())
} }
/// # `GET _matrix/client/r0/account/whoami` /// # `GET _matrix/client/r0/account/whoami`
@ -664,6 +667,7 @@ pub async fn deactivate_route(
avatar_url: None, avatar_url: None,
is_direct: None, is_direct: None,
third_party_invite: None, third_party_invite: None,
blurhash: None,
}; };
let mutex = Arc::clone( let mutex = Arc::clone(

View File

@ -46,7 +46,7 @@ pub async fn update_backup_route(
db.flush().await?; db.flush().await?;
Ok(update_backup::Response.into()) Ok(update_backup::Response {}.into())
} }
#[cfg_attr( #[cfg_attr(
@ -119,7 +119,7 @@ pub async fn delete_backup_route(
db.flush().await?; db.flush().await?;
Ok(delete_backup::Response.into()) Ok(delete_backup::Response {}.into())
} }
/// Add the received backup keys to the database. /// Add the received backup keys to the database.

View File

@ -45,7 +45,7 @@ pub async fn set_global_account_data_route(
db.flush().await?; db.flush().await?;
Ok(set_global_account_data::Response.into()) Ok(set_global_account_data::Response {}.into())
} }
#[cfg_attr( #[cfg_attr(
@ -80,7 +80,7 @@ pub async fn set_room_account_data_route(
db.flush().await?; db.flush().await?;
Ok(set_room_account_data::Response.into()) Ok(set_room_account_data::Response {}.into())
} }
#[cfg_attr( #[cfg_attr(

View File

@ -73,7 +73,7 @@ pub async fn update_device_route(
db.flush().await?; db.flush().await?;
Ok(update_device::Response.into()) Ok(update_device::Response {}.into())
} }
#[cfg_attr( #[cfg_attr(
@ -125,7 +125,7 @@ pub async fn delete_device_route(
db.flush().await?; db.flush().await?;
Ok(delete_device::Response.into()) Ok(delete_device::Response {}.into())
} }
#[cfg_attr( #[cfg_attr(
@ -179,5 +179,5 @@ pub async fn delete_devices_route(
db.flush().await?; db.flush().await?;
Ok(delete_devices::Response.into()) Ok(delete_devices::Response {}.into())
} }

View File

@ -102,7 +102,7 @@ pub async fn set_room_visibility_route(
db.flush().await?; db.flush().await?;
Ok(set_room_visibility::Response.into()) Ok(set_room_visibility::Response {}.into())
} }
#[cfg_attr( #[cfg_attr(

View File

@ -163,7 +163,7 @@ pub async fn upload_signing_keys_route(
db.flush().await?; db.flush().await?;
Ok(upload_signing_keys::Response.into()) Ok(upload_signing_keys::Response {}.into())
} }
#[cfg_attr( #[cfg_attr(
@ -224,7 +224,7 @@ pub async fn upload_signatures_route(
db.flush().await?; db.flush().await?;
Ok(upload_signatures::Response.into()) Ok(upload_signatures::Response {}.into())
} }
#[cfg_attr( #[cfg_attr(

View File

@ -165,7 +165,7 @@ pub async fn invite_user_route(
if let invite_user::IncomingInvitationRecipient::UserId { user_id } = &body.recipient { if let invite_user::IncomingInvitationRecipient::UserId { user_id } = &body.recipient {
invite_helper(sender_user, user_id, &body.room_id, &db, false).await?; invite_helper(sender_user, user_id, &body.room_id, &db, false).await?;
db.flush().await?; db.flush().await?;
Ok(invite_user::Response.into()) Ok(invite_user::Response {}.into())
} else { } else {
Err(Error::BadRequest(ErrorKind::NotFound, "User not found.")) Err(Error::BadRequest(ErrorKind::NotFound, "User not found."))
} }
@ -261,6 +261,7 @@ pub async fn ban_user_route(
avatar_url: db.users.avatar_url(&body.user_id)?, avatar_url: db.users.avatar_url(&body.user_id)?,
is_direct: None, is_direct: None,
third_party_invite: None, third_party_invite: None,
blurhash: db.users.blurhash(&body.user_id)?,
}), }),
|event| { |event| {
let mut event = serde_json::from_value::<Raw<member::MemberEventContent>>( let mut event = serde_json::from_value::<Raw<member::MemberEventContent>>(
@ -556,6 +557,7 @@ async fn join_room_by_id_helper(
avatar_url: db.users.avatar_url(&sender_user)?, avatar_url: db.users.avatar_url(&sender_user)?,
is_direct: None, is_direct: None,
third_party_invite: None, third_party_invite: None,
blurhash: db.users.blurhash(&sender_user)?,
}) })
.expect("event is valid, we just created it"), .expect("event is valid, we just created it"),
); );
@ -685,6 +687,7 @@ async fn join_room_by_id_helper(
avatar_url: db.users.avatar_url(&sender_user)?, avatar_url: db.users.avatar_url(&sender_user)?,
is_direct: None, is_direct: None,
third_party_invite: None, third_party_invite: None,
blurhash: db.users.blurhash(&sender_user)?,
}; };
db.rooms.build_and_append_pdu( db.rooms.build_and_append_pdu(
@ -833,6 +836,7 @@ pub async fn invite_helper<'a>(
is_direct: Some(is_direct), is_direct: Some(is_direct),
membership: MembershipState::Invite, membership: MembershipState::Invite,
third_party_invite: None, third_party_invite: None,
blurhash: db.users.blurhash(&sender_user)?,
}) })
.expect("member event is valid value"); .expect("member event is valid value");
@ -1008,6 +1012,7 @@ pub async fn invite_helper<'a>(
avatar_url: db.users.avatar_url(&user_id)?, avatar_url: db.users.avatar_url(&user_id)?,
is_direct: Some(is_direct), is_direct: Some(is_direct),
third_party_invite: None, third_party_invite: None,
blurhash: db.users.blurhash(&sender_user)?,
}) })
.expect("event is valid, we just created it"), .expect("event is valid, we just created it"),
unsigned: None, unsigned: None,

View File

@ -75,5 +75,5 @@ pub const SESSION_ID_LENGTH: usize = 256;
#[options("/<_..>")] #[options("/<_..>")]
#[tracing::instrument] #[tracing::instrument]
pub async fn options_route() -> ConduitResult<send_event_to_device::Response> { pub async fn options_route() -> ConduitResult<send_event_to_device::Response> {
Ok(send_event_to_device::Response.into()) Ok(send_event_to_device::Response {}.into())
} }

View File

@ -43,7 +43,7 @@ pub async fn set_presence_route(
db.flush().await?; db.flush().await?;
Ok(set_presence::Response.into()) Ok(set_presence::Response {}.into())
} }
#[cfg_attr( #[cfg_attr(

View File

@ -108,7 +108,7 @@ pub async fn set_displayname_route(
db.flush().await?; db.flush().await?;
Ok(set_display_name::Response.into()) Ok(set_display_name::Response {}.into())
} }
#[cfg_attr( #[cfg_attr(
@ -140,6 +140,8 @@ pub async fn set_avatar_url_route(
db.users db.users
.set_avatar_url(&sender_user, body.avatar_url.clone())?; .set_avatar_url(&sender_user, body.avatar_url.clone())?;
db.users.set_blurhash(&sender_user, body.blurhash.clone())?;
// Send a new membership event and presence update into all joined rooms // Send a new membership event and presence update into all joined rooms
for (pdu_builder, room_id) in db for (pdu_builder, room_id) in db
.rooms .rooms
@ -220,7 +222,7 @@ pub async fn set_avatar_url_route(
db.flush().await?; db.flush().await?;
Ok(set_avatar_url::Response.into()) Ok(set_avatar_url::Response {}.into())
} }
#[cfg_attr( #[cfg_attr(
@ -234,6 +236,7 @@ pub async fn get_avatar_url_route(
) -> ConduitResult<get_avatar_url::Response> { ) -> ConduitResult<get_avatar_url::Response> {
Ok(get_avatar_url::Response { Ok(get_avatar_url::Response {
avatar_url: db.users.avatar_url(&body.user_id)?, avatar_url: db.users.avatar_url(&body.user_id)?,
blurhash: db.users.blurhash(&body.user_id)?,
} }
.into()) .into())
} }
@ -257,6 +260,7 @@ pub async fn get_profile_route(
Ok(get_profile::Response { Ok(get_profile::Response {
avatar_url: db.users.avatar_url(&body.user_id)?, avatar_url: db.users.avatar_url(&body.user_id)?,
blurhash: db.users.blurhash(&body.user_id)?,
displayname: db.users.displayname(&body.user_id)?, displayname: db.users.displayname(&body.user_id)?,
} }
.into()) .into())

View File

@ -194,7 +194,7 @@ pub async fn set_pushrule_route(
db.flush().await?; db.flush().await?;
Ok(set_pushrule::Response.into()) Ok(set_pushrule::Response {}.into())
} }
#[cfg_attr( #[cfg_attr(
@ -327,7 +327,7 @@ pub async fn set_pushrule_actions_route(
db.flush().await?; db.flush().await?;
Ok(set_pushrule_actions::Response.into()) Ok(set_pushrule_actions::Response {}.into())
} }
#[cfg_attr( #[cfg_attr(
@ -467,7 +467,7 @@ pub async fn set_pushrule_enabled_route(
db.flush().await?; db.flush().await?;
Ok(set_pushrule_enabled::Response.into()) Ok(set_pushrule_enabled::Response {}.into())
} }
#[cfg_attr( #[cfg_attr(
@ -536,7 +536,7 @@ pub async fn delete_pushrule_route(
db.flush().await?; db.flush().await?;
Ok(delete_pushrule::Response.into()) Ok(delete_pushrule::Response {}.into())
} }
#[cfg_attr( #[cfg_attr(

View File

@ -77,7 +77,7 @@ pub async fn set_read_marker_route(
db.flush().await?; db.flush().await?;
Ok(set_read_marker::Response.into()) Ok(set_read_marker::Response {}.into())
} }
#[cfg_attr( #[cfg_attr(
@ -130,5 +130,5 @@ pub async fn create_receipt_route(
db.flush().await?; db.flush().await?;
Ok(create_receipt::Response.into()) Ok(create_receipt::Response {}.into())
} }

View File

@ -96,6 +96,7 @@ pub async fn create_room_route(
avatar_url: db.users.avatar_url(&sender_user)?, avatar_url: db.users.avatar_url(&sender_user)?,
is_direct: Some(body.is_direct), is_direct: Some(body.is_direct),
third_party_invite: None, third_party_invite: None,
blurhash: db.users.blurhash(&sender_user)?,
}) })
.expect("event is valid, we just created it"), .expect("event is valid, we just created it"),
unsigned: None, unsigned: None,
@ -444,6 +445,7 @@ pub async fn upgrade_room_route(
avatar_url: db.users.avatar_url(&sender_user)?, avatar_url: db.users.avatar_url(&sender_user)?,
is_direct: None, is_direct: None,
third_party_invite: None, third_party_invite: None,
blurhash: db.users.blurhash(&sender_user)?,
}) })
.expect("event is valid, we just created it"), .expect("event is valid, we just created it"),
unsigned: None, unsigned: None,

View File

@ -753,6 +753,7 @@ async fn sync_helper(
leave: left_rooms, leave: left_rooms,
join: joined_rooms, join: joined_rooms,
invite: invited_rooms, invite: invited_rooms,
knock: BTreeMap::new(), // TODO
}, },
presence: sync_events::Presence { presence: sync_events::Presence {
events: presence_updates events: presence_updates

View File

@ -42,7 +42,7 @@ pub async fn update_tag_route(
db.flush().await?; db.flush().await?;
Ok(create_tag::Response.into()) Ok(create_tag::Response {}.into())
} }
#[cfg_attr( #[cfg_attr(
@ -76,7 +76,7 @@ pub async fn delete_tag_route(
db.flush().await?; db.flush().await?;
Ok(delete_tag::Response.into()) Ok(delete_tag::Response {}.into())
} }
#[cfg_attr( #[cfg_attr(

View File

@ -69,5 +69,5 @@ pub async fn send_event_to_device_route(
db.flush().await?; db.flush().await?;
Ok(send_event_to_device::Response.into()) Ok(send_event_to_device::Response {}.into())
} }

View File

@ -29,5 +29,5 @@ pub fn create_typing_event_route(
.typing_remove(&sender_user, &body.room_id, &db.globals)?; .typing_remove(&sender_user, &body.room_id, &db.globals)?;
} }
Ok(create_typing_event::Response.into()) Ok(create_typing_event::Response {}.into())
} }

View File

@ -229,6 +229,7 @@ impl Database {
userid_password: builder.open_tree("userid_password")?, userid_password: builder.open_tree("userid_password")?,
userid_displayname: builder.open_tree("userid_displayname")?, userid_displayname: builder.open_tree("userid_displayname")?,
userid_avatarurl: builder.open_tree("userid_avatarurl")?, userid_avatarurl: builder.open_tree("userid_avatarurl")?,
userid_blurhash: builder.open_tree("userid_blurhash")?,
userdeviceid_token: builder.open_tree("userdeviceid_token")?, userdeviceid_token: builder.open_tree("userdeviceid_token")?,
userdeviceid_metadata: builder.open_tree("userdeviceid_metadata")?, userdeviceid_metadata: builder.open_tree("userdeviceid_metadata")?,
userid_devicelistversion: builder.open_tree("userid_devicelistversion")?, userid_devicelistversion: builder.open_tree("userid_devicelistversion")?,

View File

@ -15,6 +15,7 @@ pub struct Users {
pub(super) userid_password: Arc<dyn Tree>, pub(super) userid_password: Arc<dyn Tree>,
pub(super) userid_displayname: Arc<dyn Tree>, pub(super) userid_displayname: Arc<dyn Tree>,
pub(super) userid_avatarurl: Arc<dyn Tree>, pub(super) userid_avatarurl: Arc<dyn Tree>,
pub(super) userid_blurhash: Arc<dyn Tree>,
pub(super) userdeviceid_token: Arc<dyn Tree>, pub(super) userdeviceid_token: Arc<dyn Tree>,
pub(super) userdeviceid_metadata: Arc<dyn Tree>, // This is also used to check if a device exists pub(super) userdeviceid_metadata: Arc<dyn Tree>, // This is also used to check if a device exists
pub(super) userid_devicelistversion: Arc<dyn Tree>, // DevicelistVersion = u64 pub(super) userid_devicelistversion: Arc<dyn Tree>, // DevicelistVersion = u64
@ -150,7 +151,7 @@ impl Users {
Ok(()) Ok(())
} }
/// Get a the avatar_url of a user. /// Get the avatar_url of a user.
pub fn avatar_url(&self, user_id: &UserId) -> Result<Option<MxcUri>> { pub fn avatar_url(&self, user_id: &UserId) -> Result<Option<MxcUri>> {
self.userid_avatarurl self.userid_avatarurl
.get(user_id.as_bytes())? .get(user_id.as_bytes())?
@ -174,6 +175,31 @@ impl Users {
Ok(()) Ok(())
} }
/// Get the blurhash of a user.
pub fn blurhash(&self, user_id: &UserId) -> Result<Option<String>> {
self.userid_blurhash
.get(user_id.as_bytes())?
.map(|bytes| {
let s = utils::string_from_bytes(&bytes)
.map_err(|_| Error::bad_database("Avatar URL in db is invalid."))?;
Ok(s)
})
.transpose()
}
/// Sets a new avatar_url or removes it if avatar_url is None.
pub fn set_blurhash(&self, user_id: &UserId, blurhash: Option<String>) -> Result<()> {
if let Some(blurhash) = blurhash {
self.userid_blurhash
.insert(user_id.as_bytes(), blurhash.as_bytes())?;
} else {
self.userid_blurhash.remove(user_id.as_bytes())?;
}
Ok(())
}
/// Adds a new device to a user. /// Adds a new device to a user.
pub fn create_device( pub fn create_device(
&self, &self,

View File

@ -2001,6 +2001,7 @@ pub fn create_join_event_template_route(
let content = serde_json::to_value(MemberEventContent { let content = serde_json::to_value(MemberEventContent {
avatar_url: None, avatar_url: None,
blurhash: None,
displayname: None, displayname: None,
is_direct: None, is_direct: None,
membership: MembershipState::Join, membership: MembershipState::Join,
@ -2420,19 +2421,25 @@ pub fn get_profile_information_route(
let mut displayname = None; let mut displayname = None;
let mut avatar_url = None; let mut avatar_url = None;
let mut blurhash = None;
match &body.field { match &body.field {
Some(ProfileField::DisplayName) => displayname = db.users.displayname(&body.user_id)?, Some(ProfileField::DisplayName) => displayname = db.users.displayname(&body.user_id)?,
Some(ProfileField::AvatarUrl) => avatar_url = db.users.avatar_url(&body.user_id)?, Some(ProfileField::AvatarUrl) => {
avatar_url = db.users.avatar_url(&body.user_id)?;
blurhash = db.users.blurhash(&body.user_id)?
}
// TODO: what to do with custom // TODO: what to do with custom
Some(_) => {} Some(_) => {}
None => { None => {
displayname = db.users.displayname(&body.user_id)?; displayname = db.users.displayname(&body.user_id)?;
avatar_url = db.users.avatar_url(&body.user_id)?; avatar_url = db.users.avatar_url(&body.user_id)?;
blurhash = db.users.blurhash(&body.user_id)?;
} }
} }
Ok(get_profile_information::v1::Response { Ok(get_profile_information::v1::Response {
blurhash,
displayname, displayname,
avatar_url, avatar_url,
} }