Support sending and displaying read markers (#11)

This commit is contained in:
Ulyssa 2023-01-26 15:40:16 -08:00
parent d8713141f2
commit afe892c7fe
No known key found for this signature in database
GPG key ID: 1B3965A3D18B9B64
7 changed files with 270 additions and 94 deletions

View file

@ -241,7 +241,7 @@ impl ChatState {
let ev = match &msg.event {
MessageEvent::Original(ev) => &ev.content,
MessageEvent::Local(ev) => ev.deref(),
MessageEvent::Local(_, ev) => ev.deref(),
_ => {
let msg = "Cannot edit a redacted message";
let err = UIError::Failure(msg.into());
@ -275,9 +275,7 @@ impl ChatState {
let event_id = match &msg.event {
MessageEvent::Original(ev) => ev.event_id.clone(),
MessageEvent::Local(_) => {
self.scrollback.get_key(info).ok_or(IambError::NoSelectedMessage)?.1
},
MessageEvent::Local(event_id, _) => event_id.clone(),
MessageEvent::Redacted(_) => {
let msg = "";
let err = UIError::Failure(msg.into());
@ -378,8 +376,8 @@ impl ChatState {
if show_echo {
let user = store.application.settings.profile.user_id.clone();
let key = (MessageTimeStamp::LocalEcho, event_id);
let msg = MessageEvent::Local(msg.into());
let key = (MessageTimeStamp::LocalEcho, event_id.clone());
let msg = MessageEvent::Local(event_id, msg.into());
let msg = Message::new(msg, user, MessageTimeStamp::LocalEcho);
info.messages.insert(key, msg);
}
@ -415,7 +413,7 @@ impl ChatState {
return;
}
if !store.application.settings.tunables.typing_notice {
if !store.application.settings.tunables.typing_notice_send {
return;
}

View file

@ -1260,7 +1260,13 @@ impl<'a> StatefulWidget for Scrollback<'a> {
y += 1;
}
let first_key = info.messages.first_key_value().map(|f| f.0.clone());
if settings.tunables.read_receipt_send && state.cursor.timestamp.is_none() {
// If the cursor is at the last message, then update the read marker.
info.read_till = info.messages.last_key_value().map(|(k, _)| k.1.clone());
}
// Check whether we should load older messages for this room.
let first_key = info.messages.first_key_value().map(|(k, _)| k.clone());
if first_key == state.viewctx.corner.timestamp {
// If the top of the screen is the older message, load more.
self.store.application.mark_for_load(state.room_id.clone());