Skip to content

Commit e707eaa

Browse files
committed
WIP: chat-history: Move the message list in a separate widget
This a new major change to the chat history. We now have a new widget component, called MessageListView, which can display messages... in a list view. For now it's basically the same as the internal list view in ChatHistory, but in the future it will support showing messages from other contexts, like pinned messages history, reply threads, post comments, etc.
1 parent d4e2b03 commit e707eaa

26 files changed

+518
-439
lines changed

data/resources/resources.gresource.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<file compressed="true" preprocess="xml-stripblanks">ui/content-message-text.ui</file>
2626
<file compressed="true" preprocess="xml-stripblanks">ui/content-send-photo-dialog.ui</file>
2727
<file compressed="true" preprocess="xml-stripblanks">ui/login.ui</file>
28+
<file compressed="true" preprocess="xml-stripblanks">ui/message-list-view.ui</file>
2829
<file compressed="true" preprocess="xml-stripblanks">ui/message-menu.ui</file>
2930
<file compressed="true" preprocess="xml-stripblanks">ui/phone-number-input.ui</file>
3031
<file compressed="true" preprocess="xml-stripblanks">ui/preferences-window.ui</file>

data/resources/style.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,11 @@ sidebarsearchitemrow {
119119
border-spacing: 12px;
120120
}
121121

