11mod chat_action_bar;
22mod chat_history;
33mod chat_info_window;
4+ mod pinned_messages_bar;
5+ mod pinned_messages_view;
46mod send_photo_dialog;
57
68use self :: chat_action_bar:: ChatActionBar ;
79use self :: chat_history:: ChatHistory ;
810use self :: chat_info_window:: ChatInfoWindow ;
11+ use self :: pinned_messages_bar:: PinnedMessagesBar ;
12+ use self :: pinned_messages_view:: PinnedMessagesView ;
913use self :: send_photo_dialog:: SendPhotoDialog ;
1014
1115use gtk:: glib;
@@ -31,6 +35,8 @@ mod imp {
3135 #[ template_child]
3236 pub ( super ) unselected_chat : TemplateChild < gtk:: Box > ,
3337 #[ template_child]
38+ pub ( super ) chat_leaflet : TemplateChild < adw:: Leaflet > ,
39+ #[ template_child]
3440 pub ( super ) chat_history : TemplateChild < ChatHistory > ,
3541 }
3642
@@ -41,8 +47,11 @@ mod imp {
4147 type ParentType = adw:: Bin ;
4248
4349 fn class_init ( klass : & mut Self :: Class ) {
44- ChatHistory :: static_type ( ) ;
4550 klass. bind_template ( ) ;
51+
52+ klass. install_action ( "content.show-pinned-messages" , None , move |widget, _, _| {
53+ widget. show_pinned_messages ( ) ;
54+ } ) ;
4655 }
4756
4857 fn instance_init ( obj : & glib:: subclass:: InitializingObject < Self > ) {
@@ -114,6 +123,16 @@ impl Content {
114123 self . imp ( ) . chat_history . handle_paste_action ( ) ;
115124 }
116125
126+ fn show_pinned_messages ( & self ) {
127+ if let Some ( chat) = self . chat ( ) {
128+ let imp = self . imp ( ) ;
129+ let pinned_messages = PinnedMessagesView :: new ( & chat) ;
130+
131+ imp. chat_leaflet . append ( & pinned_messages) ;
132+ imp. chat_leaflet . navigate ( adw:: NavigationDirection :: Forward ) ;
133+ }
134+ }
135+
117136 pub ( crate ) fn chat ( & self ) -> Option < Chat > {
118137 self . imp ( ) . chat . borrow ( ) . clone ( )
119138 }
@@ -125,7 +144,16 @@ impl Content {
125144
126145 let imp = self . imp ( ) ;
127146 if chat. is_some ( ) {
128- imp. stack . set_visible_child ( & imp. chat_history . get ( ) ) ;
147+ // Remove every leaflet page except the first one (the first chat history)
148+ imp. chat_leaflet
149+ . pages ( )
150+ . iter :: < adw:: LeafletPage > ( )
151+ . map ( |p| p. unwrap ( ) )
152+ . enumerate ( )
153+ . filter ( |( i, _) | i > & 0 )
154+ . for_each ( |( _, p) | imp. chat_leaflet . remove ( & p. child ( ) ) ) ;
155+
156+ imp. stack . set_visible_child ( & imp. chat_leaflet . get ( ) ) ;
129157 } else {
130158 imp. stack . set_visible_child ( & imp. unselected_chat . get ( ) ) ;
131159 }
0 commit comments