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