improvement: upgrade ruma and implement blurhashes
parent
0fcefa4125
commit
f5273f7eb1
|
@ -2015,6 +2015,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma"
|
||||
version = "0.2.0"
|
||||
source = "git+https://github.com/ruma/ruma?rev=c29c2b16ec114fa655e2b70bdd53c82e35859005#c29c2b16ec114fa655e2b70bdd53c82e35859005"
|
||||
dependencies = [
|
||||
"assign",
|
||||
"js_int",
|
||||
|
@ -2035,6 +2036,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-api"
|
||||
version = "0.17.1"
|
||||
source = "git+https://github.com/ruma/ruma?rev=c29c2b16ec114fa655e2b70bdd53c82e35859005#c29c2b16ec114fa655e2b70bdd53c82e35859005"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"http",
|
||||
|
@ -2050,6 +2052,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-api-macros"
|
||||
version = "0.17.1"
|
||||
source = "git+https://github.com/ruma/ruma?rev=c29c2b16ec114fa655e2b70bdd53c82e35859005#c29c2b16ec114fa655e2b70bdd53c82e35859005"
|
||||
dependencies = [
|
||||
"proc-macro-crate",
|
||||
"proc-macro2",
|
||||
|
@ -2060,6 +2063,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-appservice-api"
|
||||
version = "0.3.0"
|
||||
source = "git+https://github.com/ruma/ruma?rev=c29c2b16ec114fa655e2b70bdd53c82e35859005#c29c2b16ec114fa655e2b70bdd53c82e35859005"
|
||||
dependencies = [
|
||||
"ruma-api",
|
||||
"ruma-common",
|
||||
|
@ -2073,6 +2077,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-client-api"
|
||||
version = "0.11.0"
|
||||
source = "git+https://github.com/ruma/ruma?rev=c29c2b16ec114fa655e2b70bdd53c82e35859005#c29c2b16ec114fa655e2b70bdd53c82e35859005"
|
||||
dependencies = [
|
||||
"assign",
|
||||
"bytes",
|
||||
|
@ -2092,6 +2097,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-common"
|
||||
version = "0.5.4"
|
||||
source = "git+https://github.com/ruma/ruma?rev=c29c2b16ec114fa655e2b70bdd53c82e35859005#c29c2b16ec114fa655e2b70bdd53c82e35859005"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"js_int",
|
||||
|
@ -2106,6 +2112,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-events"
|
||||
version = "0.23.2"
|
||||
source = "git+https://github.com/ruma/ruma?rev=c29c2b16ec114fa655e2b70bdd53c82e35859005#c29c2b16ec114fa655e2b70bdd53c82e35859005"
|
||||
dependencies = [
|
||||
"indoc",
|
||||
"js_int",
|
||||
|
@ -2121,6 +2128,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-events-macros"
|
||||
version = "0.23.2"
|
||||
source = "git+https://github.com/ruma/ruma?rev=c29c2b16ec114fa655e2b70bdd53c82e35859005#c29c2b16ec114fa655e2b70bdd53c82e35859005"
|
||||
dependencies = [
|
||||
"proc-macro-crate",
|
||||
"proc-macro2",
|
||||
|
@ -2131,6 +2139,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-federation-api"
|
||||
version = "0.2.0"
|
||||
source = "git+https://github.com/ruma/ruma?rev=c29c2b16ec114fa655e2b70bdd53c82e35859005#c29c2b16ec114fa655e2b70bdd53c82e35859005"
|
||||
dependencies = [
|
||||
"js_int",
|
||||
"ruma-api",
|
||||
|
@ -2145,6 +2154,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-identifiers"
|
||||
version = "0.19.4"
|
||||
source = "git+https://github.com/ruma/ruma?rev=c29c2b16ec114fa655e2b70bdd53c82e35859005#c29c2b16ec114fa655e2b70bdd53c82e35859005"
|
||||
dependencies = [
|
||||
"paste",
|
||||
"rand 0.8.4",
|
||||
|
@ -2158,6 +2168,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-identifiers-macros"
|
||||
version = "0.19.4"
|
||||
source = "git+https://github.com/ruma/ruma?rev=c29c2b16ec114fa655e2b70bdd53c82e35859005#c29c2b16ec114fa655e2b70bdd53c82e35859005"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"ruma-identifiers-validation",
|
||||
|
@ -2167,10 +2178,12 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-identifiers-validation"
|
||||
version = "0.4.0"
|
||||
source = "git+https://github.com/ruma/ruma?rev=c29c2b16ec114fa655e2b70bdd53c82e35859005#c29c2b16ec114fa655e2b70bdd53c82e35859005"
|
||||
|
||||
[[package]]
|
||||
name = "ruma-identity-service-api"
|
||||
version = "0.2.0"
|
||||
source = "git+https://github.com/ruma/ruma?rev=c29c2b16ec114fa655e2b70bdd53c82e35859005#c29c2b16ec114fa655e2b70bdd53c82e35859005"
|
||||
dependencies = [
|
||||
"js_int",
|
||||
"ruma-api",
|
||||
|
@ -2183,6 +2196,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-push-gateway-api"
|
||||
version = "0.2.0"
|
||||
source = "git+https://github.com/ruma/ruma?rev=c29c2b16ec114fa655e2b70bdd53c82e35859005#c29c2b16ec114fa655e2b70bdd53c82e35859005"
|
||||
dependencies = [
|
||||
"js_int",
|
||||
"ruma-api",
|
||||
|
@ -2197,6 +2211,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-serde"
|
||||
version = "0.4.1"
|
||||
source = "git+https://github.com/ruma/ruma?rev=c29c2b16ec114fa655e2b70bdd53c82e35859005#c29c2b16ec114fa655e2b70bdd53c82e35859005"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"form_urlencoded",
|
||||
|
@ -2210,6 +2225,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-serde-macros"
|
||||
version = "0.4.1"
|
||||
source = "git+https://github.com/ruma/ruma?rev=c29c2b16ec114fa655e2b70bdd53c82e35859005#c29c2b16ec114fa655e2b70bdd53c82e35859005"
|
||||
dependencies = [
|
||||
"proc-macro-crate",
|
||||
"proc-macro2",
|
||||
|
@ -2220,6 +2236,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-signatures"
|
||||
version = "0.8.0"
|
||||
source = "git+https://github.com/ruma/ruma?rev=c29c2b16ec114fa655e2b70bdd53c82e35859005#c29c2b16ec114fa655e2b70bdd53c82e35859005"
|
||||
dependencies = [
|
||||
"base64 0.13.0",
|
||||
"ed25519-dalek",
|
||||
|
@ -2236,6 +2253,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-state-res"
|
||||
version = "0.2.0"
|
||||
source = "git+https://github.com/ruma/ruma?rev=c29c2b16ec114fa655e2b70bdd53c82e35859005#c29c2b16ec114fa655e2b70bdd53c82e35859005"
|
||||
dependencies = [
|
||||
"itertools 0.10.1",
|
||||
"js_int",
|
||||
|
|
|
@ -18,8 +18,8 @@ edition = "2018"
|
|||
rocket = { version = "0.5.0-rc.1", features = ["tls"] } # Used to handle requests
|
||||
|
||||
# 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 = { 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 = { 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"] }
|
||||
|
||||
# Used for long polling and federation sender, should be the same as rocket::tokio
|
||||
tokio = "1.2.0"
|
||||
|
|
|
@ -283,6 +283,7 @@ pub async fn register_route(
|
|||
avatar_url: None,
|
||||
is_direct: None,
|
||||
third_party_invite: None,
|
||||
blurhash: None,
|
||||
})
|
||||
.expect("event is valid, we just created it"),
|
||||
unsigned: None,
|
||||
|
@ -446,6 +447,7 @@ pub async fn register_route(
|
|||
avatar_url: None,
|
||||
is_direct: None,
|
||||
third_party_invite: None,
|
||||
blurhash: None,
|
||||
})
|
||||
.expect("event is valid, we just created it"),
|
||||
unsigned: None,
|
||||
|
@ -466,6 +468,7 @@ pub async fn register_route(
|
|||
avatar_url: None,
|
||||
is_direct: None,
|
||||
third_party_invite: None,
|
||||
blurhash: None,
|
||||
})
|
||||
.expect("event is valid, we just created it"),
|
||||
unsigned: None,
|
||||
|
@ -578,7 +581,7 @@ pub async fn change_password_route(
|
|||
|
||||
db.flush().await?;
|
||||
|
||||
Ok(change_password::Response.into())
|
||||
Ok(change_password::Response {}.into())
|
||||
}
|
||||
|
||||
/// # `GET _matrix/client/r0/account/whoami`
|
||||
|
@ -664,6 +667,7 @@ pub async fn deactivate_route(
|
|||
avatar_url: None,
|
||||
is_direct: None,
|
||||
third_party_invite: None,
|
||||
blurhash: None,
|
||||
};
|
||||
|
||||
let mutex = Arc::clone(
|
||||
|
|
|
@ -46,7 +46,7 @@ pub async fn update_backup_route(
|
|||
|
||||
db.flush().await?;
|
||||
|
||||
Ok(update_backup::Response.into())
|
||||
Ok(update_backup::Response {}.into())
|
||||
}
|
||||
|
||||
#[cfg_attr(
|
||||
|
@ -119,7 +119,7 @@ pub async fn delete_backup_route(
|
|||
|
||||
db.flush().await?;
|
||||
|
||||
Ok(delete_backup::Response.into())
|
||||
Ok(delete_backup::Response {}.into())
|
||||
}
|
||||
|
||||
/// Add the received backup keys to the database.
|
||||
|
|
|
@ -45,7 +45,7 @@ pub async fn set_global_account_data_route(
|
|||
|
||||
db.flush().await?;
|
||||
|
||||
Ok(set_global_account_data::Response.into())
|
||||
Ok(set_global_account_data::Response {}.into())
|
||||
}
|
||||
|
||||
#[cfg_attr(
|
||||
|
@ -80,7 +80,7 @@ pub async fn set_room_account_data_route(
|
|||
|
||||
db.flush().await?;
|
||||
|
||||
Ok(set_room_account_data::Response.into())
|
||||
Ok(set_room_account_data::Response {}.into())
|
||||
}
|
||||
|
||||
#[cfg_attr(
|
||||
|
|
|
@ -73,7 +73,7 @@ pub async fn update_device_route(
|
|||
|
||||
db.flush().await?;
|
||||
|
||||
Ok(update_device::Response.into())
|
||||
Ok(update_device::Response {}.into())
|
||||
}
|
||||
|
||||
#[cfg_attr(
|
||||
|
@ -125,7 +125,7 @@ pub async fn delete_device_route(
|
|||
|
||||
db.flush().await?;
|
||||
|
||||
Ok(delete_device::Response.into())
|
||||
Ok(delete_device::Response {}.into())
|
||||
}
|
||||
|
||||
#[cfg_attr(
|
||||
|
@ -179,5 +179,5 @@ pub async fn delete_devices_route(
|
|||
|
||||
db.flush().await?;
|
||||
|
||||
Ok(delete_devices::Response.into())
|
||||
Ok(delete_devices::Response {}.into())
|
||||
}
|
||||
|
|
|
@ -102,7 +102,7 @@ pub async fn set_room_visibility_route(
|
|||
|
||||
db.flush().await?;
|
||||
|
||||
Ok(set_room_visibility::Response.into())
|
||||
Ok(set_room_visibility::Response {}.into())
|
||||
}
|
||||
|
||||
#[cfg_attr(
|
||||
|
|
|
@ -163,7 +163,7 @@ pub async fn upload_signing_keys_route(
|
|||
|
||||
db.flush().await?;
|
||||
|
||||
Ok(upload_signing_keys::Response.into())
|
||||
Ok(upload_signing_keys::Response {}.into())
|
||||
}
|
||||
|
||||
#[cfg_attr(
|
||||
|
@ -224,7 +224,7 @@ pub async fn upload_signatures_route(
|
|||
|
||||
db.flush().await?;
|
||||
|
||||
Ok(upload_signatures::Response.into())
|
||||
Ok(upload_signatures::Response {}.into())
|
||||
}
|
||||
|
||||
#[cfg_attr(
|
||||
|
|
|
@ -165,7 +165,7 @@ pub async fn invite_user_route(
|
|||
if let invite_user::IncomingInvitationRecipient::UserId { user_id } = &body.recipient {
|
||||
invite_helper(sender_user, user_id, &body.room_id, &db, false).await?;
|
||||
db.flush().await?;
|
||||
Ok(invite_user::Response.into())
|
||||
Ok(invite_user::Response {}.into())
|
||||
} else {
|
||||
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)?,
|
||||
is_direct: None,
|
||||
third_party_invite: None,
|
||||
blurhash: db.users.blurhash(&body.user_id)?,
|
||||
}),
|
||||
|event| {
|
||||
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)?,
|
||||
is_direct: None,
|
||||
third_party_invite: None,
|
||||
blurhash: db.users.blurhash(&sender_user)?,
|
||||
})
|
||||
.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)?,
|
||||
is_direct: None,
|
||||
third_party_invite: None,
|
||||
blurhash: db.users.blurhash(&sender_user)?,
|
||||
};
|
||||
|
||||
db.rooms.build_and_append_pdu(
|
||||
|
@ -833,6 +836,7 @@ pub async fn invite_helper<'a>(
|
|||
is_direct: Some(is_direct),
|
||||
membership: MembershipState::Invite,
|
||||
third_party_invite: None,
|
||||
blurhash: db.users.blurhash(&sender_user)?,
|
||||
})
|
||||
.expect("member event is valid value");
|
||||
|
||||
|
@ -1008,6 +1012,7 @@ pub async fn invite_helper<'a>(
|
|||
avatar_url: db.users.avatar_url(&user_id)?,
|
||||
is_direct: Some(is_direct),
|
||||
third_party_invite: None,
|
||||
blurhash: db.users.blurhash(&sender_user)?,
|
||||
})
|
||||
.expect("event is valid, we just created it"),
|
||||
unsigned: None,
|
||||
|
|
|
@ -75,5 +75,5 @@ pub const SESSION_ID_LENGTH: usize = 256;
|
|||
#[options("/<_..>")]
|
||||
#[tracing::instrument]
|
||||
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())
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ pub async fn set_presence_route(
|
|||
|
||||
db.flush().await?;
|
||||
|
||||
Ok(set_presence::Response.into())
|
||||
Ok(set_presence::Response {}.into())
|
||||
}
|
||||
|
||||
#[cfg_attr(
|
||||
|
|
|
@ -108,7 +108,7 @@ pub async fn set_displayname_route(
|
|||
|
||||
db.flush().await?;
|
||||
|
||||
Ok(set_display_name::Response.into())
|
||||
Ok(set_display_name::Response {}.into())
|
||||
}
|
||||
|
||||
#[cfg_attr(
|
||||
|
@ -140,6 +140,8 @@ pub async fn set_avatar_url_route(
|
|||
db.users
|
||||
.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
|
||||
for (pdu_builder, room_id) in db
|
||||
.rooms
|
||||
|
@ -220,7 +222,7 @@ pub async fn set_avatar_url_route(
|
|||
|
||||
db.flush().await?;
|
||||
|
||||
Ok(set_avatar_url::Response.into())
|
||||
Ok(set_avatar_url::Response {}.into())
|
||||
}
|
||||
|
||||
#[cfg_attr(
|
||||
|
@ -234,6 +236,7 @@ pub async fn get_avatar_url_route(
|
|||
) -> ConduitResult<get_avatar_url::Response> {
|
||||
Ok(get_avatar_url::Response {
|
||||
avatar_url: db.users.avatar_url(&body.user_id)?,
|
||||
blurhash: db.users.blurhash(&body.user_id)?,
|
||||
}
|
||||
.into())
|
||||
}
|
||||
|
@ -257,6 +260,7 @@ pub async fn get_profile_route(
|
|||
|
||||
Ok(get_profile::Response {
|
||||
avatar_url: db.users.avatar_url(&body.user_id)?,
|
||||
blurhash: db.users.blurhash(&body.user_id)?,
|
||||
displayname: db.users.displayname(&body.user_id)?,
|
||||
}
|
||||
.into())
|
||||
|
|
|
@ -194,7 +194,7 @@ pub async fn set_pushrule_route(
|
|||
|
||||
db.flush().await?;
|
||||
|
||||
Ok(set_pushrule::Response.into())
|
||||
Ok(set_pushrule::Response {}.into())
|
||||
}
|
||||
|
||||
#[cfg_attr(
|
||||
|
@ -327,7 +327,7 @@ pub async fn set_pushrule_actions_route(
|
|||
|
||||
db.flush().await?;
|
||||
|
||||
Ok(set_pushrule_actions::Response.into())
|
||||
Ok(set_pushrule_actions::Response {}.into())
|
||||
}
|
||||
|
||||
#[cfg_attr(
|
||||
|
@ -467,7 +467,7 @@ pub async fn set_pushrule_enabled_route(
|
|||
|
||||
db.flush().await?;
|
||||
|
||||
Ok(set_pushrule_enabled::Response.into())
|
||||
Ok(set_pushrule_enabled::Response {}.into())
|
||||
}
|
||||
|
||||
#[cfg_attr(
|
||||
|
@ -536,7 +536,7 @@ pub async fn delete_pushrule_route(
|
|||
|
||||
db.flush().await?;
|
||||
|
||||
Ok(delete_pushrule::Response.into())
|
||||
Ok(delete_pushrule::Response {}.into())
|
||||
}
|
||||
|
||||
#[cfg_attr(
|
||||
|
|
|
@ -77,7 +77,7 @@ pub async fn set_read_marker_route(
|
|||
|
||||
db.flush().await?;
|
||||
|
||||
Ok(set_read_marker::Response.into())
|
||||
Ok(set_read_marker::Response {}.into())
|
||||
}
|
||||
|
||||
#[cfg_attr(
|
||||
|
@ -130,5 +130,5 @@ pub async fn create_receipt_route(
|
|||
|
||||
db.flush().await?;
|
||||
|
||||
Ok(create_receipt::Response.into())
|
||||
Ok(create_receipt::Response {}.into())
|
||||
}
|
||||
|
|
|
@ -96,6 +96,7 @@ pub async fn create_room_route(
|
|||
avatar_url: db.users.avatar_url(&sender_user)?,
|
||||
is_direct: Some(body.is_direct),
|
||||
third_party_invite: None,
|
||||
blurhash: db.users.blurhash(&sender_user)?,
|
||||
})
|
||||
.expect("event is valid, we just created it"),
|
||||
unsigned: None,
|
||||
|
@ -444,6 +445,7 @@ pub async fn upgrade_room_route(
|
|||
avatar_url: db.users.avatar_url(&sender_user)?,
|
||||
is_direct: None,
|
||||
third_party_invite: None,
|
||||
blurhash: db.users.blurhash(&sender_user)?,
|
||||
})
|
||||
.expect("event is valid, we just created it"),
|
||||
unsigned: None,
|
||||
|
|
|
@ -753,6 +753,7 @@ async fn sync_helper(
|
|||
leave: left_rooms,
|
||||
join: joined_rooms,
|
||||
invite: invited_rooms,
|
||||
knock: BTreeMap::new(), // TODO
|
||||
},
|
||||
presence: sync_events::Presence {
|
||||
events: presence_updates
|
||||
|
|
|
@ -42,7 +42,7 @@ pub async fn update_tag_route(
|
|||
|
||||
db.flush().await?;
|
||||
|
||||
Ok(create_tag::Response.into())
|
||||
Ok(create_tag::Response {}.into())
|
||||
}
|
||||
|
||||
#[cfg_attr(
|
||||
|
@ -76,7 +76,7 @@ pub async fn delete_tag_route(
|
|||
|
||||
db.flush().await?;
|
||||
|
||||
Ok(delete_tag::Response.into())
|
||||
Ok(delete_tag::Response {}.into())
|
||||
}
|
||||
|
||||
#[cfg_attr(
|
||||
|
|
|
@ -69,5 +69,5 @@ pub async fn send_event_to_device_route(
|
|||
|
||||
db.flush().await?;
|
||||
|
||||
Ok(send_event_to_device::Response.into())
|
||||
Ok(send_event_to_device::Response {}.into())
|
||||
}
|
||||
|
|
|
@ -29,5 +29,5 @@ pub fn create_typing_event_route(
|
|||
.typing_remove(&sender_user, &body.room_id, &db.globals)?;
|
||||
}
|
||||
|
||||
Ok(create_typing_event::Response.into())
|
||||
Ok(create_typing_event::Response {}.into())
|
||||
}
|
||||
|
|
|
@ -229,6 +229,7 @@ impl Database {
|
|||
userid_password: builder.open_tree("userid_password")?,
|
||||
userid_displayname: builder.open_tree("userid_displayname")?,
|
||||
userid_avatarurl: builder.open_tree("userid_avatarurl")?,
|
||||
userid_blurhash: builder.open_tree("userid_blurhash")?,
|
||||
userdeviceid_token: builder.open_tree("userdeviceid_token")?,
|
||||
userdeviceid_metadata: builder.open_tree("userdeviceid_metadata")?,
|
||||
userid_devicelistversion: builder.open_tree("userid_devicelistversion")?,
|
||||
|
|
|
@ -15,6 +15,7 @@ pub struct Users {
|
|||
pub(super) userid_password: Arc<dyn Tree>,
|
||||
pub(super) userid_displayname: 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_metadata: Arc<dyn Tree>, // This is also used to check if a device exists
|
||||
pub(super) userid_devicelistversion: Arc<dyn Tree>, // DevicelistVersion = u64
|
||||
|
@ -150,7 +151,7 @@ impl Users {
|
|||
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>> {
|
||||
self.userid_avatarurl
|
||||
.get(user_id.as_bytes())?
|
||||
|
@ -174,6 +175,31 @@ impl Users {
|
|||
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.
|
||||
pub fn create_device(
|
||||
&self,
|
||||
|
|
|
@ -2001,6 +2001,7 @@ pub fn create_join_event_template_route(
|
|||
|
||||
let content = serde_json::to_value(MemberEventContent {
|
||||
avatar_url: None,
|
||||
blurhash: None,
|
||||
displayname: None,
|
||||
is_direct: None,
|
||||
membership: MembershipState::Join,
|
||||
|
@ -2420,19 +2421,25 @@ pub fn get_profile_information_route(
|
|||
|
||||
let mut displayname = None;
|
||||
let mut avatar_url = None;
|
||||
let mut blurhash = None;
|
||||
|
||||
match &body.field {
|
||||
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
|
||||
Some(_) => {}
|
||||
None => {
|
||||
displayname = db.users.displayname(&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 {
|
||||
blurhash,
|
||||
displayname,
|
||||
avatar_url,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue