From 149d22eef76aab8400e121ec00b3d666b8ed5e27 Mon Sep 17 00:00:00 2001 From: strawberry Date: Sun, 14 Jan 2024 01:42:37 -0500 Subject: [PATCH] make set avatar, displayname, and blurhash async and forgot another let _ Signed-off-by: strawberry --- src/api/client_server/account.rs | 3 ++- src/api/client_server/profile.rs | 36 ++++++++++++++++++---------- src/service/admin/mod.rs | 3 ++- src/service/rooms/state_cache/mod.rs | 15 ++++++++---- src/service/users/mod.rs | 14 ++++++++--- 5 files changed, 49 insertions(+), 22 deletions(-) diff --git a/src/api/client_server/account.rs b/src/api/client_server/account.rs index 00657b7c..ac3324db 100644 --- a/src/api/client_server/account.rs +++ b/src/api/client_server/account.rs @@ -205,7 +205,8 @@ pub async fn register_route(body: Ruma) -> Result = services() @@ -132,13 +133,16 @@ pub async fn get_displayname_route( let _ = services().users.create(&body.user_id, None); let _ = services() .users - .set_displayname(&body.user_id, response.displayname.clone()); + .set_displayname(&body.user_id, response.displayname.clone()) + .await; let _ = services() .users - .set_avatar_url(&body.user_id, response.avatar_url); + .set_avatar_url(&body.user_id, response.avatar_url) + .await; let _ = services() .users - .set_blurhash(&body.user_id, response.blurhash); + .set_blurhash(&body.user_id, response.blurhash) + .await; return Ok(get_display_name::v3::Response { displayname: response.displayname, @@ -162,11 +166,13 @@ pub async fn set_avatar_url_route( services() .users - .set_avatar_url(sender_user, body.avatar_url.clone())?; + .set_avatar_url(sender_user, body.avatar_url.clone()) + .await?; services() .users - .set_blurhash(sender_user, body.blurhash.clone())?; + .set_blurhash(sender_user, body.blurhash.clone()) + .await?; // Send a new membership event and presence update into all joined rooms let all_joined_rooms: Vec<_> = services() @@ -271,13 +277,16 @@ pub async fn get_avatar_url_route( let _ = services().users.create(&body.user_id, None); let _ = services() .users - .set_displayname(&body.user_id, response.displayname); + .set_displayname(&body.user_id, response.displayname) + .await; let _ = services() .users - .set_avatar_url(&body.user_id, response.avatar_url.clone()); + .set_avatar_url(&body.user_id, response.avatar_url.clone()) + .await; let _ = services() .users - .set_blurhash(&body.user_id, response.blurhash.clone()); + .set_blurhash(&body.user_id, response.blurhash.clone()) + .await; return Ok(get_avatar_url::v3::Response { avatar_url: response.avatar_url, @@ -320,13 +329,16 @@ pub async fn get_profile_route( let _ = services().users.create(&body.user_id, None); let _ = services() .users - .set_displayname(&body.user_id, response.displayname.clone()); + .set_displayname(&body.user_id, response.displayname.clone()) + .await; let _ = services() .users - .set_avatar_url(&body.user_id, response.avatar_url.clone()); + .set_avatar_url(&body.user_id, response.avatar_url.clone()) + .await; let _ = services() .users - .set_blurhash(&body.user_id, response.blurhash.clone()); + .set_blurhash(&body.user_id, response.blurhash.clone()) + .await; return Ok(get_profile::v3::Response { displayname: response.displayname, diff --git a/src/service/admin/mod.rs b/src/service/admin/mod.rs index 3385c902..01517597 100644 --- a/src/service/admin/mod.rs +++ b/src/service/admin/mod.rs @@ -600,7 +600,8 @@ impl Service { services() .users - .set_displayname(&user_id, Some(displayname))?; + .set_displayname(&user_id, Some(displayname)) + .await?; // Initial account data services().account_data.update( diff --git a/src/service/rooms/state_cache/mod.rs b/src/service/rooms/state_cache/mod.rs index f3b1a823..b7cd04a6 100644 --- a/src/service/rooms/state_cache/mod.rs +++ b/src/service/rooms/state_cache/mod.rs @@ -58,13 +58,18 @@ impl Service { }, ) .await?; - services() + let _ = services() .users - .set_displayname(user_id, response.displayname.clone())?; - services() + .set_displayname(user_id, response.displayname.clone()) + .await; + let _ = services() .users - .set_avatar_url(user_id, response.avatar_url)?; - services().users.set_blurhash(user_id, response.blurhash)?; + .set_avatar_url(user_id, response.avatar_url) + .await; + let _ = services() + .users + .set_blurhash(user_id, response.blurhash) + .await; }; } diff --git a/src/service/users/mod.rs b/src/service/users/mod.rs index 10578679..b1a771ef 100644 --- a/src/service/users/mod.rs +++ b/src/service/users/mod.rs @@ -314,7 +314,11 @@ impl Service { } /// Sets a new displayname or removes it if displayname is None. You still need to nofify all rooms of this change. - pub fn set_displayname(&self, user_id: &UserId, displayname: Option) -> Result<()> { + pub async fn set_displayname( + &self, + user_id: &UserId, + displayname: Option, + ) -> Result<()> { self.db.set_displayname(user_id, displayname) } @@ -324,7 +328,11 @@ impl Service { } /// Sets a new avatar_url or removes it if avatar_url is None. - pub fn set_avatar_url(&self, user_id: &UserId, avatar_url: Option) -> Result<()> { + pub async fn set_avatar_url( + &self, + user_id: &UserId, + avatar_url: Option, + ) -> Result<()> { self.db.set_avatar_url(user_id, avatar_url) } @@ -334,7 +342,7 @@ impl Service { } /// Sets a new avatar_url or removes it if avatar_url is None. - pub fn set_blurhash(&self, user_id: &UserId, blurhash: Option) -> Result<()> { + pub async fn set_blurhash(&self, user_id: &UserId, blurhash: Option) -> Result<()> { self.db.set_blurhash(user_id, blurhash) }