1fe480c16a3c | atagen | 2026-09-26 08:44 UTC | 1 | use std::{collections::HashSet, future::Future, panic::AssertUnwindSafe, sync::Arc}; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 2 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 3 | use futures_util::{FutureExt, StreamExt}; |
1fe480c16a3c | atagen | 2026-09-26 08:44 UTC | 4 | use matrix_sdk::SendOutsideWasm; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 5 | use matrix_sdk::{ |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 6 | room::edit::EditedContent, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 7 | room::reply::{EnforceThread, Reply as SdkReply}, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 8 | ruma::{ |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 9 | api::client::receipt::create_receipt::v3::ReceiptType, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 10 | events::{ |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 11 | Mentions, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 12 | room::message::{ |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 13 | AddMentions, Relation, ReplyWithinThread, RoomMessageEventContentWithoutRelation, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 14 | }, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 15 | }, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 16 | }, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 17 | }; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 18 | use matrix_sdk_ui::timeline::{Timeline, TimelineEventItemId}; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 19 | use ruma::{OwnedEventId, OwnedUserId}; |
1fe480c16a3c | atagen | 2026-09-26 08:44 UTC | 20 | use tokio::sync::mpsc; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 21 | |
1fe480c16a3c | atagen | 2026-09-26 08:44 UTC | 22 | use super::executor::{EngineBoxFuture, JoinHandle, TaskSet, spawn}; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 23 | use crate::{ |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 24 | Error, ErrorKind, Event, EventRef, HistoryState, MessageContent, MessageEditContent, |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 25 | MessageMentions, RichText, TimelineCommand, TimelineId, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 26 | engine::MediaService, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 27 | normalise::{MediaScope, normalise_timeline, normalise_timeline_diffs}, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 28 | transport::{EventSender, Responder, SendEventError}, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 29 | }; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 30 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 31 | const PAGINATION_QUEUE: usize = 32; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 32 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 33 | /// long-lived tasks inside a room actor report panics here so the actor can die loudly |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 34 | #[derive(Clone)] |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 35 | pub(super) struct Supervisor(mpsc::UnboundedSender<&'static str>); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 36 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 37 | impl Supervisor { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 38 | pub(super) fn new() -> (Self, mpsc::UnboundedReceiver<&'static str>) { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 39 | let (sender, receiver) = mpsc::unbounded_channel(); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 40 | (Self(sender), receiver) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 41 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 42 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 43 | pub(super) fn spawn( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 44 | &self, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 45 | label: &'static str, |
1fe480c16a3c | atagen | 2026-09-26 08:44 UTC | 46 | task: impl Future<Output = ()> + SendOutsideWasm + 'static, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 47 | ) -> JoinHandle<()> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 48 | let panics = self.0.clone(); |
1fe480c16a3c | atagen | 2026-09-26 08:44 UTC | 49 | spawn(async move { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 50 | if AssertUnwindSafe(task).catch_unwind().await.is_err() { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 51 | let _ = panics.send(label); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 52 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 53 | }) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 54 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 55 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 56 | |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 57 | /// aborts its task when dropped, so an actor that dies mid-flight takes its helpers with it |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 58 | pub(super) struct TaskGuard(pub(super) JoinHandle<()>); |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 59 | |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 60 | impl Drop for TaskGuard { |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 61 | fn drop(&mut self) { |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 62 | self.0.abort(); |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 63 | } |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 64 | } |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 65 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 66 | /// what a timeline session needs from the room that owns it |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 67 | #[derive(Clone)] |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 68 | pub(super) struct SessionContext { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 69 | pub(super) events: EventSender, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 70 | pub(super) media: Arc<MediaService>, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 71 | pub(super) current_user_id: Option<OwnedUserId>, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 72 | pub(super) initial_history_limit: u16, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 73 | pub(super) supervisor: Supervisor, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 74 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 75 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 76 | pub(super) struct TimelineSession { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 77 | pub(super) id: TimelineId, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 78 | timeline: Arc<Timeline>, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 79 | context: SessionContext, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 80 | scope: MediaScope, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 81 | watcher: JoinHandle<()>, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 82 | pagination: mpsc::Sender<PaginationRequest>, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 83 | pagination_worker: JoinHandle<()>, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 84 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 85 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 86 | struct PaginationRequest { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 87 | limit: u16, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 88 | reply: Option<Responder>, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 89 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 90 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 91 | impl TimelineSession { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 92 | pub(super) async fn start( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 93 | id: TimelineId, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 94 | timeline: Timeline, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 95 | context: SessionContext, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 96 | ) -> Result<Self, SendEventError> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 97 | let timeline = Arc::new(timeline); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 98 | let scope = MediaScope::new(); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 99 | let watcher = start_watcher(&id, &timeline, &context, &scope).await?; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 100 | let (pagination, requests) = mpsc::channel(PAGINATION_QUEUE); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 101 | let pagination_worker = context.supervisor.spawn( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 102 | "pagination worker", |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 103 | run_pagination( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 104 | requests, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 105 | timeline.clone(), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 106 | context.events.clone(), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 107 | id.clone(), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 108 | ), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 109 | ); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 110 | let session = Self { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 111 | id, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 112 | timeline, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 113 | scope, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 114 | watcher, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 115 | pagination, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 116 | pagination_worker, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 117 | context, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 118 | }; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 119 | if session.context.initial_history_limit > 0 { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 120 | session.paginate(session.context.initial_history_limit, None); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 121 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 122 | Ok(session) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 123 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 124 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 125 | /// swaps in a fresh watcher. the old one is dead before the reset goes out, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 126 | /// so no stale diff can land after it |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 127 | pub(super) async fn resync(&mut self) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 128 | self.watcher.abort(); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 129 | let _ = (&mut self.watcher).await; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 130 | self.watcher = start_watcher(&self.id, &self.timeline, &self.context, &self.scope) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 131 | .await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 132 | .map_err(|_| Error::new(ErrorKind::Timeline, "timeline reset could not be sent"))?; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 133 | Ok(()) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 134 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 135 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 136 | pub(super) fn paginate(&self, limit: u16, reply: Option<Responder>) { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 137 | if let Err(error) = self.pagination.try_send(PaginationRequest { limit, reply }) { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 138 | let (request, error) = match error { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 139 | mpsc::error::TrySendError::Full(request) => ( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 140 | request, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 141 | Error::new(ErrorKind::QueueFull, "pagination queue is full"), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 142 | ), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 143 | mpsc::error::TrySendError::Closed(request) => ( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 144 | request, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 145 | Error::new(ErrorKind::TimelineNotOpen, "timeline is closing"), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 146 | ), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 147 | }; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 148 | if let Some(reply) = request.reply { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 149 | reply.done(Err(error)); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 150 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 151 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 152 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 153 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 154 | /// pending paginations answer `Interrupted` as their responders drop |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 155 | pub(super) async fn close(mut self) { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 156 | self.pagination_worker.abort(); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 157 | let _ = (&mut self.pagination_worker).await; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 158 | self.watcher.abort(); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 159 | let _ = (&mut self.watcher).await; |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 160 | // after the watcher, or a last diff could register media for a timeline that's gone |
5a52012c9b1d | atagen | 2026-09-24 23:45 UTC | 161 | self.context.media.release(&self.scope).await; |
0bfa3f46f0be | atagen | 2026-09-26 09:12 UTC | 162 | let _ = self |
0bfa3f46f0be | atagen | 2026-09-26 09:12 UTC | 163 | .context |
0bfa3f46f0be | atagen | 2026-09-26 09:12 UTC | 164 | .events |
0bfa3f46f0be | atagen | 2026-09-26 09:12 UTC | 165 | .send(Event::TimelineClosed { |
0bfa3f46f0be | atagen | 2026-09-26 09:12 UTC | 166 | timeline_id: self.id.clone(), |
0bfa3f46f0be | atagen | 2026-09-26 09:12 UTC | 167 | }) |
0bfa3f46f0be | atagen | 2026-09-26 09:12 UTC | 168 | .await; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 169 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 170 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 171 | pub(super) async fn execute( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 172 | &self, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 173 | command: TimelineCommand, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 174 | reply: Responder, |
1fe480c16a3c | atagen | 2026-09-26 08:44 UTC | 175 | work: &mut TaskSet<()>, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 176 | ) { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 177 | let timeline = self.timeline.clone(); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 178 | let thread_root = self.id.thread_root().cloned(); |
1fe480c16a3c | atagen | 2026-09-26 08:44 UTC | 179 | let background: EngineBoxFuture<'static, Result<(), Error>> = match command { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 180 | TimelineCommand::Paginate { limit, .. } => return self.paginate(limit, Some(reply)), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 181 | // network-bound, so it runs beside the actor instead of queueing the room behind it |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 182 | TimelineCommand::Redact { target, reason, .. } => Box::pin(async move { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 183 | timeline |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 184 | .redact(&item_id(target), reason.as_deref()) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 185 | .await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 186 | .map_err(timeline_error) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 187 | }), |
8fa8a7cde89c | atagen | 2026-10-08 12:39 UTC | 188 | TimelineCommand::ToggleReaction { |
8fa8a7cde89c | atagen | 2026-10-08 12:39 UTC | 189 | target, |
8fa8a7cde89c | atagen | 2026-10-08 12:39 UTC | 190 | key, |
8fa8a7cde89c | atagen | 2026-10-08 12:39 UTC | 191 | shortcode, |
8fa8a7cde89c | atagen | 2026-10-08 12:39 UTC | 192 | .. |
8fa8a7cde89c | atagen | 2026-10-08 12:39 UTC | 193 | } => Box::pin(async move { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 194 | timeline |
8fa8a7cde89c | atagen | 2026-10-08 12:39 UTC | 195 | .toggle_reaction_with_shortcode(&item_id(target), &key, shortcode.as_deref()) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 196 | .await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 197 | .map(drop) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 198 | .map_err(timeline_error) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 199 | }), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 200 | TimelineCommand::MarkRead { event_id, .. } => Box::pin(async move { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 201 | let receipt_failed = |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 202 | |source| Error::from_sdk("sending read receipt failed", source); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 203 | timeline |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 204 | .send_single_receipt(ReceiptType::Read, event_id.clone()) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 205 | .await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 206 | .map_err(receipt_failed)?; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 207 | if thread_root.is_none() { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 208 | timeline |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 209 | .send_single_receipt(ReceiptType::FullyRead, event_id) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 210 | .await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 211 | .map_err(receipt_failed)?; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 212 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 213 | Ok(()) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 214 | }), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 215 | command => return reply.done(self.execute_serial(command).await), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 216 | }; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 217 | work.spawn(async move { reply.done(background.await) }); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 218 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 219 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 220 | /// sends stay on the actor so they hit the send queue in the order they were asked for |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 221 | async fn execute_serial(&self, command: TimelineCommand) -> Result<(), Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 222 | let timeline = &self.timeline; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 223 | match command { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 224 | TimelineCommand::Send { content, .. } => { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 225 | let body = match &content { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 226 | MessageContent::Text { content, .. } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 227 | | MessageContent::Emote { content, .. } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 228 | | MessageContent::Reply { content, .. } => &content.body, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 229 | }; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 230 | if body.trim().is_empty() { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 231 | return Err(Error::new(ErrorKind::EmptyBody, "message body is empty")); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 232 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 233 | let content = match content { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 234 | MessageContent::Text { content, mentions } => { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 235 | message_content(content, mentions, false).with_relation(None) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 236 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 237 | MessageContent::Emote { content, mentions } => { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 238 | message_content(content, mentions, true).with_relation(None) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 239 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 240 | MessageContent::Reply { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 241 | event_id, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 242 | content, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 243 | mentions, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 244 | notify_replied_to, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 245 | } => { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 246 | self.reply_content(event_id, content, mentions, notify_replied_to) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 247 | .await? |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 248 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 249 | }; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 250 | timeline |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 251 | .send(content.into()) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 252 | .await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 253 | .map(drop) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 254 | .map_err(timeline_error) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 255 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 256 | TimelineCommand::Edit { |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 257 | target, content, .. |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 258 | } => { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 259 | let (content, mentions, emote) = match content { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 260 | MessageEditContent::Text { content, mentions } => (content, mentions, false), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 261 | MessageEditContent::Emote { content, mentions } => (content, mentions, true), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 262 | }; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 263 | if content.body.trim().is_empty() { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 264 | return Err(Error::new(ErrorKind::EmptyBody, "message body is empty")); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 265 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 266 | timeline |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 267 | .edit( |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 268 | &item_id(target), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 269 | EditedContent::RoomMessage(message_content(content, mentions, emote)), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 270 | ) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 271 | .await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 272 | .map_err(timeline_error) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 273 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 274 | _ => Err(Error::new( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 275 | ErrorKind::Other, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 276 | "timeline command was misrouted", |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 277 | )), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 278 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 279 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 280 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 281 | async fn reply_content( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 282 | &self, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 283 | event_id: OwnedEventId, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 284 | content: RichText, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 285 | mentions: MessageMentions, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 286 | notify_replied_to: bool, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 287 | ) -> Result<matrix_sdk::ruma::events::room::message::RoomMessageEventContent, Error> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 288 | let thread_root = self.id.thread_root(); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 289 | let content = self |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 290 | .timeline |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 291 | .room() |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 292 | .make_reply_event( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 293 | message_content(content, mentions, false), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 294 | SdkReply { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 295 | event_id, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 296 | enforce_thread: if thread_root.is_some() { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 297 | EnforceThread::Threaded(ReplyWithinThread::Yes) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 298 | } else { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 299 | EnforceThread::MaybeThreaded |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 300 | }, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 301 | add_mentions: if notify_replied_to { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 302 | AddMentions::Yes |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 303 | } else { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 304 | AddMentions::No |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 305 | }, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 306 | }, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 307 | ) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 308 | .await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 309 | .map_err(|source| { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 310 | Error::with_source(ErrorKind::Timeline, "reply operation failed", source) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 311 | })?; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 312 | if let Some(thread_root) = thread_root |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 313 | && !matches!( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 314 | content.relates_to.as_ref(), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 315 | Some(Relation::Thread(thread)) if &thread.event_id == thread_root |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 316 | ) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 317 | { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 318 | return Err(Error::new( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 319 | ErrorKind::Invalid, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 320 | "reply target does not belong to the selected thread", |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 321 | )); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 322 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 323 | Ok(content) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 324 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 325 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 326 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 327 | impl Drop for TimelineSession { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 328 | fn drop(&mut self) { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 329 | self.watcher.abort(); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 330 | self.pagination_worker.abort(); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 331 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 332 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 333 | |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 334 | fn item_id(target: EventRef) -> TimelineEventItemId { |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 335 | match target { |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 336 | EventRef::Remote(event_id) => TimelineEventItemId::EventId(event_id), |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 337 | EventRef::Local(transaction_id) => TimelineEventItemId::TransactionId(transaction_id), |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 338 | } |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 339 | } |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 340 | |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 341 | /// the sdk leaves a reply's target unloaded until someone asks, so the watcher asks, once per event |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 342 | struct ReplyFetcher { |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 343 | timeline: Arc<Timeline>, |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 344 | asked: HashSet<OwnedEventId>, |
1fe480c16a3c | atagen | 2026-09-26 08:44 UTC | 345 | fetches: TaskSet<()>, |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 346 | } |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 347 | |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 348 | impl ReplyFetcher { |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 349 | fn fetch(&mut self, missing: Vec<OwnedEventId>) { |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 350 | for event_id in missing { |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 351 | if self.asked.insert(event_id.clone()) { |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 352 | let timeline = self.timeline.clone(); |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 353 | self.fetches.spawn(async move { |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 354 | if let Err(error) = timeline.fetch_details_for_event(&event_id).await { |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 355 | tracing::debug!(%event_id, %error, "fetching reply details failed"); |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 356 | } |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 357 | }); |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 358 | } |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 359 | } |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 360 | } |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 361 | } |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 362 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 363 | async fn start_watcher( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 364 | id: &TimelineId, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 365 | timeline: &Arc<Timeline>, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 366 | context: &SessionContext, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 367 | scope: &MediaScope, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 368 | ) -> Result<JoinHandle<()>, SendEventError> { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 369 | let (items, mut stream) = timeline.subscribe().await; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 370 | let current_user_id = context.current_user_id.clone(); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 371 | let normalised = normalise_timeline(items.iter(), current_user_id.as_deref(), scope); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 372 | context.media.register(normalised.media).await; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 373 | context |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 374 | .events |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 375 | .send(Event::TimelineReset { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 376 | timeline_id: id.clone(), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 377 | items: normalised.items, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 378 | }) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 379 | .await?; |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 380 | let mut replies = ReplyFetcher { |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 381 | timeline: timeline.clone(), |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 382 | asked: HashSet::new(), |
1fe480c16a3c | atagen | 2026-09-26 08:44 UTC | 383 | fetches: TaskSet::new(), |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 384 | }; |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 385 | replies.fetch(normalised.missing_replies); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 386 | let id = id.clone(); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 387 | let events = context.events.clone(); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 388 | let media = context.media.clone(); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 389 | let scope = scope.clone(); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 390 | Ok(context.supervisor.spawn("timeline watcher", async move { |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 391 | loop { |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 392 | let diffs = tokio::select! { |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 393 | diffs = stream.next() => match diffs { |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 394 | Some(diffs) => diffs, |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 395 | None => return, |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 396 | }, |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 397 | Some(_) = replies.fetches.join_next(), if !replies.fetches.is_empty() => continue, |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 398 | }; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 399 | let normalised = normalise_timeline_diffs(diffs, current_user_id.as_deref(), &scope); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 400 | media.register(normalised.media).await; |
960ac0721079 | atagen | 2026-09-25 00:24 UTC | 401 | replies.fetch(normalised.missing_replies); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 402 | let event = Event::TimelineChanged { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 403 | timeline_id: id.clone(), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 404 | diffs: normalised.diffs, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 405 | }; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 406 | if events.send(event).await.is_err() { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 407 | return; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 408 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 409 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 410 | })) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 411 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 412 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 413 | async fn run_pagination( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 414 | mut requests: mpsc::Receiver<PaginationRequest>, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 415 | timeline: Arc<Timeline>, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 416 | events: EventSender, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 417 | timeline_id: TimelineId, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 418 | ) { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 419 | while let Some(PaginationRequest { limit, reply }) = requests.recv().await { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 420 | let history = |state| Event::HistoryChanged { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 421 | timeline_id: timeline_id.clone(), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 422 | state, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 423 | }; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 424 | if events.send(history(HistoryState::Loading)).await.is_err() { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 425 | return; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 426 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 427 | let result = timeline |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 428 | .paginate_backwards(limit.max(1)) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 429 | .await |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 430 | .map_err(timeline_error); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 431 | let state = match &result { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 432 | Ok(true) => HistoryState::StartReached, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 433 | Ok(false) => HistoryState::Idle, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 434 | Err(error) => HistoryState::Failed(error.to_string()), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 435 | }; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 436 | let _ = events.send(history(state)).await; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 437 | if let Some(reply) = reply { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 438 | reply.done(result.map(drop)); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 439 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 440 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 441 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 442 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 443 | fn message_content( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 444 | content: RichText, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 445 | mentions: MessageMentions, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 446 | emote: bool, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 447 | ) -> RoomMessageEventContentWithoutRelation { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 448 | let content = match content.formatted_body { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 449 | Some(formatted_body) if emote => { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 450 | RoomMessageEventContentWithoutRelation::emote_html(content.body, formatted_body) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 451 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 452 | Some(formatted_body) => { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 453 | RoomMessageEventContentWithoutRelation::text_html(content.body, formatted_body) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 454 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 455 | None if emote => RoomMessageEventContentWithoutRelation::emote_plain(content.body), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 456 | None => RoomMessageEventContentWithoutRelation::text_plain(content.body), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 457 | }; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 458 | let content = content.add_mentions(Mentions::with_user_ids(mentions.user_ids)); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 459 | if mentions.room { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 460 | content.add_mentions(Mentions::with_room_mention()) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 461 | } else { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 462 | content |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 463 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 464 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 465 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 466 | pub(super) fn timeline_error(source: matrix_sdk_ui::timeline::Error) -> Error { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 467 | Error::with_source(ErrorKind::Timeline, "timeline operation failed", source) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 468 | } |