[fractal/fractal-next] room_details: No avatar, no remove button



commit 0105a66f7f822491f6c9b5c04acc0c8b09a98d80
Author: Kai A. Hiller <V02460 gmail com>
Date:   Mon Aug 23 20:38:01 2021 +0200

    room_details: No avatar, no remove button

 src/session/content/room_details/room_details.rs | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)
---
diff --git a/src/session/content/room_details/room_details.rs 
b/src/session/content/room_details/room_details.rs
index 2fa5b2bb..b020ae98 100644
--- a/src/session/content/room_details/room_details.rs
+++ b/src/session/content/room_details/room_details.rs
@@ -1,5 +1,6 @@
 use adw::subclass::prelude::*;
 use gettextrs::gettext;
+use gtk::gdk;
 use gtk::{
     glib::{self, clone},
     prelude::*,
@@ -10,8 +11,8 @@ use matrix_sdk::ruma::events::EventType;
 
 use crate::components::CustomEntry;
 use crate::session::room::RoomAction;
-use crate::session::Room;
-use crate::utils::or_expr;
+use crate::session::{self, Room};
+use crate::utils::{and_expr, or_expr, prop_expr};
 
 mod imp {
     use super::*;
@@ -138,10 +139,25 @@ impl RoomDetails {
 
         // Hide avatar controls when the user is not eligible to perform the actions.
         let room = self.room();
+
+        let avatar = prop_expr(room, "avatar");
+        let avatar_image =
+            gtk::PropertyExpression::new(session::Avatar::static_type(), Some(&avatar), "image")
+                .upcast();
+        let room_avatar_exists = gtk::ClosureExpression::new(
+            move |args| {
+                let image: Option<gdk::Paintable> = args[1].get().unwrap();
+                image.is_some()
+            },
+            &[avatar_image],
+        )
+        .upcast();
+
         let room_avatar_changeable =
             room.new_allowed_expr(RoomAction::StateEvent(EventType::RoomAvatar));
+        let room_avatar_removable = and_expr(room_avatar_changeable.clone(), room_avatar_exists);
 
-        room_avatar_changeable.bind(&avatar_remove_button.get(), "visible", None);
+        room_avatar_removable.bind(&avatar_remove_button.get(), "visible", None);
         room_avatar_changeable.bind(&avatar_edit_button.get(), "visible", None);
     }
 


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