122-
listview.chat-history {
122+
messagelistview listview.message {
123123
padding: 3px 0;
124124
}
125125

126-
listview.chat-history > row {
126+
messagelistview listview.message > row {
127127
margin: 2px 4px;
128128
border-radius: 9px;
129129
}

data/resources/ui/content-chat-history.ui

Lines changed: 2 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -35,98 +35,8 @@
3535
</object>
3636
</child>
3737
<child>
38-
<object class="GtkOverlay">
39-
<child type="overlay">
40-
<object class="GtkRevealer">
41-
<property name="transition-type">slide-up</property>
42-
<property name="reveal-child" bind-source="ContentChatHistory" bind-property="sticky" bind-flags="sync-create|invert-boolean"/>
43-
<property name="valign">end</property>
44-
<property name="halign">end</property>
45-
<child>
46-
<object class="GtkOverlay">
47-
<child type="overlay">
48-
<object class="GtkLabel">
49-
<property name="halign">center</property>
50-
<property name="valign">start</property>
51-
<property name="ellipsize">middle</property>
52-
<binding name="label">
53-
<lookup name="unread-count" type="Chat">
54-
<lookup name="chat">ContentChatHistory</lookup>
55-
</lookup>
56-
</binding>
57-
<binding name="visible">
58-
<lookup name="unread-count" type="Chat">
59-
<lookup name="chat">ContentChatHistory</lookup>
60-
</lookup>
61-
</binding>
62-
<style>
63-
<class name="unread-count"/>
64-
</style>
65-
</object>
66-
</child>
67-
<child>
68-
<object class="GtkButton">
69-
<property name="halign">center</property>
70-
<property name="valign">end</property>
71-
<property name="icon-name">go-down-symbolic</property>
72-
<property name="action-name">chat-history.scroll-down</property>
73-
<accessibility>
74-
<property name="label" translatable="yes">Scroll to bottom</property>
75-
</accessibility>
76-
<style>
77-
<class name="circular"/>
78-
<class name="opaque"/>
79-
<class name="scroll-to-bottom"/>
80-
</style>
81-
</object>
82-
</child>
83-
</object>
84-
</child>
85-
</object>
86-
</child>
87-
<child>
88-
<object class="GtkScrolledWindow" id="scrolled_window">
89-
<property name="vexpand">True</property>
90-
<property name="hscrollbar-policy">never</property>
91-
<style>
92-
<class name="view"/>
93-
</style>
94-
<property name="child">
95-
<object class="AdwClampScrollable">
96-
<property name="maximum-size">800</property>
97-
<property name="tightening-threshold">600</property>
98-
<property name="vscroll-policy">natural</property>
99-
<property name="child">
100-
<object class="GtkListView" id="list_view">
101-
<property name="reversed">True</property>
102-
<style>
103-
<class name="chat-history"/>
104-
</style>
105-
<property name="factory">
106-
<object class="GtkBuilderListItemFactory">
107-
<property name="bytes"><![CDATA[
108-
<?xml version="1.0" encoding="UTF-8"?>
109-
<interface>
110-
<template class="GtkListItem">
111-
<property name="activatable">False</property>
112-
<property name="child">
113-
<object class="ContentChatHistoryRow">
114-
<binding name="item">
115-
<lookup name="item">GtkListItem</lookup>
116-
</binding>
117-
</object>
118-
</property>
119-
</template>
120-
</interface>
121-
]]></property>
122-
</object>
123-
</property>
124-
</object>
125-
</property>
126-
</object>
127-
</property>
128-
</object>
129-
</child>
38+
<object class="MessageListView" id="message_list_view">
39+
<property name="vexpand">True</property>
13040
</object>
13141
</child>
13242
<child>

data/resources/ui/content-event-row.blp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using Gtk 4.0;
22
using Adw 1;
33

4-
template ContentEventRow : Adw.Bin {
4+
template MessageListViewEventRow : Adw.Bin {
55
styles ["event-row"]
66

77
child: Label label {
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<interface>
3+
<template class="MessageListView" parent="GtkWidget">
4+
<child>
5+
<object class="GtkOverlay">
6+
<child type="overlay">
7+
<object class="GtkRevealer" id="scroll_to_bottom_revealer">
8+
<property name="transition-type">slide-up</property>
9+
<property name="valign">end</property>
10+
<property name="halign">end</property>
11+
<child>
12+
<object class="GtkOverlay">
13+
<child type="overlay">
14+
<object class="GtkLabel">
15+
<property name="halign">center</property>
16+
<property name="valign">start</property>
17+
<property name="ellipsize">middle</property>
18+
<!-- <binding name="label"> -->
19+
<!-- <lookup name="unread-count" type="Chat"> -->
20+
<!-- <lookup name="chat">ContentChatHistory</lookup> -->
21+
<!-- </lookup> -->
22+
<!-- </binding> -->
23+
<!-- <binding name="visible"> -->
24+
<!-- <lookup name="unread-count" type="Chat"> -->
25+
<!-- <lookup name="chat">ContentChatHistory</lookup> -->
26+
<!-- </lookup> -->
27+
<!-- </binding> -->
28+
<style>
29+
<class name="unread-count"/>
30+
</style>
31+
</object>
32+
</child>
33+
<child>
34+
<object class="GtkButton">
35+
<property name="halign">center</property>
36+
<property name="valign">end</property>
37+
<property name="icon-name">go-down-symbolic</property>
38+
<property name="action-name">message-list-view.scroll-to-bottom</property>
39+
<accessibility>
40+
<property name="label" translatable="yes">Scroll to bottom</property>
41+
</accessibility>
42+
<style>
43+
<class name="circular"/>
44+
<class name="opaque"/>
45+
<class name="scroll-to-bottom"/>
46+
</style>
47+
</object>
48+
</child>
49+
</object>
50+
</child>
51+
</object>
52+
</child>
53+
<child>
54+
<object class="GtkScrolledWindow" id="scrolled_window">
55+
<property name="hscrollbar-policy">never</property>
56+
<style>
57+
<class name="view"/>
58+
</style>
59+
<property name="child">
60+
<object class="AdwClampScrollable">
61+
<property name="maximum-size">800</property>
62+
<property name="tightening-threshold">600</property>
63+
<property name="vscroll-policy">natural</property>
64+
<property name="child">
65+
<object class="GtkListView" id="list_view">
66+
<property name="reversed">True</property>
67+
<style>
68+
<class name="message"/>
69+
</style>
70+
<property name="factory">
71+
<object class="GtkBuilderListItemFactory">
72+
<property name="bytes"><![CDATA[
73+
<?xml version="1.0" encoding="UTF-8"?>
74+
<interface>
75+
<template class="GtkListItem">
76+
<property name="activatable">False</property>
77+
<property name="child">
78+
<object class="MessageListViewRow">
79+
<binding name="item">
80+
<lookup name="item">GtkListItem</lookup>
81+
</binding>
82+
</object>
83+
</property>
84+
</template>
85+
</interface>
86+
]]></property>
87+
</object>
88+
</property>
89+
</object>
90+
</property>
91+
</object>
92+
</property>
93+
</object>
94+
</child>
95+
</object>
96+
</child>
97+
</template>
98+
</interface>

data/resources/ui/message-menu.blp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ menu model {
1616

1717
item {
1818
label: _("Delete for Ever_yone");
19-
action: "message-row.revoke-delete";
19+
action: "message-list-view.revoke-delete";
2020
hidden-when: "action-disabled";
2121
}
2222

2323
item {
2424
label: _("_Delete for Me");
25-
action: "message-row.delete";
25+
action: "message-list-view.delete";
2626
hidden-when: "action-disabled";
2727
}
2828
}

src/session/content/event_row.rs renamed to src/components/message_list_view/event_row.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ mod imp {
99

1010
#[derive(Debug, Default, CompositeTemplate)]
1111
#[template(resource = "/com/github/melix99/telegrand/ui/content-event-row.ui")]
12-
pub(crate) struct EventRow {
12+
pub(crate) struct MessageListViewEventRow {
1313
#[template_child]
1414
pub(super) label: TemplateChild<gtk::Label>,
1515
}
1616

1717
#[glib::object_subclass]
18-
impl ObjectSubclass for EventRow {
19-
const NAME: &'static str = "ContentEventRow";
20-
type Type = super::EventRow;
18+
impl ObjectSubclass for MessageListViewEventRow {
19+
const NAME: &'static str = "MessageListViewEventRow";
20+
type Type = super::MessageListViewEventRow;
2121
type ParentType = adw::Bin;
2222

2323
fn class_init(klass: &mut Self::Class) {
@@ -29,7 +29,7 @@ mod imp {
2929
}
3030
}
3131

32-
impl ObjectImpl for EventRow {
32+
impl ObjectImpl for MessageListViewEventRow {
3333
fn properties() -> &'static [glib::ParamSpec] {
3434
static PROPERTIES: Lazy<Vec<glib::ParamSpec>> =
3535
Lazy::new(|| vec![glib::ParamSpecString::builder("label").build()]);
@@ -55,22 +55,22 @@ mod imp {
5555
}
5656
}
5757

58-
impl WidgetImpl for EventRow {}
59-
impl BinImpl for EventRow {}
58+
impl WidgetImpl for MessageListViewEventRow {}
59+
impl BinImpl for MessageListViewEventRow {}
6060
}
6161

6262
glib::wrapper! {
63-
pub(crate) struct EventRow(ObjectSubclass<imp::EventRow>)
63+
pub(crate) struct MessageListViewEventRow(ObjectSubclass<imp::MessageListViewEventRow>)
6464
@extends gtk::Widget, adw::Bin;
6565
}
6666

67-
impl Default for EventRow {
67+
impl Default for MessageListViewEventRow {
6868
fn default() -> Self {
6969
Self::new()
7070
}
7171
}
7272

73-
impl EventRow {
73+
impl MessageListViewEventRow {
7474
pub(crate) fn new() -> Self {
7575
glib::Object::new()
7676
}

0 commit comments

Comments
 (0)