diff --git a/src/error.rs b/src/error.rs index c3a94f03..1404c034 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,17 +1,13 @@ use gtk::{glib, subclass::prelude::*}; -use matrix_sdk::Error as MatrixError; - type WidgetBuilderFn = Box Option + 'static>; mod imp { use super::*; - use once_cell::sync::OnceCell; use std::cell::RefCell; #[derive(Default)] pub struct Error { - pub matrix_error: OnceCell, pub widget_builder: RefCell>, } @@ -31,23 +27,12 @@ glib::wrapper! { } impl Error { - pub fn new Option + 'static>(error: MatrixError, f: F) -> Self { + pub fn new Option + 'static>(f: F) -> Self { let obj: Self = glib::Object::new(&[]).expect("Failed to create Error"); - obj.set_matrix_error(error); obj.set_widget_builder(f); obj } - fn set_matrix_error(&self, error: MatrixError) { - let priv_ = imp::Error::from_instance(self); - priv_.matrix_error.set(error).unwrap() - } - - pub fn matrix_error(&self) -> &MatrixError { - let priv_ = imp::Error::from_instance(self); - priv_.matrix_error.get().unwrap() - } - /// Set a function that builds the widget used to display this error in the UI pub fn set_widget_builder Option + 'static>(&self, f: F) { let priv_ = imp::Error::from_instance(self); diff --git a/src/session/room/mod.rs b/src/session/room/mod.rs index a5fb480b..175f42eb 100644 --- a/src/session/room/mod.rs +++ b/src/session/room/mod.rs @@ -414,7 +414,6 @@ impl Room { Err(error) => { error!("Couldn’t set the room category: {}", error); let error = Error::new( - error, clone!(@weak obj => @default-return None, move |_| { let error_message = gettext!( "Failed to move from {} to {}.", @@ -889,16 +888,13 @@ impl Room { Ok(result) => Ok(result), Err(error) => { error!("Accepting invitation failed: {}", error); - let error = Error::new( - error, - clone!(@strong self as room => move |_| { - let error_message = gettext("Failed to accept invitation for . Try again later."); - let room_pill = Pill::new(); - room_pill.set_room(Some(room.clone())); - let error_label = LabelWithWidgets::new(&error_message, vec![room_pill]); - Some(error_label.upcast()) - }), - ); + let error = Error::new(clone!(@strong self as room => move |_| { + let error_message = gettext("Failed to accept invitation for . Try again later."); + let room_pill = Pill::new(); + room_pill.set_room(Some(room.clone())); + let error_label = LabelWithWidgets::new(&error_message, vec![room_pill]); + Some(error_label.upcast()) + })); if let Some(window) = self.session().parent_window() { window.append_error(&error); @@ -923,16 +919,13 @@ impl Room { Ok(result) => Ok(result), Err(error) => { error!("Rejecting invitation failed: {}", error); - let error = Error::new( - error, - clone!(@strong self as room => move |_| { - let error_message = gettext("Failed to reject invitation for . Try again later."); - let room_pill = Pill::new(); - room_pill.set_room(Some(room.clone())); - let error_label = LabelWithWidgets::new(&error_message, vec![room_pill]); - Some(error_label.upcast()) - }), - ); + let error = Error::new(clone!(@strong self as room => move |_| { + let error_message = gettext("Failed to reject invitation for . Try again later."); + let room_pill = Pill::new(); + room_pill.set_room(Some(room.clone())); + let error_label = LabelWithWidgets::new(&error_message, vec![room_pill]); + Some(error_label.upcast()) + })); if let Some(window) = self.session().parent_window() { window.append_error(&error); diff --git a/src/session/room_list.rs b/src/session/room_list.rs index e67fd247..ae860808 100644 --- a/src/session/room_list.rs +++ b/src/session/room_list.rs @@ -329,7 +329,6 @@ impl RoomList { obj.pending_rooms_remove(&identifier); error!("Joining room {} failed: {}", identifier, error); let error = Error::new( - matrix_sdk::Error::Http(error), clone!(@strong obj => move |_| { let error_message = gettext!( "Failed to join room {}. Try again later.", identifier