[fractal] Don't request usernames from matrix server when creating messages



commit eef50dee6623cb5cf80df4cf6b60c419213408d9
Author: Julian Sparber <julian sparber net>
Date:   Thu Dec 31 17:40:35 2020 +0100

    Don't request usernames from matrix server when creating messages
    
    There isn't any sense in requesting the username again everytime a new
    message is added to a room.

 fractal-gtk/src/cache/mod.rs       | 54 --------------------------------------
 fractal-gtk/src/widgets/message.rs | 15 ++---------
 2 files changed, 2 insertions(+), 67 deletions(-)
---
diff --git a/fractal-gtk/src/cache/mod.rs b/fractal-gtk/src/cache/mod.rs
index 5752e5d1..6198d196 100644
--- a/fractal-gtk/src/cache/mod.rs
+++ b/fractal-gtk/src/cache/mod.rs
@@ -2,7 +2,6 @@ use crate::app::RUNTIME;
 use crate::appop::UserInfoCache;
 use crate::backend::user;
 use crate::util::cache_dir_path;
-use gtk::LabelExt;
 use matrix_sdk::Client as MatrixClient;
 
 use anyhow::Error;
@@ -120,56 +119,3 @@ pub fn download_to_cache(
         }
     });
 }
-
-/* Get username based on the MXID, we should cache the username */
-pub fn download_to_cache_username(
-    session_client: MatrixClient,
-    uid: UserId,
-    label: gtk::Label,
-    avatar: Option<Rc<RefCell<AvatarData>>>,
-) {
-    let response = RUNTIME.spawn(async move {
-        user::get_username(session_client, &uid)
-            .await
-            .ok()
-            .flatten()
-            .unwrap_or_default()
-    });
-    glib::MainContext::default().spawn_local(async move {
-        if let Ok(username) = response.await {
-            label.set_text(&username);
-            if let Some(ref rc_data) = avatar {
-                let mut data = rc_data.borrow_mut();
-                data.redraw(Some(username));
-            }
-        }
-    });
-}
-
-/* Download username for a given MXID and update a emote message
- * FIXME: We should cache this request and do it before we need to display the username in an emote*/
-pub fn download_to_cache_username_emote(
-    session_client: MatrixClient,
-    uid: UserId,
-    text: &str,
-    label: gtk::Label,
-    avatar: Option<Rc<RefCell<AvatarData>>>,
-) {
-    let response = RUNTIME.spawn(async move {
-        user::get_username(session_client, &uid)
-            .await
-            .ok()
-            .flatten()
-            .unwrap_or_default()
-    });
-    let text = text.to_string();
-    glib::MainContext::default().spawn_local(async move {
-        if let Ok(username) = response.await {
-            label.set_markup(&format!("<b>{}</b> {}", &username, text));
-            if let Some(ref rc_data) = avatar {
-                let mut data = rc_data.borrow_mut();
-                data.redraw(Some(username));
-            }
-        }
-    });
-}
diff --git a/fractal-gtk/src/widgets/message.rs b/fractal-gtk/src/widgets/message.rs
index 1c4beb6f..e6851620 100644
--- a/fractal-gtk/src/widgets/message.rs
+++ b/fractal-gtk/src/widgets/message.rs
@@ -13,8 +13,6 @@ use std::rc::Rc;
 use crate::util::markup_text;
 
 use crate::cache::download_to_cache;
-use crate::cache::download_to_cache_username;
-use crate::cache::download_to_cache_username_emote;
 
 use crate::globals;
 use crate::ui::MessageContent as Message;
@@ -231,7 +229,7 @@ impl MessageBox {
         let body = match msg.mtype {
             RowType::Sticker => self.build_room_msg_sticker(session_client, msg),
             RowType::Image => self.build_room_msg_image(session_client, msg),
-            RowType::Emote => self.build_room_msg_emote(session_client, msg),
+            RowType::Emote => self.build_room_msg_emote(msg),
             RowType::Audio => self.build_room_audio_player(session_client, msg),
             RowType::Video => self.build_room_video_player(session_client, msg),
             RowType::File => self.build_room_msg_file(msg),
@@ -284,7 +282,6 @@ impl MessageBox {
             uid.clone(),
             data.clone(),
         );
-        download_to_cache_username(session_client, uid, self.username.clone(), Some(data));
 
         avatar
     }
@@ -648,7 +645,7 @@ impl MessageBox {
         info
     }
 
-    fn build_room_msg_emote(&self, session_client: MatrixClient, msg: &Message) -> gtk::Box {
+    fn build_room_msg_emote(&self, msg: &Message) -> gtk::Box {
         let bx = gtk::Box::new(gtk::Orientation::Horizontal, 0);
         /* Use MXID till we have a alias */
         let sname = msg
@@ -659,14 +656,6 @@ impl MessageBox {
         let body: &str = &msg.body;
         let markup = markup_text(body);
 
-        download_to_cache_username_emote(
-            session_client,
-            msg.sender.clone(),
-            &markup,
-            msg_label.clone(),
-            None,
-        );
-
         self.connect_right_click_menu(msg, Some(&msg_label));
         msg_label.set_markup(&format!("<b>{}</b> {}", sname, markup));
         self.set_label_styles(&msg_label);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]