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