@@ -12,7 +12,9 @@ use tdlib::{functions, types};
12
12
13
13
use crate :: components:: MessageEntry ;
14
14
use 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
+ } ;
16
18
use crate :: utils:: { block_on, spawn, temp_dir} ;
17
19
use crate :: { expressions, strings} ;
18
20
@@ -29,6 +31,7 @@ enum ChatActionBarState {
29
31
mod imp {
30
32
use super :: * ;
31
33
use once_cell:: sync:: Lazy ;
34
+ use once_cell:: unsync:: OnceCell ;
32
35
use std:: cell:: { Cell , RefCell } ;
33
36
34
37
#[ derive( Debug , Default , CompositeTemplate ) ]
@@ -38,6 +41,9 @@ mod imp {
38
41
pub ( super ) chat_action_in_cooldown : Cell < bool > ,
39
42
pub ( super ) state : Cell < ChatActionBarState > ,
40
43
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 > ,
41
47
pub ( super ) bindings : RefCell < Vec < gtk:: ExpressionWatch > > ,
42
48
#[ template_child]
43
49
pub ( super ) top_bar_revealer : TemplateChild < gtk:: Revealer > ,
@@ -117,12 +123,6 @@ mod imp {
117
123
None ,
118
124
|widget, _, _| async move {
119
125
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
- }
126
126
} ,
127
127
) ;
128
128
klass. install_action_async (
@@ -221,6 +221,8 @@ mod imp {
221
221
. connect_activate ( clone ! ( @weak obj => move |_| {
222
222
obj. activate_action( "chat-action-bar.send-message" , None ) . unwrap( )
223
223
} ) ) ;
224
+
225
+ obj. create_signal_groups ( ) ;
224
226
}
225
227
226
228
fn dispose ( & self ) {
@@ -251,6 +253,55 @@ impl ChatActionBar {
251
253
glib:: Object :: new ( )
252
254
}
253
255
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
+
254
305
fn cancel_action ( & self ) {
255
306
use ChatActionBarState :: * ;
256
307
@@ -694,10 +745,11 @@ impl ChatActionBar {
694
745
}
695
746
696
747
imp. chat . replace ( chat) ;
697
- self . notify ( "chat" ) ;
698
748
699
- // FIXME: Update entry_stack everytime ChatMemberStatus or ChatPermissions has changed
700
749
self . update_stack_page ( ) ;
750
+ self . update_signal_groups ( ) ;
751
+
752
+ self . notify ( "chat" ) ;
701
753
}
702
754
703
755
pub ( crate ) fn reply_to_message_id ( & self , message_id : i64 ) {
@@ -708,7 +760,7 @@ impl ChatActionBar {
708
760
self . set_state ( ChatActionBarState :: Editing ( message_id) ) ;
709
761
}
710
762
711
- pub ( crate ) fn update_stack_page ( & self ) {
763
+ fn update_stack_page ( & self ) {
712
764
let imp = self . imp ( ) ;
713
765
if let Some ( chat) = self . chat ( ) {
714
766
match chat. type_ ( ) {
@@ -778,6 +830,28 @@ impl ChatActionBar {
778
830
}
779
831
}
780
832
}
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
+ }
781
855
}
782
856
783
857
async fn save_stream_to_file (
0 commit comments