@@ -3,12 +3,12 @@ use std::sync::Arc;
3
3
use imbl:: Vector ;
4
4
use matrix_sdk:: ruma:: events:: room:: message:: MessageType ;
5
5
use matrix_sdk_ui:: timeline:: {
6
- MembershipChange , MsgLikeContent , MsgLikeKind , TimelineItem , TimelineItemContent ,
7
- TimelineItemKind , VirtualTimelineItem ,
6
+ MembershipChange , MsgLikeContent , MsgLikeKind , TimelineDetails , TimelineItem ,
7
+ TimelineItemContent , TimelineItemKind , VirtualTimelineItem ,
8
8
} ;
9
9
use ratatui:: { prelude:: * , widgets:: * } ;
10
10
11
- use crate :: { ALT_ROW_COLOR , NORMAL_ROW_COLOR , TEXT_COLOR } ;
11
+ use crate :: { ALT_ROW_COLOR , NORMAL_ROW_COLOR , SELECTED_STYLE_FG , TEXT_COLOR } ;
12
12
13
13
pub struct TimelineView < ' a > {
14
14
items : & ' a Vector < Arc < TimelineItem > > ,
@@ -27,7 +27,7 @@ impl StatefulWidget for &mut TimelineView<'_> {
27
27
where
28
28
Self : Sized ,
29
29
{
30
- let mut content = Vec :: new ( ) ;
30
+ let mut content: Vec < ListItem < ' _ > > = Vec :: new ( ) ;
31
31
32
32
for item in self . items . iter ( ) {
33
33
match item. kind ( ) {
@@ -39,20 +39,58 @@ impl StatefulWidget for &mut TimelineView<'_> {
39
39
kind : MsgLikeKind :: Message ( message) ,
40
40
..
41
41
} ) => {
42
+ if ev. content ( ) . thread_root ( ) . is_some ( ) {
43
+ continue ;
44
+ }
45
+
42
46
if let MessageType :: Text ( text) = message. msgtype ( ) {
43
- content. push ( format ! ( "{}: {}" , sender, text. body) )
47
+ let mut lines = Vec :: new ( ) ;
48
+ let first_line = Line :: from ( format ! ( "{}: {}" , sender, text. body) ) ;
49
+
50
+ lines. push ( first_line) ;
51
+
52
+ if let Some ( thread_summary) = ev. content ( ) . thread_summary ( ) {
53
+ match thread_summary. latest_event {
54
+ TimelineDetails :: Unavailable => { }
55
+ TimelineDetails :: Pending => { }
56
+ TimelineDetails :: Ready ( e) => {
57
+ let sender = e. sender ;
58
+ let content =
59
+ e. content . as_message ( ) . map ( |m| m. msgtype ( ) ) ;
60
+
61
+ if let Some ( MessageType :: Text ( text) ) = content {
62
+ let replies = if thread_summary. num_replies == 1 {
63
+ "1 reply" . to_owned ( )
64
+ } else {
65
+ format ! ( "{} replies" , {
66
+ thread_summary. num_replies
67
+ } )
68
+ } ;
69
+ let thread_line = Line :: from ( format ! (
70
+ " 💬 {replies} {sender}: {}" ,
71
+ text. body
72
+ ) ) ;
73
+
74
+ lines. push ( thread_line) ;
75
+ }
76
+ }
77
+ TimelineDetails :: Error ( _) => { }
78
+ }
79
+ }
80
+
81
+ content. push ( ListItem :: from ( lines) ) ;
44
82
}
45
83
}
46
84
47
85
TimelineItemContent :: MsgLike ( MsgLikeContent {
48
86
kind : MsgLikeKind :: Redacted ,
49
87
..
50
- } ) => content. push ( format ! ( "{sender}: -- redacted --" ) ) ,
88
+ } ) => content. push ( format ! ( "{sender}: -- redacted --" ) . into ( ) ) ,
51
89
52
90
TimelineItemContent :: MsgLike ( MsgLikeContent {
53
91
kind : MsgLikeKind :: UnableToDecrypt ( _) ,
54
92
..
55
- } ) => content. push ( format ! ( "{sender}: (UTD)" ) ) ,
93
+ } ) => content. push ( format ! ( "{sender}: (UTD)" ) . into ( ) ) ,
56
94
57
95
TimelineItemContent :: MembershipChange ( m) => {
58
96
if let Some ( change) = m. change ( ) {
@@ -91,7 +129,7 @@ impl StatefulWidget for &mut TimelineView<'_> {
91
129
}
92
130
} ;
93
131
94
- content. push ( format ! ( "{display_name} {change}" ) ) ;
132
+ content. push ( format ! ( "{display_name} {change}" ) . into ( ) ) ;
95
133
}
96
134
}
97
135
@@ -116,13 +154,13 @@ impl StatefulWidget for &mut TimelineView<'_> {
116
154
117
155
TimelineItemKind :: Virtual ( virt) => match virt {
118
156
VirtualTimelineItem :: DateDivider ( unix_ts) => {
119
- content. push ( format ! ( "Date: {unix_ts:?}" ) ) ;
157
+ content. push ( format ! ( "Date: {unix_ts:?}" ) . into ( ) ) ;
120
158
}
121
159
VirtualTimelineItem :: ReadMarker => {
122
- content. push ( "Read marker" . to_owned ( ) ) ;
160
+ content. push ( "Read marker" . to_owned ( ) . into ( ) ) ;
123
161
}
124
162
VirtualTimelineItem :: TimelineStart => {
125
- content. push ( "🥳 Timeline start! 🥳" . to_owned ( ) ) ;
163
+ content. push ( "🥳 Timeline start! 🥳" . to_owned ( ) . into ( ) ) ;
126
164
}
127
165
} ,
128
166
}
@@ -136,8 +174,8 @@ impl StatefulWidget for &mut TimelineView<'_> {
136
174
0 => NORMAL_ROW_COLOR ,
137
175
_ => ALT_ROW_COLOR ,
138
176
} ;
139
- let line = Line :: styled ( line , TEXT_COLOR ) ;
140
- ListItem :: new ( line) . bg ( bg_color)
177
+
178
+ line. fg ( TEXT_COLOR ) . bg ( bg_color)
141
179
} )
142
180
. collect :: < Vec < _ > > ( ) ;
143
181
0 commit comments