Show state events in the timeline (#437)

This commit is contained in:
Ulyssa 2025-05-30 23:06:19 -07:00 committed by GitHub
parent 998e50f4a5
commit 84eaadc09a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 1145 additions and 79 deletions

View file

@ -47,6 +47,7 @@ use matrix_sdk::{
},
room::redaction::{OriginalSyncRoomRedactionEvent, SyncRoomRedactionEvent},
tag::{TagName, Tags},
AnySyncStateEvent,
MessageLikeEvent,
},
presence::PresenceState,
@ -836,6 +837,9 @@ pub enum EventLocation {
/// The [EventId] belongs to a reaction to the given event.
Reaction(OwnedEventId),
/// The [EventId] belongs to a state event in the main timeline of the room.
State(MessageKey),
}
impl EventLocation {
@ -1003,6 +1007,12 @@ impl RoomInfo {
match self.keys.get(redacts) {
None => return,
Some(EventLocation::State(key)) => {
if let Some(msg) = self.messages.get_mut(key) {
let ev = SyncRoomRedactionEvent::Original(ev);
msg.redact(ev, room_version);
}
},
Some(EventLocation::Message(None, key)) => {
if let Some(msg) = self.messages.get_mut(key) {
let ev = SyncRoomRedactionEvent::Original(ev);
@ -1076,6 +1086,7 @@ impl RoomInfo {
content.apply_replacement(new_msgtype);
},
MessageEvent::Redacted(_) |
MessageEvent::State(_) |
MessageEvent::EncryptedOriginal(_) |
MessageEvent::EncryptedRedacted(_) => {
return;
@ -1085,6 +1096,15 @@ impl RoomInfo {
msg.html = msg.event.html();
}
pub fn insert_any_state(&mut self, msg: AnySyncStateEvent) {
let event_id = msg.event_id().to_owned();
let key = (msg.origin_server_ts().into(), event_id.clone());
let loc = EventLocation::State(key.clone());
self.keys.insert(event_id, loc);
self.messages.insert_message(key, msg);
}
/// Indicates whether this room has unread messages.
pub fn unreads(&self, settings: &ApplicationSettings) -> UnreadInfo {
let last_message = self.messages.last_key_value();