@@ -21,6 +21,7 @@ mod imp {
21
21
use once_cell:: sync:: Lazy ;
22
22
use once_cell:: unsync:: OnceCell ;
23
23
use std:: cell:: { Cell , RefCell } ;
24
+ use std:: collections:: HashSet ;
24
25
25
26
#[ derive( Debug , Default , CompositeTemplate ) ]
26
27
#[ template( resource = "/com/github/melix99/telegrand/ui/content-chat-history.ui" ) ]
@@ -31,6 +32,7 @@ mod imp {
31
32
pub ( super ) message_menu : OnceCell < gtk:: PopoverMenu > ,
32
33
pub ( super ) is_auto_scrolling : Cell < bool > ,
33
34
pub ( super ) sticky : Cell < bool > ,
35
+ pub ( super ) visible_messages : RefCell < HashSet < i64 > > ,
34
36
#[ template_child]
35
37
pub ( super ) window_title : TemplateChild < adw:: WindowTitle > ,
36
38
#[ template_child]
@@ -76,6 +78,38 @@ mod imp {
76
78
widget. show_leave_chat_dialog ( ) . await ;
77
79
} ,
78
80
) ;
81
+ klass. install_action_async (
82
+ "chat-history.add-visible-message" ,
83
+ Some ( "x" ) ,
84
+ |widget, _, variant| async move {
85
+ let message_id = variant. and_then ( |v| v. get ( ) ) . unwrap ( ) ;
86
+ if widget
87
+ . imp ( )
88
+ . visible_messages
89
+ . borrow_mut ( )
90
+ . insert ( message_id)
91
+ {
92
+ println ! ( "ADD {}" , message_id) ;
93
+ widget. update_visible_messages ( ) . await ;
94
+ }
95
+ } ,
96
+ ) ;
97
+ klass. install_action_async (
98
+ "chat-history.remove-visible-message" ,
99
+ Some ( "x" ) ,
100
+ |widget, _, variant| async move {
101
+ let message_id = variant. and_then ( |v| v. get ( ) ) . unwrap ( ) ;
102
+ if widget
103
+ . imp ( )
104
+ . visible_messages
105
+ . borrow_mut ( )
106
+ . remove ( & message_id)
107
+ {
108
+ println ! ( "REMOVE {}" , message_id) ;
109
+ widget. update_visible_messages ( ) . await ;
110
+ }
111
+ } ,
112
+ ) ;
79
113
}
80
114
81
115
fn instance_init ( obj : & glib:: subclass:: InitializingObject < Self > ) {
@@ -217,6 +251,39 @@ impl ChatHistory {
217
251
}
218
252
}
219
253
254
+ async fn update_visible_messages ( & self ) {
255
+ if let Some ( chat) = self . chat ( ) {
256
+ let client_id = chat. session ( ) . client_id ( ) ;
257
+ let message_ids = self
258
+ . imp ( )
259
+ . visible_messages
260
+ . borrow ( )
261
+ . clone ( )
262
+ . into_iter ( )
263
+ . collect ( ) ;
264
+ let result =
265
+ tdlib:: functions:: view_messages ( chat. id ( ) , 0 , message_ids, false , client_id) . await ;
266
+
267
+ if let Err ( e) = result {
268
+ log:: warn!( "Error setting visible messages: {e:?}" ) ;
269
+ }
270
+
271
+ let msgs: Vec < String > = self
272
+ . imp ( )
273
+ . visible_messages
274
+ . borrow ( )
275
+ . iter ( )
276
+ . map ( |id| {
277
+ let message = self . chat ( ) . unwrap ( ) . message ( * id) . unwrap ( ) ;
278
+ format ! ( "{} ||| {}" , crate :: strings:: message_content( & message) , id)
279
+ } )
280
+ . collect ( ) ;
281
+ dbg ! ( msgs) ;
282
+ println ! ( ) ;
283
+ println ! ( ) ;
284
+ }
285
+ }
286
+
220
287
fn open_info_dialog ( & self ) {
221
288
if let Some ( chat) = self . chat ( ) {
222
289
ChatInfoWindow :: new ( & self . parent_window ( ) , & chat) . present ( ) ;
0 commit comments