[fractal] Remove obsolete fields from widgets



commit 4dd7483a3c9d66ee9d2ef83ef369a34052feea89
Author: Kai A. Hiller <V02460 gmail com>
Date:   Sun Nov 29 16:32:17 2020 +0100

    Remove obsolete fields from widgets

 fractal-gtk/src/appop/media_viewer.rs    |  9 +--------
 fractal-gtk/src/appop/message.rs         | 12 ++----------
 fractal-gtk/src/appop/room.rs            |  2 +-
 fractal-gtk/src/appop/room_settings.rs   |  1 -
 fractal-gtk/src/widgets/image.rs         |  4 +---
 fractal-gtk/src/widgets/media_viewer.rs  | 18 +++++-------------
 fractal-gtk/src/widgets/message.rs       | 12 +++---------
 fractal-gtk/src/widgets/room_history.rs  | 20 +++++---------------
 fractal-gtk/src/widgets/room_settings.rs |  8 --------
 9 files changed, 18 insertions(+), 68 deletions(-)
---
diff --git a/fractal-gtk/src/appop/media_viewer.rs b/fractal-gtk/src/appop/media_viewer.rs
index 6c7ba658..f44b4a02 100644
--- a/fractal-gtk/src/appop/media_viewer.rs
+++ b/fractal-gtk/src/appop/media_viewer.rs
@@ -30,14 +30,7 @@ impl AppOp {
         {
             let room_id = self.active_room.as_ref()?;
             let room = self.rooms.get(room_id)?;
-            let mut panel = widgets::MediaViewer::new(
-                main_window,
-                room,
-                &msg,
-                login_data.session_client.homeserver().clone(),
-                login_data.access_token,
-                login_data.uid,
-            );
+            let mut panel = widgets::MediaViewer::new(main_window, room, &msg, login_data.uid);
             panel.display_media_viewer(login_data.session_client.clone(), msg);
             let (body, header) = panel.create(login_data.session_client.clone())?;
             *self.media_viewer.borrow_mut() = Some(panel);
diff --git a/fractal-gtk/src/appop/message.rs b/fractal-gtk/src/appop/message.rs
index 0b989d55..974974b4 100644
--- a/fractal-gtk/src/appop/message.rs
+++ b/fractal-gtk/src/appop/message.rs
@@ -70,11 +70,7 @@ impl AppOp {
         let login_data = self.login_data.clone()?;
         let messages = self.history.as_ref()?.get_listbox();
         if let Some(ui_msg) = self.create_new_room_message(&msg) {
-            let mb = widgets::MessageBox::new(
-                login_data.session_client.homeserver().clone(),
-                login_data.access_token,
-            )
-            .tmpwidget(
+            let mb = widgets::MessageBox::new().tmpwidget(
                 login_data.session_client.clone(),
                 self.user_info_cache.clone(),
                 &ui_msg,
@@ -114,11 +110,7 @@ impl AppOp {
         let mut widgets = vec![];
         for t in self.msg_queue.iter().rev().filter(|m| m.msg.room == r.id) {
             if let Some(ui_msg) = self.create_new_room_message(&t.msg) {
-                let mb = widgets::MessageBox::new(
-                    login_data.session_client.homeserver().clone(),
-                    login_data.access_token.clone(),
-                )
-                .tmpwidget(
+                let mb = widgets::MessageBox::new().tmpwidget(
                     login_data.session_client.clone(),
                     self.user_info_cache.clone(),
                     &ui_msg,
diff --git a/fractal-gtk/src/appop/room.rs b/fractal-gtk/src/appop/room.rs
index 6b635861..e21f561d 100644
--- a/fractal-gtk/src/appop/room.rs
+++ b/fractal-gtk/src/appop/room.rs
@@ -303,7 +303,7 @@ impl AppOp {
             self.ui.clone(),
             back_history,
         );
-        let history = widgets::RoomHistory::new(actions, active_room.clone(), self);
+        let history = widgets::RoomHistory::new(actions, active_room.clone(), &self.ui);
         self.history = if let Some(mut history) = history {
             history.create(
                 login_data.session_client,
diff --git a/fractal-gtk/src/appop/room_settings.rs b/fractal-gtk/src/appop/room_settings.rs
index 4b939823..f4acc52a 100644
--- a/fractal-gtk/src/appop/room_settings.rs
+++ b/fractal-gtk/src/appop/room_settings.rs
@@ -26,7 +26,6 @@ impl AppOp {
                 &window,
                 login_data.uid,
                 room.clone(),
-                login_data.access_token,
             );
             let page = panel.create(login_data.session_client.clone())?;
 
diff --git a/fractal-gtk/src/widgets/image.rs b/fractal-gtk/src/widgets/image.rs
index c371e79f..760f85e5 100644
--- a/fractal-gtk/src/widgets/image.rs
+++ b/fractal-gtk/src/widgets/image.rs
@@ -20,7 +20,6 @@ use url::Url;
 pub struct Image {
     pub path: Either<Url, PathBuf>,
     pub local_path: Arc<Mutex<Option<PathBuf>>>,
-    pub server_url: Url,
     pub max_size: Option<(i32, i32)>,
     pub widget: DrawingArea,
     pub pixbuf: Arc<Mutex<Option<Pixbuf>>>,
@@ -46,7 +45,7 @@ impl Image {
     ///           .size(Some((50, 50)))
     ///           .build();
     /// ```
-    pub fn new(server_url: Url, path: Either<Url, PathBuf>) -> Image {
+    pub fn new(path: Either<Url, PathBuf>) -> Image {
         let da = DrawingArea::new();
         da.add_events(gdk::EventMask::ENTER_NOTIFY_MASK);
         da.add_events(gdk::EventMask::LEAVE_NOTIFY_MASK);
@@ -65,7 +64,6 @@ impl Image {
         Image {
             path,
             local_path: Arc::new(Mutex::new(None)),
-            server_url,
             max_size: None,
             widget: da,
             pixbuf: Arc::new(Mutex::new(None)),
diff --git a/fractal-gtk/src/widgets/media_viewer.rs b/fractal-gtk/src/widgets/media_viewer.rs
index d3fe5ea5..ee4c5fa8 100644
--- a/fractal-gtk/src/widgets/media_viewer.rs
+++ b/fractal-gtk/src/widgets/media_viewer.rs
@@ -1,4 +1,3 @@
-use crate::api::r0::AccessToken;
 use crate::app::RUNTIME;
 use crate::backend::media;
 use glib::clone;
@@ -126,8 +125,6 @@ enum Widget {
 struct Data {
     builder: gtk::Builder,
     main_window: gtk::Window,
-    server_url: Url,
-    access_token: AccessToken,
     uid: UserId,
     admins: HashMap<UserId, i64>,
 
@@ -325,7 +322,7 @@ impl Data {
 
         match msg.mtype.as_ref() {
             "m.image" => {
-                let image = image::Image::new(self.server_url.clone(), Either::Left(url))
+                let image = image::Image::new(Either::Left(url))
                     .shrink_to_fit(true)
                     .center(true)
                     .build(session_client);
@@ -588,8 +585,6 @@ impl MediaViewer {
         main_window: gtk::Window,
         room: &Room,
         current_media_msg: &Message,
-        server_url: Url,
-        access_token: AccessToken,
         uid: UserId,
     ) -> MediaViewer {
         let builder = gtk::Builder::new();
@@ -625,8 +620,6 @@ impl MediaViewer {
                 no_more_media: false,
                 widget: Widget::None,
                 builder: builder.clone(),
-                server_url,
-                access_token,
                 uid,
                 admins: room.admins.clone(),
                 main_window,
@@ -679,11 +672,10 @@ impl MediaViewer {
 
         match media_msg.mtype.as_ref() {
             "m.image" => {
-                let image =
-                    image::Image::new(self.data.borrow().server_url.clone(), Either::Left(url))
-                        .shrink_to_fit(true)
-                        .center(true)
-                        .build(session_client);
+                let image = image::Image::new(Either::Left(url))
+                    .shrink_to_fit(true)
+                    .center(true)
+                    .build(session_client);
 
                 media_container.add(&image.widget);
                 media_container.show_all();
diff --git a/fractal-gtk/src/widgets/message.rs b/fractal-gtk/src/widgets/message.rs
index 51adc0c5..ece498f7 100644
--- a/fractal-gtk/src/widgets/message.rs
+++ b/fractal-gtk/src/widgets/message.rs
@@ -1,7 +1,6 @@
 use crate::util::i18n::i18n;
 use itertools::Itertools;
 
-use crate::api::r0::AccessToken;
 use crate::appop::UserInfoCache;
 use chrono::prelude::*;
 use either::Either;
@@ -10,7 +9,6 @@ use gtk::{prelude::*, ButtonExt, ContainerExt, LabelExt, Overlay, WidgetExt};
 use matrix_sdk::Client as MatrixClient;
 use std::cmp::max;
 use std::rc::Rc;
-use url::Url;
 
 use crate::util::markup_text;
 
@@ -30,8 +28,6 @@ use crate::widgets::{AudioPlayerWidget, PlayerExt, VideoPlayerWidget};
 /* A message row in the room history */
 #[derive(Clone, Debug)]
 pub struct MessageBox {
-    access_token: AccessToken,
-    server_url: Url,
     username: gtk::Label,
     pub username_event_box: gtk::EventBox,
     eventbox: gtk::EventBox,
@@ -43,7 +39,7 @@ pub struct MessageBox {
 }
 
 impl MessageBox {
-    pub fn new(server_url: Url, access_token: AccessToken) -> MessageBox {
+    pub fn new() -> MessageBox {
         let username = gtk::Label::new(None);
         let eb = gtk::EventBox::new();
         let eventbox = gtk::EventBox::new();
@@ -55,8 +51,6 @@ impl MessageBox {
         gesture.set_touch_only(true);
 
         MessageBox {
-            access_token,
-            server_url,
             username,
             username_event_box: eb,
             eventbox,
@@ -413,7 +407,7 @@ impl MessageBox {
             .or_else(|| Some(Either::Right(msg.local_path.clone()?)));
 
         if let Some(img_path) = img {
-            let image = widgets::image::Image::new(self.server_url.clone(), img_path)
+            let image = widgets::image::Image::new(img_path)
                 .size(Some(globals::MAX_IMAGE_SIZE))
                 .build(session_client);
 
@@ -431,7 +425,7 @@ impl MessageBox {
     fn build_room_msg_sticker(&self, session_client: MatrixClient, msg: &Message) -> gtk::Box {
         let bx = gtk::Box::new(gtk::Orientation::Horizontal, 0);
         if let Some(url) = msg.url.clone() {
-            let image = widgets::image::Image::new(self.server_url.clone(), Either::Left(url))
+            let image = widgets::image::Image::new(Either::Left(url))
                 .size(Some(globals::MAX_STICKER_SIZE))
                 .build(session_client);
             image.widget.set_tooltip_text(Some(&msg.body[..]));
diff --git a/fractal-gtk/src/widgets/room_history.rs b/fractal-gtk/src/widgets/room_history.rs
index 50a2bb6c..9f83b3d0 100644
--- a/fractal-gtk/src/widgets/room_history.rs
+++ b/fractal-gtk/src/widgets/room_history.rs
@@ -8,12 +8,12 @@ use std::cell::RefCell;
 use std::collections::VecDeque;
 use std::rc::Rc;
 
-use crate::appop::{AppOp, UserInfoCache};
+use crate::appop::UserInfoCache;
+use crate::uibuilder::UI;
 use crate::uitypes::MessageContent;
 use crate::uitypes::RowType;
 use crate::util::i18n::i18n;
 
-use crate::api::r0::AccessToken;
 use crate::globals;
 use crate::widgets;
 use crate::widgets::{PlayerExt, VideoPlayerWidget};
@@ -270,16 +270,14 @@ impl Element {
 pub struct RoomHistory {
     /* Contains a list of msg ids to keep track of the displayed messages */
     rows: Rc<RefCell<List>>,
-    access_token: AccessToken,
     source_id: Rc<RefCell<Option<source::SourceId>>>,
     queue: Rc<RefCell<VecDeque<MessageContent>>>,
     edit_buffer: Rc<RefCell<VecDeque<MessageContent>>>,
 }
 
 impl RoomHistory {
-    pub fn new(actions: SimpleActionGroup, room_id: RoomId, op: &AppOp) -> Option<RoomHistory> {
-        let history_container = op
-            .ui
+    pub fn new(actions: SimpleActionGroup, room_id: RoomId, ui: &UI) -> Option<RoomHistory> {
+        let history_container = ui
             .builder
             .get_object::<gtk::Box>("history_container")
             .expect("Can't find history_container in ui file.");
@@ -295,10 +293,8 @@ impl RoomHistory {
 
         /* Add the action groupe to the room_history */
         listbox.insert_action_group("message", Some(&actions));
-        let login_data = op.login_data.clone()?;
         let mut rh = RoomHistory {
             rows: Rc::new(RefCell::new(List::new(scroll))),
-            access_token: login_data.access_token,
             source_id: Rc::new(RefCell::new(None)),
             queue: Rc::new(RefCell::new(VecDeque::new())),
             edit_buffer: Rc::new(RefCell::new(VecDeque::new())),
@@ -461,7 +457,6 @@ impl RoomHistory {
         } else {
             /* Lazy load initial messages */
             let source_id = self.source_id.clone();
-            let access_token = self.access_token.clone();
             *self.source_id.borrow_mut() = Some(glib::idle_add_local(move || {
                 let mut data = queue.borrow_mut();
                 let mut edits = edit_buffer.borrow_mut();
@@ -521,7 +516,6 @@ impl RoomHistory {
                         user_info_cache.clone(),
                         item.clone(),
                         has_header,
-                        access_token.clone(),
                         &rows,
                     ));
                     rows.borrow_mut().add_top(Element::Message(item));
@@ -596,7 +590,6 @@ impl RoomHistory {
             user_info_cache,
             item.clone(),
             has_header,
-            self.access_token.clone(),
             &self.rows,
         );
         item.widget = Some(b);
@@ -633,7 +626,6 @@ impl RoomHistory {
             user_info_cache,
             item.clone(),
             msg_widget.header,
-            self.access_token.clone(),
             &self.rows,
         ));
         rows.replace_item(i, Element::Message(item));
@@ -744,13 +736,11 @@ fn create_row(
     user_info_cache: UserInfoCache,
     row: MessageContent,
     has_header: bool,
-    access_token: AccessToken,
     rows: &Rc<RefCell<List>>,
 ) -> widgets::MessageBox {
-    let server_url = session_client.homeserver().clone();
     /* we need to create a message with the username, so that we don't have to pass
      * all information to the widget creating each row */
-    let mut mb = widgets::MessageBox::new(server_url, access_token);
+    let mut mb = widgets::MessageBox::new();
     mb.create(
         session_client,
         user_info_cache,
diff --git a/fractal-gtk/src/widgets/room_settings.rs b/fractal-gtk/src/widgets/room_settings.rs
index 01ddc8cd..9e6bbaab 100644
--- a/fractal-gtk/src/widgets/room_settings.rs
+++ b/fractal-gtk/src/widgets/room_settings.rs
@@ -1,4 +1,3 @@
-use crate::api::r0::AccessToken;
 use crate::backend::{room, HandleError};
 use glib::clone;
 use matrix_sdk::identifiers::UserId;
@@ -9,7 +8,6 @@ use std::rc::Rc;
 use crate::util::i18n::ni18n_f;
 use gio::prelude::*;
 use gtk::prelude::*;
-use url::Url;
 
 use crate::actions;
 use crate::actions::{ButtonState, StateExt};
@@ -27,8 +25,6 @@ pub struct RoomSettings {
     uid: UserId,
     builder: gtk::Builder,
     members_list: Option<MembersList>,
-    server_url: Url,
-    access_token: AccessToken,
     switch_handler: Option<Rc<glib::SignalHandlerId>>,
 }
 
@@ -38,9 +34,7 @@ impl RoomSettings {
         window: &gtk::Window,
         uid: UserId,
         room: Room,
-        access_token: AccessToken,
     ) -> RoomSettings {
-        let server_url = session_client.homeserver().clone();
         let builder = gtk::Builder::new();
 
         builder
@@ -60,8 +54,6 @@ impl RoomSettings {
             uid,
             builder,
             members_list: None,
-            server_url,
-            access_token,
             switch_handler: None,
         }
     }


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