@@ -12,7 +12,9 @@ use tdlib::{functions, types};
1212
1313use crate :: components:: MessageEntry ;
1414use crate :: session:: content:: SendPhotoDialog ;
15- use crate :: tdlib:: { BoxedDraftMessage , BoxedFormattedText , Chat , ChatType , SecretChatState } ;
15+ use crate :: tdlib:: {
16+ BasicGroup , BoxedDraftMessage , BoxedFormattedText , Chat , ChatType , SecretChatState , Supergroup ,
17+ } ;
1618use crate :: utils:: { block_on, spawn, temp_dir} ;
1719use crate :: { expressions, strings} ;
1820
@@ -29,6 +31,7 @@ enum ChatActionBarState {
2931mod imp {
3032 use super :: * ;
3133 use once_cell:: sync:: Lazy ;
34+ use once_cell:: unsync:: OnceCell ;
3235 use std:: cell:: { Cell , RefCell } ;
3336
3437 #[ derive( Debug , Default , CompositeTemplate ) ]
@@ -38,6 +41,9 @@ mod imp {
3841 pub ( super ) chat_action_in_cooldown : Cell < bool > ,
3942 pub ( super ) state : Cell < ChatActionBarState > ,
4043 pub ( super ) emoji_chooser : RefCell < Option < gtk:: EmojiChooser > > ,
44+ pub ( super ) chat_signal_group : OnceCell < glib:: SignalGroup > ,
45+ pub ( super ) basic_group_signal_group : OnceCell < glib:: SignalGroup > ,
46+ pub ( super ) supergroup_signal_group : OnceCell < glib:: SignalGroup > ,
4147 pub ( super ) bindings : RefCell < Vec < gtk:: ExpressionWatch > > ,
4248 #[ template_child]
4349 pub ( super ) top_bar_revealer : TemplateChild < gtk:: Revealer > ,
@@ -117,12 +123,6 @@ mod imp {
117123 None ,
118124 |widget, _, _| async move {
119125 widget. toggle_mute ( ) . await ;
120- let btn = & widget. imp ( ) . mute_button ;
121- if widget. is_chat_muted ( ) {
122- btn. set_label ( & gettext ( "Unmute" ) ) ;
123- } else {
124- btn. set_label ( & gettext ( "Mute" ) ) ;
125- }
126126 } ,
127127 ) ;
128128 klass. install_action_async (
@@ -221,6 +221,8 @@ mod imp {
221221 . connect_activate ( clone ! ( @weak obj => move |_| {
222222 obj. activate_action( "chat-action-bar.send-message" , None ) . unwrap( )
223223 } ) ) ;
224+
225+ obj. create_signal_groups ( ) ;
224226 }
225227
226228 fn dispose ( & self ) {
@@ -251,6 +253,55 @@ impl ChatActionBar {
251253 glib:: Object :: new ( )
252254 }
253255
256+ fn create_signal_groups ( & self ) {
257+ let imp = self . imp ( ) ;
258+
259+ let chat_signal_group = glib:: SignalGroup :: new ( Chat :: static_type ( ) ) ;
260+ chat_signal_group. connect_local (
261+ "notify::notification-settings" ,
262+ false ,
263+ clone ! ( @weak self as obj => @default -return None , move |_| {
264+ obj. update_stack_page( ) ;
265+ None
266+ } ) ,
267+ ) ;
268+ chat_signal_group. connect_local (
269+ "notify::is-blocked" ,
270+ false ,
271+ clone ! ( @weak self as obj => @default -return None , move |_| {
272+ obj. update_stack_page( ) ;
273+ None
274+ } ) ,
275+ ) ;
276+ imp. chat_signal_group . set ( chat_signal_group) . unwrap ( ) ;
277+
278+ let basic_group_signal_group = glib:: SignalGroup :: new ( BasicGroup :: static_type ( ) ) ;
279+ basic_group_signal_group. connect_local (
280+ "notify::status" ,
281+ false ,
282+ clone ! ( @weak self as obj => @default -return None , move |_| {
283+ obj. update_stack_page( ) ;
284+ None
285+ } ) ,
286+ ) ;
287+ imp. basic_group_signal_group
288+ . set ( basic_group_signal_group)
289+ . unwrap ( ) ;
290+
291+ let supergroup_signal_group = glib:: SignalGroup :: new ( Supergroup :: static_type ( ) ) ;
292+ supergroup_signal_group. connect_local (
293+ "notify::status" ,
294+ false ,
295+ clone ! ( @weak self as obj => @default -return None , move |_| {
296+ obj. update_stack_page( ) ;
297+ None
298+ } ) ,
299+ ) ;
300+ imp. supergroup_signal_group
301+ . set ( supergroup_signal_group)
302+ . unwrap ( ) ;
303+ }
304+
254305 fn cancel_action ( & self ) {
255306 use ChatActionBarState :: * ;
256307
@@ -694,10 +745,11 @@ impl ChatActionBar {
694745 }
695746
696747 imp. chat . replace ( chat) ;
697- self . notify ( "chat" ) ;
698748
699- // FIXME: Update entry_stack everytime ChatMemberStatus or ChatPermissions has changed
700749 self . update_stack_page ( ) ;
750+ self . update_signal_groups ( ) ;
751+
752+ self . notify ( "chat" ) ;
701753 }
702754
703755 pub ( crate ) fn reply_to_message_id ( & self , message_id : i64 ) {
@@ -708,7 +760,7 @@ impl ChatActionBar {
708760 self . set_state ( ChatActionBarState :: Editing ( message_id) ) ;
709761 }
710762
711- pub ( crate ) fn update_stack_page ( & self ) {
763+ fn update_stack_page ( & self ) {
712764 let imp = self . imp ( ) ;
713765 if let Some ( chat) = self . chat ( ) {
714766 match chat. type_ ( ) {
@@ -778,6 +830,28 @@ impl ChatActionBar {
778830 }
779831 }
780832 }
833+
834+ fn update_signal_groups ( & self ) {
835+ let imp = self . imp ( ) ;
836+
837+ let chat = self . chat ( ) ;
838+ imp. chat_signal_group
839+ . get ( )
840+ . unwrap ( )
841+ . set_target ( chat. as_ref ( ) ) ;
842+
843+ let basic_group = chat. as_ref ( ) . and_then ( |c| c. type_ ( ) . basic_group ( ) ) ;
844+ imp. basic_group_signal_group
845+ . get ( )
846+ . unwrap ( )
847+ . set_target ( basic_group) ;
848+
849+ let supergroup = chat. as_ref ( ) . and_then ( |c| c. type_ ( ) . supergroup ( ) ) ;
850+ imp. supergroup_signal_group
851+ . get ( )
852+ . unwrap ( )
853+ . set_target ( supergroup) ;
854+ }
781855}
782856
783857async fn save_stream_to_file (
0 commit comments