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_view : TemplateChild < adw:: ToolbarView > ,
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,14 @@ 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.go-back" , None , move |widget, _, _| {
53+ widget. go_back ( ) ;
54+ } ) ;
55+ klass. install_action ( "content.show-pinned-messages" , None , move |widget, _, _| {
56+ widget. show_pinned_messages ( ) ;
57+ } ) ;
4658 }
4759
4860 fn instance_init ( obj : & glib:: subclass:: InitializingObject < Self > ) {
@@ -114,6 +126,36 @@ impl Content {
114126 self . imp ( ) . chat_history . handle_paste_action ( ) ;
115127 }
116128
129+ fn go_back ( & self ) {
130+ self . imp ( )
131+ . chat_leaflet
132+ . navigate ( adw:: NavigationDirection :: Back ) ;
133+ }
134+
135+ fn show_pinned_messages ( & self ) {
136+ if let Some ( chat) = self . chat ( ) {
137+ let imp = self . imp ( ) ;
138+
139+ let next_child = imp
140+ . chat_leaflet
141+ . adjacent_child ( adw:: NavigationDirection :: Forward ) ;
142+ let cached = if let Some ( pinned_messages_view) =
143+ next_child. and_downcast :: < PinnedMessagesView > ( )
144+ {
145+ pinned_messages_view. chat ( ) == chat
146+ } else {
147+ false
148+ } ;
149+
150+ if !cached {
151+ let pinned_messages = PinnedMessagesView :: new ( & chat) ;
152+ imp. chat_leaflet . append ( & pinned_messages) ;
153+ }
154+
155+ imp. chat_leaflet . navigate ( adw:: NavigationDirection :: Forward ) ;
156+ }
157+ }
158+
117159 pub ( crate ) fn chat ( & self ) -> Option < Chat > {
118160 self . imp ( ) . chat . borrow ( ) . clone ( )
119161 }
@@ -125,7 +167,16 @@ impl Content {
125167
126168 let imp = self . imp ( ) ;
127169 if chat. is_some ( ) {
128- imp. stack . set_visible_child ( & imp. chat_history . get ( ) ) ;
170+ // Remove every leaflet page except the first one (the first chat history)
171+ imp. chat_leaflet
172+ . pages ( )
173+ . iter :: < adw:: LeafletPage > ( )
174+ . map ( |p| p. unwrap ( ) )
175+ . enumerate ( )
176+ . filter ( |( i, _) | i > & 0 )
177+ . for_each ( |( _, p) | imp. chat_leaflet . remove ( & p. child ( ) ) ) ;
178+
179+ imp. stack . set_visible_child ( & imp. chat_leaflet . get ( ) ) ;
129180 } else {
130181 imp. stack . set_visible_child ( & imp. unselected_chat_view . get ( ) ) ;
131182 }
0 commit comments