[fractal/get-account-metadata] Get display name and avatar of account at startup
- From: Alejandro Domínguez <aledomu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal/get-account-metadata] Get display name and avatar of account at startup
- Date: Thu, 29 Jul 2021 01:54:16 +0000 (UTC)
commit 55d1ff79570dcea14c6038c3027e7dc6a235957c
Author: Alejandro Domínguez <adomu net-c com>
Date: Thu Jul 29 03:08:38 2021 +0200
Get display name and avatar of account at startup
src/session/mod.rs | 22 ++++++++++++++++++++--
src/session/user.rs | 11 ++++++++++-
2 files changed, 30 insertions(+), 3 deletions(-)
---
diff --git a/src/session/mod.rs b/src/session/mod.rs
index 10512fc5..311bb445 100644
--- a/src/session/mod.rs
+++ b/src/session/mod.rs
@@ -306,9 +306,27 @@ impl Session {
let priv_ = imp::Session::from_instance(self);
match result {
Ok((client, session)) => {
- priv_.client.set(client).unwrap();
+ priv_.client.set(client.clone()).unwrap();
let user = User::new(self, &session.user_id);
- priv_.user.set(user).unwrap();
+ priv_.user.set(user.clone()).unwrap();
+
+ do_async(
+ glib::PRIORITY_LOW,
+ async move {
+ let display_name = client.display_name().await?;
+ let avatar_url = client.avatar_url().await?;
+ Ok((display_name, avatar_url))
+ },
+ move |result: matrix_sdk::Result<_>| async move {
+ match result {
+ Ok((display_name, avatar_url)) => {
+ user.set_display_name(display_name);
+ user.set_avatar_url(avatar_url);
+ }
+ Err(error) => error!("Couldn’t fetch account metadata: {}", error),
+ };
+ },
+ );
if store_session {
// TODO: report secret service errors
diff --git a/src/session/user.rs b/src/session/user.rs
index df6c7de9..ef349518 100644
--- a/src/session/user.rs
+++ b/src/session/user.rs
@@ -4,7 +4,7 @@ use crate::session::Session;
use matrix_sdk::{
ruma::{
events::{room::member::MemberEventContent, StrippedStateEvent, SyncStateEvent},
- identifiers::UserId,
+ identifiers::{MxcUri, UserId},
},
RoomMember,
};
@@ -144,11 +144,20 @@ impl User {
}
}
+ pub fn set_display_name(&self, display_name: Option<String>) {
+ let priv_ = imp::User::from_instance(&self);
+ priv_.display_name.replace(display_name);
+ }
+
pub fn avatar(&self) -> &Avatar {
let priv_ = imp::User::from_instance(&self);
priv_.avatar.get().unwrap()
}
+ pub fn set_avatar_url(&self, url: Option<MxcUri>) {
+ self.avatar().set_url(url);
+ }
+
/// Update the user based on the the room member state event
pub fn update_from_room_member(&self, member: &RoomMember) {
let changed = {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]