Commit afe892c7fe

afe892c7feb34566d56437e0778b8964c21867c8

parent: d8713141f2

Unregistered key

Ulyssa <git@ulyssa.dev> · 2023-01-26 23:40 UTC

Support sending and displaying read markers (#11)

Layout: unified · split

src/base.rs +28 −3
@@ -214,6 +214,8 @@ pub type AsyncProgramStore = Arc<AsyncMutex<ProgramStore>>;
214214
215215pub type IambResult<T> = UIResult<T, IambInfo>;
216216
217pub type Receipts = HashMap<OwnedEventId, Vec<OwnedUserId>>;
218
217219#[derive(thiserror::Error, Debug)]
218220pub enum IambError {
219221 #[error("Invalid user identifier: {0}")]
@@ -286,6 +288,9 @@ pub struct RoomInfo {
286288 pub keys: HashMap<OwnedEventId, MessageKey>,
287289 pub messages: Messages,
288290
291 pub receipts: HashMap<OwnedEventId, Vec<OwnedUserId>>,
292 pub read_till: Option<OwnedEventId>,
293
289294 pub fetch_id: RoomFetchStatus,
290295 pub fetch_last: Option<Instant>,
291296 pub users_typing: Option<(Instant, Vec<OwnedUserId>)>,
@@ -316,7 +321,7 @@ impl RoomInfo {
316321 MessageEvent::Original(orig) => {
317322 orig.content = *new_content;
318323 },
319 MessageEvent::Local(content) => {
324 MessageEvent::Local(_, content) => {
320325 *content = new_content;
321326 },
322327 MessageEvent::Redacted(_) => {
@@ -364,7 +369,7 @@ impl RoomInfo {
364369 }
365370 }
366371
367 fn get_typing_spans(&self, settings: &ApplicationSettings) -> Spans {
372 fn get_typing_spans<'a>(&'a self, settings: &'a ApplicationSettings) -> Spans<'a> {
368373 let typers = self.get_typers();
369374 let n = typers.len();
370375
@@ -454,6 +459,26 @@ impl ChatStore {
454459 .unwrap_or_else(|| "Untitled Matrix Room".to_string())
455460 }
456461
462 pub async fn set_receipts(&mut self, receipts: Vec<(OwnedRoomId, Receipts)>) {
463 let mut updates = vec![];
464
465 for (room_id, receipts) in receipts.into_iter() {
466 if let Some(info) = self.rooms.get_mut(&room_id) {
467 info.receipts = receipts;
468
469 if let Some(read_till) = info.read_till.take() {
470 updates.push((room_id, read_till));
471 }
472 }
473 }
474
475 for (room_id, read_till) in updates.into_iter() {
476 if let Some(room) = self.worker.client.get_joined_room(&room_id) {
477 let _ = room.read_receipt(read_till.as_ref()).await;
478 }
479 }
480 }
481
457482 pub fn mark_for_load(&mut self, room_id: OwnedRoomId) {
458483 self.need_load.insert(room_id);
459484 }
@@ -588,7 +613,7 @@ impl ApplicationInfo for IambInfo {
588613#[cfg(test)]
589614pub mod tests {
590615 use super::*;
591 use crate::config::{user_style, user_style_from_color};
616 use crate::config::user_style_from_color;
592617 use crate::tests::*;
593618 use modalkit::tui::style::Color;
594619
src/config.rs +55 −33
@@ -1,3 +1,4 @@
1use std::borrow::Cow;
12use std::collections::hash_map::DefaultHasher;
23use std::collections::HashMap;
34use std::fmt;
@@ -52,10 +53,6 @@ pub fn user_style_from_color(color: Color) -> Style {
5253 Style::default().fg(color).add_modifier(StyleModifier::BOLD)
5354}
5455
55pub fn user_style(user: &str) -> Style {
56 user_style_from_color(user_color(user))
57}
58
5956fn is_profile_char(c: char) -> bool {
6057 c.is_ascii_alphanumeric() || c == '.' || c == '-'
6158}
@@ -181,14 +178,18 @@ fn merge_users(a: Option<UserOverrides>, b: Option<UserOverrides>) -> Option<Use
181178
182179#[derive(Clone)]
183180pub struct TunableValues {
184 pub typing_notice: bool,
181 pub read_receipt_send: bool,
182 pub read_receipt_display: bool,
183 pub typing_notice_send: bool,
185184 pub typing_notice_display: bool,
186185 pub users: UserOverrides,
187186}
188187
189188#[derive(Clone, Default, Deserialize)]
190189pub struct Tunables {
191 pub typing_notice: Option<bool>,
190 pub read_receipt_send: Option<bool>,
191 pub read_receipt_display: Option<bool>,
192 pub typing_notice_send: Option<bool>,
192193 pub typing_notice_display: Option<bool>,
193194 pub users: Option<UserOverrides>,
194195}
@@ -196,7 +197,9 @@ pub struct Tunables {
196197impl Tunables {
197198 fn merge(self, other: Self) -> Self {
198199 Tunables {
199 typing_notice: self.typing_notice.or(other.typing_notice),
200 read_receipt_send: self.read_receipt_send.or(other.read_receipt_send),
201 read_receipt_display: self.read_receipt_display.or(other.read_receipt_display),
202 typing_notice_send: self.typing_notice_send.or(other.typing_notice_send),
200203 typing_notice_display: self.typing_notice_display.or(other.typing_notice_display),
201204 users: merge_users(self.users, other.users),
202205 }
@@ -204,8 +207,10 @@ impl Tunables {
204207
205208 fn values(self) -> TunableValues {
206209 TunableValues {
207 typing_notice: self.typing_notice.unwrap_or(true),
208 typing_notice_display: self.typing_notice.unwrap_or(true),
210 read_receipt_send: self.read_receipt_send.unwrap_or(true),
211 read_receipt_display: self.read_receipt_display.unwrap_or(true),
212 typing_notice_send: self.typing_notice_send.unwrap_or(true),
213 typing_notice_display: self.typing_notice_display.unwrap_or(true),
209214 users: self.users.unwrap_or_default(),
210215 }
211216 }
@@ -374,24 +379,41 @@ impl ApplicationSettings {
374379 Ok(settings)
375380 }
376381
382 pub fn get_user_char_span<'a>(&self, user_id: &'a UserId) -> Span<'a> {
383 let (color, c) = self
384 .tunables
385 .users
386 .get(user_id)
387 .map(|user| {
388 (
389 user.color.as_ref().map(|c| c.0),
390 user.name.as_ref().and_then(|s| s.chars().next()),
391 )
392 })
393 .unwrap_or_default();
394
395 let color = color.unwrap_or_else(|| user_color(user_id.as_str()));
396 let style = user_style_from_color(color);
397
398 let c = c.unwrap_or_else(|| user_id.localpart().chars().next().unwrap_or(' '));
399
400 Span::styled(String::from(c), style)
401 }
402
377403 pub fn get_user_span<'a>(&self, user_id: &'a UserId) -> Span<'a> {
378 if let Some(user) = self.tunables.users.get(user_id) {
379 let color = if let Some(UserColor(c)) = user.color {
380 c
381 } else {
382 user_color(user_id.as_str())
383 };
384
385 let style = user_style_from_color(color);
386
387 if let Some(name) = &user.name {
388 Span::styled(name.clone(), style)
389 } else {
390 Span::styled(user_id.as_str(), style)
391 }
392 } else {
393 Span::styled(user_id.as_str(), user_style(user_id.as_str()))
394 }
404 let (color, name) = self
405 .tunables
406 .users
407 .get(user_id)
408 .map(|user| (user.color.as_ref().map(|c| c.0), user.name.clone().map(Cow::Owned)))
409 .unwrap_or_default();
410
411 let user_id = user_id.as_str();
412 let color = color.unwrap_or_else(|| user_color(user_id));
413 let style = user_style_from_color(color);
414 let name = name.unwrap_or(Cow::Borrowed(user_id));
415
416 Span::styled(name, style)
395417 }
396418}
397419
@@ -461,22 +483,22 @@ mod tests {
461483 #[test]
462484 fn test_parse_tunables() {
463485 let res: Tunables = serde_json::from_str("{}").unwrap();
464 assert_eq!(res.typing_notice, None);
486 assert_eq!(res.typing_notice_send, None);
465487 assert_eq!(res.typing_notice_display, None);
466488 assert_eq!(res.users, None);
467489
468 let res: Tunables = serde_json::from_str("{\"typing_notice\": true}").unwrap();
469 assert_eq!(res.typing_notice, Some(true));
490 let res: Tunables = serde_json::from_str("{\"typing_notice_send\": true}").unwrap();
491 assert_eq!(res.typing_notice_send, Some(true));
470492 assert_eq!(res.typing_notice_display, None);
471493 assert_eq!(res.users, None);
472494
473 let res: Tunables = serde_json::from_str("{\"typing_notice\": false}").unwrap();
474 assert_eq!(res.typing_notice, Some(false));
495 let res: Tunables = serde_json::from_str("{\"typing_notice_send\": false}").unwrap();
496 assert_eq!(res.typing_notice_send, Some(false));
475497 assert_eq!(res.typing_notice_display, None);
476498 assert_eq!(res.users, None);
477499
478500 let res: Tunables = serde_json::from_str("{\"users\": {}}").unwrap();
479 assert_eq!(res.typing_notice, None);
501 assert_eq!(res.typing_notice_send, None);
480502 assert_eq!(res.typing_notice_display, None);
481503 assert_eq!(res.users, Some(HashMap::new()));
482504
@@ -484,7 +506,7 @@ mod tests {
484506 "{\"users\": {\"@a:b.c\": {\"color\": \"black\", \"name\": \"Tim\"}}}",
485507 )
486508 .unwrap();
487 assert_eq!(res.typing_notice, None);
509 assert_eq!(res.typing_notice_send, None);
488510 assert_eq!(res.typing_notice_display, None);
489511 let users = vec![(user_id!("@a:b.c").to_owned(), UserDisplayTunables {
490512 color: Some(UserColor(Color::Black)),
src/message/mod.rs +123 −45
@@ -4,6 +4,7 @@ use std::collections::hash_map::DefaultHasher;
44use std::collections::BTreeMap;
55use std::convert::TryFrom;
66use std::hash::{Hash, Hasher};
7use std::slice::Iter;
78
89use chrono::{DateTime, NaiveDateTime, Utc};
910use unicode_width::UnicodeWidthStr;
@@ -25,6 +26,7 @@ use matrix_sdk::ruma::{
2526 },
2627 Redact,
2728 },
29 EventId,
2830 MilliSecondsSinceUnixEpoch,
2931 OwnedEventId,
3032 OwnedUserId,
@@ -54,20 +56,28 @@ pub type MessageFetchResult = IambResult<(Option<String>, Vec<RoomMessageEvent>)
5456pub type MessageKey = (MessageTimeStamp, OwnedEventId);
5557pub type Messages = BTreeMap<MessageKey, Message>;
5658
59const fn span_static(s: &'static str) -> Span<'static> {
60 Span {
61 content: Cow::Borrowed(s),
62 style: Style {
63 fg: None,
64 bg: None,
65 add_modifier: StyleModifier::empty(),
66 sub_modifier: StyleModifier::empty(),
67 },
68 }
69}
70
5771const USER_GUTTER: usize = 30;
5872const TIME_GUTTER: usize = 12;
73const READ_GUTTER: usize = 5;
5974const MIN_MSG_LEN: usize = 30;
6075
6176const USER_GUTTER_EMPTY: &str = " ";
62const USER_GUTTER_EMPTY_SPAN: Span<'static> = Span {
63 content: Cow::Borrowed(USER_GUTTER_EMPTY),
64 style: Style {
65 fg: None,
66 bg: None,
67 add_modifier: StyleModifier::empty(),
68 sub_modifier: StyleModifier::empty(),
69 },
70};
77const USER_GUTTER_EMPTY_SPAN: Span<'static> = span_static(USER_GUTTER_EMPTY);
78
79const TIME_GUTTER_EMPTY: &str = " ";
80const TIME_GUTTER_EMPTY_SPAN: Span<'static> = span_static(TIME_GUTTER_EMPTY);
7181
7282#[derive(thiserror::Error, Debug)]
7383pub enum TimeStampIntError {
@@ -271,10 +281,18 @@ impl PartialOrd for MessageCursor {
271281pub enum MessageEvent {
272282 Original(Box<OriginalRoomMessageEvent>),
273283 Redacted(Box<RedactedRoomMessageEvent>),
274 Local(Box<RoomMessageEventContent>),
284 Local(OwnedEventId, Box<RoomMessageEventContent>),
275285}
276286
277287impl MessageEvent {
288 pub fn event_id(&self) -> &EventId {
289 match self {
290 MessageEvent::Original(ev) => ev.event_id.as_ref(),
291 MessageEvent::Redacted(ev) => ev.event_id.as_ref(),
292 MessageEvent::Local(event_id, _) => event_id.as_ref(),
293 }
294 }
295
278296 pub fn body(&self) -> Cow<'_, str> {
279297 match self {
280298 MessageEvent::Original(ev) => body_cow_content(&ev.content),
@@ -292,7 +310,7 @@ impl MessageEvent {
292310 Cow::Borrowed("[Redacted]")
293311 }
294312 },
295 MessageEvent::Local(content) => body_cow_content(content),
313 MessageEvent::Local(_, content) => body_cow_content(content),
296314 }
297315 }
298316
@@ -300,7 +318,7 @@ impl MessageEvent {
300318 let content = match self {
301319 MessageEvent::Original(ev) => &ev.content,
302320 MessageEvent::Redacted(_) => return None,
303 MessageEvent::Local(content) => content,
321 MessageEvent::Local(_, content) => content,
304322 };
305323
306324 if let MessageType::Text(content) = &content.msgtype {
@@ -317,7 +335,7 @@ impl MessageEvent {
317335 pub fn redact(&mut self, redaction: SyncRoomRedactionEvent, version: &RoomVersionId) {
318336 match self {
319337 MessageEvent::Redacted(_) => return,
320 MessageEvent::Local(_) => return,
338 MessageEvent::Local(_, _) => return,
321339 MessageEvent::Original(ev) => {
322340 let redacted = ev.clone().redact(redaction, version);
323341 *self = MessageEvent::Redacted(Box::new(redacted));
@@ -354,27 +372,65 @@ fn body_cow_content(content: &RoomMessageEventContent) -> Cow<'_, str> {
354372 Cow::Borrowed(s)
355373}
356374
357enum MessageColumns<'a> {
358 Three(usize, Option<Span<'a>>, Option<Span<'a>>),
359 Two(usize, Option<Span<'a>>),
360 One(usize, Option<Span<'a>>),
375enum MessageColumns {
376 /// Four columns: sender, message, timestamp, read receipts.
377 Four,
378
379 /// Three columns: sender, message, timestamp.
380 Three,
381
382 /// Two columns: sender, message.
383 Two,
384
385 /// One column: message with sender on line before the message.
386 One,
361387}
362388
363impl<'a> MessageColumns<'a> {
389struct MessageFormatter<'a> {
390 settings: &'a ApplicationSettings,
391 cols: MessageColumns,
392 fill: usize,
393 user: Option<Span<'a>>,
394 time: Option<Span<'a>>,
395 read: Iter<'a, OwnedUserId>,
396}
397
398impl<'a> MessageFormatter<'a> {
364399 fn width(&self) -> usize {
365 match self {
366 MessageColumns::Three(fill, _, _) => *fill,
367 MessageColumns::Two(fill, _) => *fill,
368 MessageColumns::One(fill, _) => *fill,
369 }
400 self.fill
370401 }
371402
372403 #[inline]
373404 fn push_spans(&mut self, spans: Spans<'a>, style: Style, text: &mut Text<'a>) {
374 match self {
375 MessageColumns::Three(_, user, time) => {
376 let user = user.take().unwrap_or(USER_GUTTER_EMPTY_SPAN);
377 let time = time.take().unwrap_or_else(|| Span::from(""));
405 match self.cols {
406 MessageColumns::Four => {
407 let settings = self.settings;
408 let user = self.user.take().unwrap_or(USER_GUTTER_EMPTY_SPAN);
409 let time = self.time.take().unwrap_or(TIME_GUTTER_EMPTY_SPAN);
410
411 let mut line = vec![user];
412 line.extend(spans.0);
413 line.push(time);
414
415 // Show read receipts.
416 let user_char =
417 |user: &'a OwnedUserId| -> Span<'a> { settings.get_user_char_span(user) };
418
419 let a = self.read.next().map(user_char).unwrap_or_else(|| Span::raw(" "));
420 let b = self.read.next().map(user_char).unwrap_or_else(|| Span::raw(" "));
421 let c = self.read.next().map(user_char).unwrap_or_else(|| Span::raw(" "));
422
423 line.push(Span::raw(" "));
424 line.push(c);
425 line.push(b);
426 line.push(a);
427 line.push(Span::raw(" "));
428
429 text.lines.push(Spans(line))
430 },
431 MessageColumns::Three => {
432 let user = self.user.take().unwrap_or(USER_GUTTER_EMPTY_SPAN);
433 let time = self.time.take().unwrap_or_else(|| Span::from(""));
378434
379435 let mut line = vec![user];
380436 line.extend(spans.0);
@@ -382,15 +438,15 @@ impl<'a> MessageColumns<'a> {
382438
383439 text.lines.push(Spans(line))
384440 },
385 MessageColumns::Two(_, opt) => {
386 let user = opt.take().unwrap_or(USER_GUTTER_EMPTY_SPAN);
441 MessageColumns::Two => {
442 let user = self.user.take().unwrap_or(USER_GUTTER_EMPTY_SPAN);
387443 let mut line = vec![user];
388444 line.extend(spans.0);
389445
390446 text.lines.push(Spans(line));
391447 },
392 MessageColumns::One(_, opt) => {
393 if let Some(user) = opt.take() {
448 MessageColumns::One => {
449 if let Some(user) = self.user.take() {
394450 text.lines.push(Spans(vec![user]));
395451 }
396452
@@ -428,7 +484,7 @@ impl Message {
428484
429485 pub fn reply_to(&self) -> Option<OwnedEventId> {
430486 let content = match &self.event {
431 MessageEvent::Local(content) => content,
487 MessageEvent::Local(_, content) => content,
432488 MessageEvent::Original(ev) => &ev.content,
433489 MessageEvent::Redacted(_) => return None,
434490 };
@@ -454,28 +510,50 @@ impl Message {
454510 return style;
455511 }
456512
457 fn get_render_format(
458 &self,
513 fn get_render_format<'a>(
514 &'a self,
459515 prev: Option<&Message>,
460516 width: usize,
461 settings: &ApplicationSettings,
462 ) -> MessageColumns {
463 if USER_GUTTER + TIME_GUTTER + MIN_MSG_LEN <= width {
464 let lw = width - USER_GUTTER - TIME_GUTTER;
517 info: &'a RoomInfo,
518 settings: &'a ApplicationSettings,
519 ) -> MessageFormatter<'a> {
520 if USER_GUTTER + TIME_GUTTER + READ_GUTTER + MIN_MSG_LEN <= width &&
521 settings.tunables.read_receipt_display
522 {
523 let cols = MessageColumns::Four;
524 let fill = width - USER_GUTTER - TIME_GUTTER - READ_GUTTER;
525 let user = self.show_sender(prev, true, settings);
526 let time = self.timestamp.show();
527 let read = match info.receipts.get(self.event.event_id()) {
528 Some(read) => read.iter(),
529 None => [].iter(),
530 };
531
532 MessageFormatter { settings, cols, fill, user, time, read }
533 } else if USER_GUTTER + TIME_GUTTER + MIN_MSG_LEN <= width {
534 let cols = MessageColumns::Three;
535 let fill = width - USER_GUTTER - TIME_GUTTER;
465536 let user = self.show_sender(prev, true, settings);
466537 let time = self.timestamp.show();
538 let read = [].iter();
467539
468 MessageColumns::Three(lw, user, time)
540 MessageFormatter { settings, cols, fill, user, time, read }
469541 } else if USER_GUTTER + MIN_MSG_LEN <= width {
470 let lw = width - USER_GUTTER;
542 let cols = MessageColumns::Two;
543 let fill = width - USER_GUTTER;
471544 let user = self.show_sender(prev, true, settings);
545 let time = None;
546 let read = [].iter();
472547
473 MessageColumns::Two(lw, user)
548 MessageFormatter { settings, cols, fill, user, time, read }
474549 } else {
475 let lw = width.saturating_sub(2);
550 let cols = MessageColumns::One;
551 let fill = width.saturating_sub(2);
476552 let user = self.show_sender(prev, false, settings);
553 let time = None;
554 let read = [].iter();
477555
478 MessageColumns::One(lw, user)
556 MessageFormatter { settings, cols, fill, user, time, read }
479557 }
480558 }
481559
@@ -485,12 +563,12 @@ impl Message {
485563 selected: bool,
486564 vwctx: &ViewportContext<MessageCursor>,
487565 info: &'a RoomInfo,
488 settings: &ApplicationSettings,
566 settings: &'a ApplicationSettings,
489567 ) -> Text<'a> {
490568 let width = vwctx.get_width();
491569
492570 let style = self.get_render_style(selected);
493 let mut fmt = self.get_render_format(prev, width, settings);
571 let mut fmt = self.get_render_format(prev, width, info, settings);
494572 let mut text = Text { lines: vec![] };
495573 let width = fmt.width();
496574
src/tests.rs +15 −4
@@ -15,13 +15,15 @@ use matrix_sdk::ruma::{
1515};
1616
1717use lazy_static::lazy_static;
18use modalkit::tui::style::Color;
18use modalkit::tui::style::{Color, Style};
1919use tokio::sync::mpsc::unbounded_channel;
2020use url::Url;
2121
2222use crate::{
2323 base::{ChatStore, ProgramStore, RoomFetchStatus, RoomInfo},
2424 config::{
25 user_color,
26 user_style_from_color,
2527 ApplicationSettings,
2628 DirectoryValues,
2729 ProfileConfig,
@@ -60,6 +62,10 @@ lazy_static! {
6062 pub static ref MSG5_KEY: MessageKey = (OriginServer(UInt::new(8).unwrap()), MSG5_EVID.clone());
6163}
6264
65pub fn user_style(user: &str) -> Style {
66 user_style_from_color(user_color(user))
67}
68
6369pub fn mock_room1_message(
6470 content: RoomMessageEventContent,
6571 sender: OwnedUserId,
@@ -82,7 +88,7 @@ pub fn mock_room1_message(
8288
8389pub fn mock_message1() -> Message {
8490 let content = RoomMessageEventContent::text_plain("writhe");
85 let content = MessageEvent::Local(content.into());
91 let content = MessageEvent::Local(MSG1_EVID.clone(), content.into());
8692
8793 Message::new(content, TEST_USER1.clone(), MSG1_KEY.0)
8894}
@@ -138,10 +144,13 @@ pub fn mock_messages() -> Messages {
138144pub fn mock_room() -> RoomInfo {
139145 RoomInfo {
140146 name: Some("Watercooler Discussion".into()),
147 tags: None,
141148
142149 keys: mock_keys(),
143150 messages: mock_messages(),
144 tags: None,
151
152 receipts: HashMap::new(),
153 read_till: None,
145154
146155 fetch_id: RoomFetchStatus::NotStarted,
147156 fetch_last: None,
@@ -159,7 +168,9 @@ pub fn mock_dirs() -> DirectoryValues {
159168
160169pub fn mock_tunables() -> TunableValues {
161170 TunableValues {
162 typing_notice: true,
171 read_receipt_send: true,
172 read_receipt_display: true,
173 typing_notice_send: true,
163174 typing_notice_display: true,
164175 users: vec![(TEST_USER5.clone(), UserDisplayTunables {
165176 color: Some(UserColor(Color::Black)),
src/windows/room/chat.rs +5 −7
@@ -241,7 +241,7 @@ impl ChatState {
241241
242242 let ev = match &msg.event {
243243 MessageEvent::Original(ev) => &ev.content,
244 MessageEvent::Local(ev) => ev.deref(),
244 MessageEvent::Local(_, ev) => ev.deref(),
245245 _ => {
246246 let msg = "Cannot edit a redacted message";
247247 let err = UIError::Failure(msg.into());
@@ -275,9 +275,7 @@ impl ChatState {
275275
276276 let event_id = match &msg.event {
277277 MessageEvent::Original(ev) => ev.event_id.clone(),
278 MessageEvent::Local(_) => {
279 self.scrollback.get_key(info).ok_or(IambError::NoSelectedMessage)?.1
280 },
278 MessageEvent::Local(event_id, _) => event_id.clone(),
281279 MessageEvent::Redacted(_) => {
282280 let msg = "";
283281 let err = UIError::Failure(msg.into());
@@ -378,8 +376,8 @@ impl ChatState {
378376
379377 if show_echo {
380378 let user = store.application.settings.profile.user_id.clone();
381 let key = (MessageTimeStamp::LocalEcho, event_id);
382 let msg = MessageEvent::Local(msg.into());
379 let key = (MessageTimeStamp::LocalEcho, event_id.clone());
380 let msg = MessageEvent::Local(event_id, msg.into());
383381 let msg = Message::new(msg, user, MessageTimeStamp::LocalEcho);
384382 info.messages.insert(key, msg);
385383 }
@@ -415,7 +413,7 @@ impl ChatState {
415413 return;
416414 }
417415
418 if !store.application.settings.tunables.typing_notice {
416 if !store.application.settings.tunables.typing_notice_send {
419417 return;
420418 }
421419
src/windows/room/scrollback.rs +7 −1
@@ -1260,7 +1260,13 @@ impl<'a> StatefulWidget for Scrollback<'a> {
12601260 y += 1;
12611261 }
12621262
1263 let first_key = info.messages.first_key_value().map(|f| f.0.clone());
1263 if settings.tunables.read_receipt_send && state.cursor.timestamp.is_none() {
1264 // If the cursor is at the last message, then update the read marker.
1265 info.read_till = info.messages.last_key_value().map(|(k, _)| k.1.clone());
1266 }
1267
1268 // Check whether we should load older messages for this room.
1269 let first_key = info.messages.first_key_value().map(|(k, _)| k.clone());
12641270 if first_key == state.viewctx.corner.timestamp {
12651271 // If the top of the screen is the older message, load more.
12661272 self.store.application.mark_for_load(state.room_id.clone());
src/worker.rs +38 −2
@@ -57,7 +57,7 @@ use matrix_sdk::{
5757use modalkit::editing::action::{EditInfo, InfoMessage, UIError};
5858
5959use crate::{
60 base::{AsyncProgramStore, IambError, IambResult, VerifyAction},
60 base::{AsyncProgramStore, IambError, IambResult, Receipts, VerifyAction},
6161 message::MessageFetchResult,
6262 ApplicationSettings,
6363};
@@ -99,6 +99,29 @@ fn oneshot<T>() -> (ClientReply<T>, ClientResponse<T>) {
9999 return (reply, response);
100100}
101101
102async fn update_receipts(client: &Client) -> Vec<(OwnedRoomId, Receipts)> {
103 let mut rooms = vec![];
104
105 for room in client.joined_rooms() {
106 if let Ok(users) = room.active_members_no_sync().await {
107 let mut receipts = Receipts::new();
108
109 for member in users {
110 let res = room.user_read_receipt(member.user_id()).await;
111
112 if let Ok(Some((event_id, _))) = res {
113 let user_id = member.user_id().to_owned();
114 receipts.entry(event_id).or_default().push(user_id);
115 }
116 }
117
118 rooms.push((room.room_id().to_owned(), receipts));
119 }
120 }
121
122 return rooms;
123}
124
102125pub type FetchedRoom = (MatrixRoom, DisplayName, Option<Tags>);
103126
104127pub enum WorkerTask {
@@ -454,7 +477,7 @@ impl ClientWorker {
454477 }
455478
456479 async fn init(&mut self, store: AsyncProgramStore) {
457 self.client.add_event_handler_context(store);
480 self.client.add_event_handler_context(store.clone());
458481
459482 let _ = self.client.add_event_handler(
460483 |ev: SyncTypingEvent, room: MatrixRoom, store: Ctx<AsyncProgramStore>| {
@@ -661,6 +684,19 @@ impl ClientWorker {
661684 },
662685 );
663686
687 let client = self.client.clone();
688 let _ = tokio::spawn(async move {
689 // Update the displayed read receipts ever 5 seconds.
690 let mut interval = tokio::time::interval(Duration::from_secs(5));
691
692 loop {
693 interval.tick().await;
694
695 let receipts = update_receipts(&client).await;
696 store.lock().await.application.set_receipts(receipts).await;
697 }
698 });
699
664700 self.initialized = true;
665701 }
666702