11use crate :: chat:: chat_room:: open_room:: OpenRoom ;
2+ use crate :: upload_mxc_dialog:: { upload_mxc_dialog, UploadMxcAcceptEvent } ;
23use cntp_i18n:: { tr, I18nString } ;
34use contemporary:: components:: button:: { button, ButtonMenuOpenPolicy } ;
45use contemporary:: components:: constrainer:: constrainer;
@@ -19,8 +20,9 @@ use gpui::{
1920 ElementId , Entity , InteractiveElement , IntoElement , ParentElement , Render , Styled , WeakEntity , Window ,
2021} ;
2122use matrix_sdk:: ruma:: api:: client:: room:: Visibility ;
23+ use matrix_sdk:: ruma:: events:: room:: avatar:: ImageInfo ;
2224use matrix_sdk:: ruma:: room:: JoinRule ;
23- use matrix_sdk:: ruma:: { OwnedRoomAliasId , RoomAliasId } ;
25+ use matrix_sdk:: ruma:: { OwnedRoomAliasId , RoomAliasId , UInt } ;
2426use matrix_sdk:: HttpError ;
2527use std:: rc:: Rc ;
2628use thegrid_common:: mxc_image:: { mxc_image, SizePolicy } ;
@@ -32,6 +34,7 @@ pub struct RoomSettings {
3234 on_back_click : Rc < Box < dyn Fn ( & ClickEvent , & mut Window , & mut App ) > > ,
3335 on_members_click : Rc < Box < dyn Fn ( & ClickEvent , & mut Window , & mut App ) > > ,
3436 edit_room_name_open : bool ,
37+ edit_room_image_open : bool ,
3538 new_name_text_field : Entity < TextField > ,
3639 enable_encryption_open : bool ,
3740 busy : bool ,
@@ -85,6 +88,7 @@ impl RoomSettings {
8588 } ) ,
8689
8790 edit_room_name_open : false ,
91+ edit_room_image_open : false ,
8892 enable_encryption_open : false ,
8993 busy : false ,
9094 published_to_directory : false ,
@@ -711,10 +715,17 @@ impl Render for RoomSettings {
711715 cx. notify ( )
712716 } ) ) ,
713717 )
714- . child ( button ( "room-change-profile-picture" ) . child ( icon_text (
715- "edit-rename" . into ( ) ,
716- tr ! ( "ROOM_CHANGE_PICTURE" , "Change Picture" ) . into ( ) ,
717- ) ) )
718+ . child (
719+ button ( "room-change-profile-picture" )
720+ . child ( icon_text (
721+ "edit-rename" . into ( ) ,
722+ tr ! ( "ROOM_CHANGE_PICTURE" , "Change Picture" ) . into ( ) ,
723+ ) )
724+ . on_click ( cx. listener ( move |this, _, _, cx| {
725+ this. edit_room_image_open = true ;
726+ cx. notify ( )
727+ } ) ) ,
728+ )
718729 . child (
719730 button ( "room-view-members" )
720731 . child ( icon_text (
@@ -921,6 +932,52 @@ impl Render for RoomSettings {
921932 } ) ) ,
922933 ) ,
923934 )
935+ . child ( upload_mxc_dialog (
936+ tr ! ( "ROOM_CHANGE_PICTURE" ) ,
937+ self . edit_room_image_open ,
938+ "dialog-ok" . into ( ) ,
939+ tr ! ( "ROOM_CHANGE_PICTURE" ) . into ( ) ,
940+ cx. listener ( move |this, _, _, cx| {
941+ this. edit_room_image_open = false ;
942+ cx. notify ( ) ;
943+ } ) ,
944+ cx. listener ( {
945+ let room = room. clone ( ) ;
946+ move |this, event : & UploadMxcAcceptEvent , _, cx| {
947+ let mxc_url = event. mxc_url . clone ( ) ;
948+
949+ let mut image_info = ImageInfo :: new ( ) ;
950+ image_info. height = UInt :: new ( event. height ) ;
951+ image_info. width = UInt :: new ( event. width ) ;
952+ image_info. blurhash = event. blur_hash . clone ( ) ;
953+ image_info. size = UInt :: new ( event. file_size ) ;
954+ cx. spawn ( {
955+ let room = room. clone ( ) ;
956+ async move |this : WeakEntity < Self > , cx : & mut AsyncApp | {
957+ if cx
958+ . spawn_tokio ( async move {
959+ room. set_avatar_url ( & mxc_url, Some ( image_info) ) . await
960+ } )
961+ . await
962+ . is_err ( )
963+ {
964+ this. update ( cx, |this, cx| {
965+ this. edit_room_image_open = false ;
966+ cx. notify ( )
967+ } )
968+ } else {
969+ this. update ( cx, |this, cx| {
970+ this. edit_room_image_open = false ;
971+ cx. notify ( )
972+ } )
973+ }
974+ }
975+ } )
976+ . detach ( ) ;
977+ cx. notify ( )
978+ }
979+ } ) ,
980+ ) )
924981 . child (
925982 dialog_box ( "enable-encryption" )
926983 . visible ( self . enable_encryption_open )
@@ -929,10 +986,10 @@ impl Render for RoomSettings {
929986 . content ( tr ! (
930987 "ROOM_ENCRYPTION_ENABLE_DESCRIPTION" ,
931988 "By enabling encryption, you will prevent anyone joining the room \
932- from being able to read message history. If there are any bots or \
933- services in this room, they may also stop working.\n \n \
934- Once enabled, encryption cannot be turned off.\n \n \
935- Do you want to enable encryption for this room?"
989+ from being able to read message history. If there are any bots or \
990+ services in this room, they may also stop working.\n \n \
991+ Once enabled, encryption cannot be turned off.\n \n \
992+ Do you want to enable encryption for this room?"
936993 ) )
937994 . standard_button (
938995 StandardButton :: Cancel ,
0 commit comments