Commit 71cb0107c2

71cb0107c2eca5eb3040f0966306be10e53a0325

parent: 44d5f71b2d

Unregistered key

vaw <git@nlih.de> · 2026-08-15 06:17 UTC
committer: <noreply@github.com>

Send messages asynchronously using the SDK's send queue (#627)

Layout: unified · split

src/base.rs +53 −13
@@ -16,6 +16,7 @@ use emojis::Emoji;
1616use matrix_sdk::ruma::events::receipt::ReceiptThread;
1717use matrix_sdk::ruma::events::room::MediaSource;
1818use matrix_sdk::ruma::events::sticker::StickerEvent;
19use matrix_sdk::ruma::OwnedTransactionId;
1920use ratatui::{
2021 buffer::Buffer,
2122 layout::{Alignment, Rect},
@@ -733,6 +734,10 @@ pub enum IambError {
733734 #[error("Matrix client error: {0}")]
734735 Matrix(#[from] matrix_sdk::Error),
735736
737 /// A failure when sending a message.
738 #[error("Send queue error: {0}")]
739 SendQueue(#[from] matrix_sdk::send_queue::RoomSendQueueError),
740
736741 /// A failure in the sled storage.
737742 #[error("Matrix client storage error: {0}")]
738743 Store(#[from] matrix_sdk::StoreError),
@@ -867,6 +872,19 @@ impl EventLocation {
867872 }
868873}
869874
875/// Indicates where a local echo lives in the [`ChatStore`].
876#[derive(Debug, Clone)]
877pub enum EchoLocation {
878 /// The [`OwnedTransactionId`] belongs to a message.
879 ///
880 /// If the first argument is [`None`], then it's part of the main scrollback. When [`Some`], it
881 /// specifies which thread it's in reply to.
882 Message(Option<OwnedEventId>, MessageKey),
883
884 /// The local echo has been replaced by an event with this event id.
885 Replaced(OwnedEventId),
886}
887
870888#[derive(Clone, Debug, Default, Eq, PartialEq)]
871889pub struct UnreadInfo {
872890 pub(crate) unread_mark: bool,
@@ -985,6 +1003,7 @@ pub struct RoomInfo {
9851003
9861004 /// A map of event IDs to where they are stored in this struct.
9871005 pub keys: HashMap<OwnedEventId, EventLocation>,
1006 pub echo_keys: HashMap<OwnedTransactionId, EchoLocation>,
9881007
9891008 /// The messages loaded for this room.
9901009 messages: Messages,
@@ -1030,6 +1049,7 @@ impl Default for RoomInfo {
10301049 name: Default::default(),
10311050 tags: Default::default(),
10321051 keys: Default::default(),
1052 echo_keys: Default::default(),
10331053 event_receipts: Default::default(),
10341054 user_receipts: Default::default(),
10351055 reactions: Default::default(),
@@ -1203,8 +1223,10 @@ impl RoomInfo {
12031223 ) {
12041224 match sticker {
12051225 MessageLikeEvent::Original(ref sticker_content) => {
1206 let key =
1207 (sticker_content.origin_server_ts.into(), sticker_content.event_id.clone());
1226 let key = MessageKey {
1227 ts: sticker_content.origin_server_ts.into(),
1228 id: sticker_content.event_id.clone().into(),
1229 };
12081230
12091231 let loc = EventLocation::Sticker(key.clone());
12101232
@@ -1221,7 +1243,11 @@ impl RoomInfo {
12211243 }
12221244 },
12231245 MessageLikeEvent::Redacted(ref redaction) => {
1224 let key = (redaction.origin_server_ts.into(), redaction.event_id.clone());
1246 let key = MessageKey {
1247 ts: redaction.origin_server_ts.into(),
1248 id: redaction.event_id.clone().into(),
1249 };
1250
12251251 self.messages.insert_message(key.clone(), sticker.clone());
12261252 },
12271253 }
@@ -1252,7 +1278,7 @@ impl RoomInfo {
12521278 MessageEvent::Original(orig) => {
12531279 orig.content.apply_replacement(new_msgtype);
12541280 },
1255 MessageEvent::Local(_, content) => {
1281 MessageEvent::Local(_, _, content) => {
12561282 content.apply_replacement(new_msgtype);
12571283 },
12581284 MessageEvent::Redacted(_, _) |
@@ -1270,7 +1296,10 @@ impl RoomInfo {
12701296
12711297 pub fn insert_any_state(&mut self, msg: AnySyncStateEvent) {
12721298 let event_id = msg.event_id().to_owned();
1273 let key = (msg.origin_server_ts().into(), event_id.clone());
1299 let key = MessageKey {
1300 ts: msg.origin_server_ts().into(),
1301 id: event_id.clone().into(),
1302 };
12741303
12751304 let loc = EventLocation::State(key.clone());
12761305 self.keys.insert(event_id, loc);
@@ -1290,14 +1319,17 @@ impl RoomInfo {
12901319 unread_messages: room.num_unread_messages(),
12911320 unread_notifications: room.num_unread_notifications(),
12921321 unread_mentions: room.num_unread_mentions(),
1293 latest: last_message.map(|((ts, _), _)| ts.to_owned()),
1322 latest: last_message.map(|(key, _)| key.ts.to_owned()),
12941323 }
12951324 }
12961325
12971326 /// Inserts events that couldn't be decrypted into the scrollback.
12981327 pub fn insert_encrypted(&mut self, msg: RoomEncryptedEvent) {
12991328 let event_id = msg.event_id().to_owned();
1300 let key = (msg.origin_server_ts().into(), event_id.clone());
1329 let key = MessageKey {
1330 ts: msg.origin_server_ts().into(),
1331 id: event_id.clone().into(),
1332 };
13011333
13021334 self.keys.insert(event_id, EventLocation::Message(None, key.clone()));
13031335 self.messages.insert(key, msg.into());
@@ -1306,7 +1338,10 @@ impl RoomInfo {
13061338 /// Insert a new message.
13071339 pub fn insert_message(&mut self, msg: RoomMessageEvent) {
13081340 let event_id = msg.event_id().to_owned();
1309 let key = (msg.origin_server_ts().into(), event_id.clone());
1341 let key = MessageKey {
1342 ts: msg.origin_server_ts().into(),
1343 id: event_id.clone().into(),
1344 };
13101345
13111346 let loc = EventLocation::Message(None, key.clone());
13121347 self.keys.insert(event_id, loc);
@@ -1315,7 +1350,10 @@ impl RoomInfo {
13151350
13161351 fn insert_thread(&mut self, msg: RoomMessageEvent, thread_root: OwnedEventId) {
13171352 let event_id = msg.event_id().to_owned();
1318 let key = (msg.origin_server_ts().into(), event_id.clone());
1353 let key = MessageKey {
1354 ts: msg.origin_server_ts().into(),
1355 id: event_id.clone().into(),
1356 };
13191357
13201358 let replies = self
13211359 .threads
@@ -1407,11 +1445,13 @@ impl RoomInfo {
14071445 }
14081446
14091447 pub fn fully_read(&mut self, user_id: OwnedUserId, thread: ReceiptThread) {
1410 let Some(messages) = (match &thread {
1448 let messages = match &thread {
14111449 ReceiptThread::Main => self.get_thread(None),
14121450 ReceiptThread::Thread(root) => self.get_thread(Some(root)),
14131451 _ => None,
1414 }) else {
1452 };
1453
1454 let Some(messages) = messages else {
14151455 return;
14161456 };
14171457
@@ -1427,11 +1467,11 @@ impl RoomInfo {
14271467 MessageEvent::Redacted(..)
14281468 )
14291469 })
1430 .map(|(_, msg)| msg.event.event_id().to_owned())
1470 .flat_map(|(_, msg)| msg.event.event_id())
14311471 .next_back();
14321472
14331473 if let Some(event_id) = event_id {
1434 self.set_receipt(thread, user_id, event_id);
1474 self.set_receipt(thread, user_id, event_id.to_owned());
14351475 }
14361476 }
14371477
src/message/mod.rs +80 −112
@@ -14,6 +14,8 @@ use matrix_sdk::ruma::events::receipt::ReceiptThread;
1414use matrix_sdk::ruma::events::room::MediaSource;
1515use matrix_sdk::ruma::events::sticker::StickerEvent;
1616use matrix_sdk::ruma::events::{AnyRedactionEvent, MessageLikeEvent};
17use matrix_sdk::ruma::OwnedTransactionId;
18use matrix_sdk::send_queue::SendHandle;
1719use unicode_width::UnicodeWidthStr;
1820
1921use matrix_sdk::ruma::{
@@ -77,7 +79,15 @@ pub use html::TreeGenState;
7779
7880type ProtocolPreview<'a> = (&'a Protocol, u16, u16);
7981
80pub type MessageKey = (MessageTimeStamp, OwnedEventId);
82/// The key used for uniquely identifying messages within a room and its threads.
83///
84/// Note that the ordering of the fields is important here, so that the derived
85/// `Ord` trait will sort by timestamp first, and then sort by the message ID.
86#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone)]
87pub struct MessageKey {
88 pub ts: MessageTimeStamp,
89 pub id: MessageId,
90}
8191
8292pub struct Messages(BTreeMap<MessageKey, Message>, pub ReceiptThread);
8393
@@ -109,16 +119,10 @@ impl Messages {
109119 }
110120
111121 pub fn insert_message(&mut self, key: MessageKey, msg: impl Into<Message>) {
112 let event_id = key.1.clone();
113122 let mut msg = msg.into();
114
115123 msg.event.strip_reply_fallback();
116124
117125 self.0.insert(key, msg);
118
119 // Remove any echo.
120 let key = (MessageTimeStamp::LocalEcho, event_id);
121 let _ = self.0.remove(&key);
122126 }
123127}
124128
@@ -161,10 +165,10 @@ fn hash_finish_usize(hasher: DefaultHasher) -> Option<usize> {
161165 }
162166}
163167
164/// Hash an [EventId] into a [usize].
165fn hash_event_id(event_id: &EventId) -> Option<usize> {
168/// Hash an [`MessageId`] into a [`usize`].
169fn hash_message_id(id: &MessageId) -> Option<usize> {
166170 let mut hasher = DefaultHasher::new();
167 event_id.hash(&mut hasher);
171 id.hash(&mut hasher);
168172 hash_finish_usize(hasher)
169173}
170174
@@ -200,11 +204,25 @@ fn placeholder_frame(
200204 Some(placeholder)
201205}
202206
203#[inline]
204fn millis_to_datetime(ms: UInt) -> DateTime<LocalTz> {
205 let time = i64::from(ms) / 1000;
206 let time = DateTime::from_timestamp(time, 0).unwrap_or_default();
207 time.into()
207#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash)]
208pub enum MessageId {
209 Origin(OwnedEventId),
210 Local(OwnedTransactionId),
211}
212
213impl MessageId {
214 pub fn as_origin(&self) -> Option<&EventId> {
215 match self {
216 Self::Origin(id) => Some(id),
217 _ => None,
218 }
219 }
220}
221
222impl From<OwnedEventId> for MessageId {
223 fn from(value: OwnedEventId) -> Self {
224 Self::Origin(value)
225 }
208226}
209227
210228#[derive(thiserror::Error, Debug)]
@@ -216,83 +234,40 @@ pub enum TimeStampIntError {
216234 UIntError(<UInt as TryFrom<u64>>::Error),
217235}
218236
219#[derive(Clone, Copy, Debug, Eq, PartialEq)]
220pub enum MessageTimeStamp {
221 OriginServer(UInt),
222 LocalEcho,
223}
237#[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord)]
238pub struct MessageTimeStamp(pub MilliSecondsSinceUnixEpoch);
224239
225240impl MessageTimeStamp {
226 fn as_datetime(&self) -> DateTime<LocalTz> {
227 match self {
228 MessageTimeStamp::OriginServer(ms) => millis_to_datetime(*ms),
229 MessageTimeStamp::LocalEcho => LocalTz::now(),
230 }
241 fn as_datetime(self) -> DateTime<LocalTz> {
242 let time = i64::from(self.0 .0) / 1000;
243 let time = DateTime::from_timestamp(time, 0).unwrap_or_default();
244 time.into()
231245 }
232246
233 fn same_day(&self, other: &Self) -> bool {
247 fn same_day(self, other: Self) -> bool {
234248 let dt1 = self.as_datetime();
235249 let dt2 = other.as_datetime();
236250
237251 dt1.date_naive() == dt2.date_naive()
238252 }
239253
240 fn show_date(&self) -> Option<Span<'_>> {
254 fn show_date(self) -> Option<Span<'static>> {
241255 let time = self.as_datetime().format("%A, %B %d %Y").to_string();
242256
243257 Span::styled(time, BOLD_STYLE).into()
244258 }
245259
246 fn show_time(&self) -> Option<Span<'_>> {
247 match self {
248 MessageTimeStamp::OriginServer(ms) => {
249 let time = millis_to_datetime(*ms).format("%T");
250 let time = format!(" [{time}]");
260 fn show_time(self) -> Option<Span<'static>> {
261 let time = self.as_datetime().format("%T");
262 let time = format!(" [{time}]");
251263
252 Span::raw(time).into()
253 },
254 MessageTimeStamp::LocalEcho => None,
255 }
256 }
257
258 fn is_local_echo(&self) -> bool {
259 matches!(self, MessageTimeStamp::LocalEcho)
260 }
261
262 pub fn as_millis(&self) -> Option<MilliSecondsSinceUnixEpoch> {
263 match self {
264 MessageTimeStamp::OriginServer(ms) => MilliSecondsSinceUnixEpoch(*ms).into(),
265 MessageTimeStamp::LocalEcho => None,
266 }
267 }
268}
269
270impl Ord for MessageTimeStamp {
271 fn cmp(&self, other: &Self) -> Ordering {
272 match (self, other) {
273 (MessageTimeStamp::OriginServer(_), MessageTimeStamp::LocalEcho) => Ordering::Less,
274 (MessageTimeStamp::OriginServer(a), MessageTimeStamp::OriginServer(b)) => a.cmp(b),
275 (MessageTimeStamp::LocalEcho, MessageTimeStamp::OriginServer(_)) => Ordering::Greater,
276 (MessageTimeStamp::LocalEcho, MessageTimeStamp::LocalEcho) => Ordering::Equal,
277 }
278 }
279}
280
281impl PartialOrd for MessageTimeStamp {
282 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
283 Some(self.cmp(other))
284 }
285}
286
287impl From<UInt> for MessageTimeStamp {
288 fn from(millis: UInt) -> Self {
289 MessageTimeStamp::OriginServer(millis)
264 Span::raw(time).into()
290265 }
291266}
292267
293268impl From<MilliSecondsSinceUnixEpoch> for MessageTimeStamp {
294269 fn from(millis: MilliSecondsSinceUnixEpoch) -> Self {
295 MessageTimeStamp::OriginServer(millis.0)
270 Self(millis)
296271 }
297272}
298273
@@ -300,10 +275,7 @@ impl TryFrom<&MessageTimeStamp> for usize {
300275 type Error = TimeStampIntError;
301276
302277 fn try_from(ts: &MessageTimeStamp) -> Result<Self, Self::Error> {
303 let n = match ts {
304 MessageTimeStamp::LocalEcho => 0,
305 MessageTimeStamp::OriginServer(u) => usize::try_from(u64::from(*u))?,
306 };
278 let n = usize::try_from(u64::from(ts.0 .0))?;
307279
308280 Ok(n)
309281 }
@@ -313,14 +285,10 @@ impl TryFrom<usize> for MessageTimeStamp {
313285 type Error = TimeStampIntError;
314286
315287 fn try_from(u: usize) -> Result<Self, Self::Error> {
316 if u == 0 {
317 Ok(MessageTimeStamp::LocalEcho)
318 } else {
319 let n = u64::try_from(u)?;
320 let n = UInt::try_from(n).map_err(TimeStampIntError::UIntError)?;
288 let n = u64::try_from(u)?;
289 let n = UInt::try_from(n).map_err(TimeStampIntError::UIntError)?;
321290
322 Ok(MessageTimeStamp::from(n))
323 }
291 Ok(MessageTimeStamp::from(MilliSecondsSinceUnixEpoch(n)))
324292 }
325293}
326294
@@ -354,33 +322,30 @@ impl MessageCursor {
354322
355323 pub fn from_cursor(cursor: &Cursor, thread: &Messages) -> Option<Self> {
356324 let ev_hash = cursor.get_x();
357 let ev_term = OwnedEventId::try_from("$").ok()?;
325 let ev_term = OwnedEventId::try_from("$").ok()?.into();
358326
359327 let ts_start = MessageTimeStamp::try_from(cursor.get_y()).ok()?;
360 let start = (ts_start, ev_term);
328 let start = MessageKey { ts: ts_start, id: ev_term };
361329
362 for ((ts, event_id), _) in thread.range(&start..) {
363 if hash_event_id(event_id)? == ev_hash {
364 return Self::from((*ts, event_id.clone())).into();
330 for (key, _) in thread.range(&start..) {
331 if hash_message_id(&key.id)? == ev_hash {
332 return Self::from(key.clone()).into();
365333 }
366334
367 if ts > &ts_start {
335 if key.ts > ts_start {
368336 break;
369337 }
370338 }
371339
372340 // If we can't find the cursor, then go to the nearest timestamp.
373 thread
374 .range(start..)
375 .next()
376 .map(|((ts, ev), _)| Self::from((*ts, ev.clone())))
341 thread.range(start..).next().map(|(key, _)| Self::from(key.clone()))
377342 }
378343
379344 pub fn to_cursor(&self, thread: &Messages) -> Option<Cursor> {
380 let (ts, event_id) = self.to_key(thread)?;
345 let key = self.to_key(thread)?;
381346
382 let y = usize::try_from(ts).ok()?;
383 let x = hash_event_id(event_id)?;
347 let y = usize::try_from(&key.ts).ok()?;
348 let x = hash_message_id(&key.id)?;
384349
385350 Cursor::new(y, x).into()
386351 }
@@ -436,20 +401,22 @@ pub enum MessageEvent {
436401 Redacted(OwnedEventId, Option<String>),
437402 State(Box<AnySyncStateEvent>),
438403 Sticker(Box<StickerEvent>),
439 Local(OwnedEventId, Box<RoomMessageEventContent>),
404 Local(OwnedTransactionId, SendHandle, Box<RoomMessageEventContent>),
440405}
441406
442407impl MessageEvent {
443 pub fn event_id(&self) -> &EventId {
444 match self {
408 pub fn event_id(&self) -> Option<&EventId> {
409 let event_id = match self {
445410 MessageEvent::EncryptedOriginal(ev) => ev.event_id.as_ref(),
446411 MessageEvent::EncryptedRedacted(ev) => ev.event_id.as_ref(),
447412 MessageEvent::Original(ev) => ev.event_id.as_ref(),
448413 MessageEvent::Redacted(event_id, _) => event_id.as_ref(),
449414 MessageEvent::State(ev) => ev.event_id(),
415 MessageEvent::Local(..) => return None,
450416 MessageEvent::Sticker(ev) => ev.event_id(),
451 MessageEvent::Local(event_id, _) => event_id.as_ref(),
452 }
417 };
418
419 Some(event_id)
453420 }
454421
455422 pub fn content(&self) -> Option<&RoomMessageEventContent> {
@@ -460,7 +427,7 @@ impl MessageEvent {
460427 MessageEvent::Redacted(_, _) => None,
461428 MessageEvent::State(_) => None,
462429 MessageEvent::Sticker(_) => None,
463 MessageEvent::Local(_, content) => Some(content),
430 MessageEvent::Local(_, _, content) => Some(content),
464431 }
465432 }
466433
@@ -481,7 +448,7 @@ impl MessageEvent {
481448 MessageEvent::Redacted(_, reason) => body_cow_reason(reason.as_deref()),
482449 MessageEvent::Sticker(ev) => body_cow_sticker(ev),
483450 MessageEvent::State(ev) => body_cow_state(ev),
484 MessageEvent::Local(_, content) => body_cow_content(content),
451 MessageEvent::Local(_, _, content) => body_cow_content(content),
485452 }
486453 }
487454
@@ -493,7 +460,7 @@ impl MessageEvent {
493460 MessageEvent::Redacted(_, _) => return None,
494461 MessageEvent::State(ev) => return Some(html_state(ev)),
495462 MessageEvent::Sticker(_) => return None,
496 MessageEvent::Local(_, content) => content,
463 MessageEvent::Local(_, _, content) => content,
497464 };
498465
499466 if let MessageType::Text(content) = &content.msgtype {
@@ -513,12 +480,12 @@ impl MessageEvent {
513480 MessageEvent::EncryptedRedacted(_) => return,
514481 MessageEvent::Redacted(_, _) => return,
515482 MessageEvent::State(_) => return,
516 MessageEvent::Local(_, _) => return,
517483 MessageEvent::Sticker(ev) => {
518484 let event_id = ev.event_id().to_owned();
519485 let reason = redaction_reason_event(redaction);
520486 *self = MessageEvent::Redacted(event_id, reason);
521487 },
488 MessageEvent::Local(..) => return,
522489 MessageEvent::Original(ev) => {
523490 let event_id = ev.event_id.to_owned();
524491 let reason = redaction_reason_event(redaction);
@@ -926,7 +893,7 @@ impl Message {
926893 let content = match &self.event {
927894 MessageEvent::EncryptedOriginal(_) => return None,
928895 MessageEvent::EncryptedRedacted(_) => return None,
929 MessageEvent::Local(_, content) => content,
896 MessageEvent::Local(_, _, content) => content,
930897 MessageEvent::Original(ev) => &ev.content,
931898 MessageEvent::Redacted(_, _) => return None,
932899 MessageEvent::State(_) => return None,
@@ -948,7 +915,7 @@ impl Message {
948915 let content = match &self.event {
949916 MessageEvent::EncryptedOriginal(_) => return None,
950917 MessageEvent::EncryptedRedacted(_) => return None,
951 MessageEvent::Local(_, content) => content,
918 MessageEvent::Local(_, _, content) => content,
952919 MessageEvent::Original(ev) => &ev.content,
953920 MessageEvent::Redacted(_, _) => return None,
954921 MessageEvent::State(_) => return None,
@@ -973,7 +940,7 @@ impl Message {
973940 style = style.add_modifier(StyleModifier::REVERSED)
974941 }
975942
976 if self.timestamp.is_local_echo() {
943 if matches!(self.event, MessageEvent::Local(..)) {
977944 style = style.add_modifier(StyleModifier::ITALIC);
978945 }
979946
@@ -994,7 +961,7 @@ impl Message {
994961 ) -> MessageFormatter<'a> {
995962 let orig = width;
996963 let date = match &prev {
997 Some(prev) if prev.timestamp.same_day(&self.timestamp) => None,
964 Some(prev) if prev.timestamp.same_day(self.timestamp) => None,
998965 _ => self.timestamp.show_date(),
999966 };
1000967 let user_gutter = settings.tunables.user_gutter_width;
@@ -1009,7 +976,7 @@ impl Message {
1009976 let read = info
1010977 .event_receipts
1011978 .values()
1012 .filter_map(|receipts| receipts.get(self.event.event_id()))
979 .filter_map(|receipts| self.event.event_id().and_then(|id| receipts.get(id)))
1013980 .flat_map(|read| read.iter())
1014981 .map(|user_id| user_id.to_owned())
1015982 .collect();
@@ -1103,11 +1070,12 @@ impl Message {
11031070 }
11041071
11051072 if settings.tunables.reaction_display {
1106 let reactions = info.get_reactions(self.event.event_id());
1073 let reactions =
1074 self.event.event_id().map(|id| info.get_reactions(id)).unwrap_or_default();
11071075 fmt.push_reactions(reactions, style, &mut text);
11081076 }
11091077
1110 if let Some(thread) = info.get_thread(Some(self.event.event_id())) {
1078 if let Some(thread) = self.event.event_id().and_then(|id| info.get_thread(Some(id))) {
11111079 fmt.push_thread_reply_count(thread.len(), &mut text);
11121080 }
11131081
@@ -1188,7 +1156,7 @@ impl Message {
11881156 ) -> SenderSpan<'a> {
11891157 if let Some(prev) = prev {
11901158 if self.sender == prev.sender &&
1191 self.timestamp.same_day(&prev.timestamp) &&
1159 self.timestamp.same_day(prev.timestamp) &&
11921160 !self.event.is_emote()
11931161 {
11941162 return SenderSpan::None;
src/tests.rs +29 −18
@@ -1,6 +1,7 @@
11use std::path::PathBuf;
22use std::{collections::HashMap, iter::FromIterator as _};
33
4use matrix_sdk::ruma::MilliSecondsSinceUnixEpoch;
45use matrix_sdk::ruma::{
56 event_id,
67 events::room::message::RoomMessageEventContent,
@@ -19,6 +20,7 @@ use ratatui::style::{Color, Style};
1920use serde_json::{Map, Value};
2021use tokio::sync::mpsc::unbounded_channel;
2122
23use crate::message::MessageTimeStamp;
2224use crate::{
2325 base::{ChatStore, EventLocation, ProgramStore, RoomInfo},
2426 config::{
@@ -37,13 +39,7 @@ use crate::{
3739 UserDisplayStyle,
3840 UserDisplayTunables,
3941 },
40 message::{
41 Message,
42 MessageEvent,
43 MessageKey,
44 MessageTimeStamp::{LocalEcho, OriginServer},
45 Messages,
46 },
42 message::{Message, MessageEvent, MessageKey, Messages},
4743 worker::Requester,
4844};
4945
@@ -64,11 +60,27 @@ lazy_static! {
6460 pub static ref MSG4_EVID: OwnedEventId =
6561 event_id!("$JP6qFV7WyXk5ZnexM3:example.com").to_owned();
6662 pub static ref MSG5_EVID: OwnedEventId = EventId::new_v1(server_name!("example.com"));
67 pub static ref MSG1_KEY: MessageKey = (LocalEcho, MSG1_EVID.clone());
68 pub static ref MSG2_KEY: MessageKey = (OriginServer(UInt::new(1).unwrap()), MSG2_EVID.clone());
69 pub static ref MSG3_KEY: MessageKey = (OriginServer(UInt::new(2).unwrap()), MSG3_EVID.clone());
70 pub static ref MSG4_KEY: MessageKey = (OriginServer(UInt::new(2).unwrap()), MSG4_EVID.clone());
71 pub static ref MSG5_KEY: MessageKey = (OriginServer(UInt::new(8).unwrap()), MSG5_EVID.clone());
63 pub static ref MSG1_KEY: MessageKey = MessageKey {
64 // 2000-01-01T00:00:00
65 ts: MessageTimeStamp(MilliSecondsSinceUnixEpoch(UInt::new(946681200).unwrap())),
66 id: MSG1_EVID.clone().into()
67 };
68 pub static ref MSG2_KEY: MessageKey = MessageKey {
69 ts: MessageTimeStamp(MilliSecondsSinceUnixEpoch(UInt::new(1).unwrap())),
70 id: MSG2_EVID.clone().into()
71 };
72 pub static ref MSG3_KEY: MessageKey = MessageKey {
73 ts: MessageTimeStamp(MilliSecondsSinceUnixEpoch(UInt::new(2).unwrap())),
74 id: MSG3_EVID.clone().into()
75 };
76 pub static ref MSG4_KEY: MessageKey = MessageKey {
77 ts: MessageTimeStamp(MilliSecondsSinceUnixEpoch(UInt::new(2).unwrap())),
78 id: MSG4_EVID.clone().into()
79 };
80 pub static ref MSG5_KEY: MessageKey = MessageKey {
81 ts: MessageTimeStamp(MilliSecondsSinceUnixEpoch(UInt::new(8).unwrap())),
82 id: MSG5_EVID.clone().into()
83 };
7284}
7385
7486pub fn user_style(user: &str) -> Style {
@@ -80,13 +92,13 @@ pub fn mock_room1_message(
8092 sender: OwnedUserId,
8193 key: MessageKey,
8294) -> Message {
83 let timestamp = key.0.as_millis().unwrap();
84 let event_id = key.1;
95 let timestamp = key.ts.0;
96 let event_id = key.id.as_origin().unwrap();
8597
8698 let event = serde_json::from_value(Value::Object(Map::from_iter([
8799 ("type".to_owned(), Value::String("m.room.message".into())),
88100 ("content".to_owned(), serde_json::to_value(&content).unwrap()),
89 ("event_id".to_owned(), serde_json::to_value(&event_id).unwrap()),
101 ("event_id".to_owned(), serde_json::to_value(event_id).unwrap()),
90102 ("sender".to_owned(), serde_json::to_value(&sender).unwrap()),
91103 ("origin_server_ts".to_owned(), serde_json::to_value(timestamp).unwrap()),
92104 ("room_id".to_owned(), serde_json::to_value(&*TEST_ROOM1_ID).unwrap()),
@@ -98,9 +110,8 @@ pub fn mock_room1_message(
98110
99111pub fn mock_message1() -> Message {
100112 let content = RoomMessageEventContent::text_plain("writhe");
101 let content = MessageEvent::Local(MSG1_EVID.clone(), content.into());
102113
103 Message::new(content, TEST_USER1.clone(), MSG1_KEY.0)
114 mock_room1_message(content, TEST_USER1.clone(), MSG1_KEY.clone())
104115}
105116
106117pub fn mock_message2() -> Message {
@@ -130,7 +141,7 @@ pub fn mock_message5() -> Message {
130141pub fn mock_keys() -> HashMap<OwnedEventId, EventLocation> {
131142 let mut keys = HashMap::new();
132143
133 keys.insert(MSG1_EVID.clone(), EventLocation::Message(None, MSG1_KEY.clone()));
144 keys.insert(MSG1_EVID.clone(), EventLocation::Message(None, MSG2_KEY.clone()));
134145 keys.insert(MSG2_EVID.clone(), EventLocation::Message(None, MSG2_KEY.clone()));
135146 keys.insert(MSG3_EVID.clone(), EventLocation::Message(None, MSG3_KEY.clone()));
136147 keys.insert(MSG4_EVID.clone(), EventLocation::Message(None, MSG4_KEY.clone()));
src/windows/mod.rs +3 −3
@@ -1695,7 +1695,7 @@ impl Promptable<ProgramContext, ProgramStore, IambInfo> for MemberItem {
16951695#[cfg(test)]
16961696mod tests {
16971697 use super::*;
1698 use matrix_sdk::ruma::{room_alias_id, server_name};
1698 use matrix_sdk::ruma::{room_alias_id, server_name, MilliSecondsSinceUnixEpoch};
16991699
17001700 #[derive(Debug, Eq, PartialEq)]
17011701 struct TestRoomItem {
@@ -1830,7 +1830,7 @@ mod tests {
18301830 alias: None,
18311831 name: "Room 2",
18321832 unread: UnreadInfo {
1833 latest: Some(MessageTimeStamp::OriginServer(40u32.into())),
1833 latest: Some(MessageTimeStamp(MilliSecondsSinceUnixEpoch(40u32.into()))),
18341834 unread_mark: false,
18351835 unread_messages: 0,
18361836 unread_notifications: 0,
@@ -1845,7 +1845,7 @@ mod tests {
18451845 alias: None,
18461846 name: "Room 3",
18471847 unread: UnreadInfo {
1848 latest: Some(MessageTimeStamp::OriginServer(20u32.into())),
1848 latest: Some(MessageTimeStamp(MilliSecondsSinceUnixEpoch(20u32.into()))),
18491849 unread_mark: false,
18501850 unread_messages: 0,
18511851 unread_notifications: 0,
src/windows/room/chat.rs +81 −54
@@ -26,13 +26,12 @@ use matrix_sdk::{
2626 OriginalRoomMessageEvent,
2727 Relation,
2828 ReplyWithinThread,
29 RoomMessageEventContent,
30 TextMessageEventContent,
3129 },
3230 OwnedEventId,
3331 OwnedRoomId,
3432 RoomId,
3533 },
34 send_queue::RoomSendQueueError,
3635 RoomState,
3736};
3837
@@ -72,6 +71,7 @@ use modalkit::prelude::*;
7271
7372use crate::base::{
7473 DownloadFlags,
74 EchoLocation,
7575 IambAction,
7676 IambBufferId,
7777 IambError,
@@ -87,14 +87,7 @@ use crate::base::{
8787};
8888
8989use crate::config::EncryptionIndicatorLocation;
90use crate::message::{
91 text_to_message,
92 Message,
93 MessageEvent,
94 MessageKey,
95 MessageTimeStamp,
96 TreeGenState,
97};
90use crate::message::{text_to_message, MessageEvent, MessageId, MessageKey, TreeGenState};
9891use crate::worker::Requester;
9992
10093use super::scrollback::{Scrollback, ScrollbackState};
@@ -346,7 +339,7 @@ impl ChatState {
346339
347340 let ev = match &msg.event {
348341 MessageEvent::Original(ev) => &ev.content,
349 MessageEvent::Local(_, ev) => ev.deref(),
342 MessageEvent::Local(_, _, ev) => ev.deref(),
350343 _ => {
351344 let msg = "Cannot edit a redacted message";
352345 let err = UIError::Failure(msg.into());
@@ -393,7 +386,14 @@ impl ChatState {
393386 MessageEvent::EncryptedOriginal(ev) => ev.event_id.clone(),
394387 MessageEvent::EncryptedRedacted(ev) => ev.event_id.clone(),
395388 MessageEvent::Original(ev) => ev.event_id.clone(),
396 MessageEvent::Local(event_id, _) => event_id.clone(),
389 MessageEvent::Local(..) => {
390 // XXX: Implement reactions for local echos
391
392 let msg = "Cannot react to a local echo";
393 let err = UIError::Failure(msg.into());
394
395 return Err(err);
396 },
397397 MessageEvent::State(ev) => ev.event_id().to_owned(),
398398 MessageEvent::Sticker(ev) => ev.event_id().to_owned(),
399399 MessageEvent::Redacted(_, _) => {
@@ -413,7 +413,8 @@ impl ChatState {
413413
414414 let reaction = Annotation::new(event_id, emoji);
415415 let msg = ReactionEventContent::new(reaction);
416 let _ = room.send(msg).await.map_err(IambError::from)?;
416
417 room.send_queue().send(msg.into()).await.map_err(IambError::from)?;
417418
418419 Ok(None)
419420 },
@@ -432,7 +433,22 @@ impl ChatState {
432433 MessageEvent::EncryptedOriginal(ev) => ev.event_id.clone(),
433434 MessageEvent::EncryptedRedacted(ev) => ev.event_id.clone(),
434435 MessageEvent::Original(ev) => ev.event_id.clone(),
435 MessageEvent::Local(event_id, _) => event_id.clone(),
436 MessageEvent::Local(_, handle, _) => {
437 let succeeded = handle
438 .abort()
439 .await
440 .map_err(RoomSendQueueError::from)
441 .map_err(IambError::from)?;
442
443 if !succeeded {
444 let msg = "local echo was already sent; please retry";
445 let err = UIError::Failure(msg.into());
446
447 return Err(err);
448 }
449
450 return Ok(None);
451 },
436452 MessageEvent::State(ev) => ev.event_id().to_owned(),
437453 MessageEvent::Sticker(ev) => ev.event_id().to_owned(),
438454 MessageEvent::Redacted(_, _) => {
@@ -496,7 +512,12 @@ impl ChatState {
496512 MessageEvent::EncryptedOriginal(ev) => ev.event_id.clone(),
497513 MessageEvent::EncryptedRedacted(ev) => ev.event_id.clone(),
498514 MessageEvent::Original(ev) => ev.event_id.clone(),
499 MessageEvent::Local(event_id, _) => event_id.clone(),
515 MessageEvent::Local(..) => {
516 let msg = "Cannot unreact to a local echo";
517 let err = UIError::Failure(msg.into());
518
519 return Err(err);
520 },
500521 MessageEvent::State(ev) => ev.event_id().to_owned(),
501522 MessageEvent::Sticker(ev) => ev.event_id().to_owned(),
502523 MessageEvent::Redacted(_, _) => {
@@ -545,9 +566,8 @@ impl ChatState {
545566 ) -> IambResult<EditInfo> {
546567 let room = self.get_joined(&store.application.worker)?;
547568 let info = store.application.rooms.get_or_default(self.id().to_owned());
548 let mut show_echo = true;
549569
550 let (event_id, msg) = match act {
570 match act {
551571 SendAction::Submit | SendAction::SubmitFromEditor => {
552572 let msg = self.tbox.get();
553573
@@ -570,13 +590,48 @@ impl ChatState {
570590
571591 let mut msg = text_to_message(msg);
572592
573 if let Some((_, event_id)) = &self.editing {
593 if let Some(key) = &self.editing {
594 let id = match &key.id {
595 MessageId::Origin(id) => id,
596 MessageId::Local(transaction_id) => {
597 match info.echo_keys.get(transaction_id) {
598 Some(EchoLocation::Replaced(id)) => id,
599 Some(EchoLocation::Message(thread, orig_key)) => {
600 let Some(MessageEvent::Local(_, handle, _)) = info
601 .get_thread(thread.as_deref())
602 .and_then(|thread| thread.get(orig_key))
603 .map(|msg| &msg.event)
604 else {
605 let msg = "local echo not found in store";
606 return Err(UIError::Failure(msg.into()));
607 };
608
609 let succeeded = handle
610 .edit(msg.into())
611 .await
612 .map_err(RoomSendQueueError::from)
613 .map_err(IambError::from)?;
614
615 if !succeeded {
616 let msg = "local echo was already sent; please retry";
617 return Err(UIError::Failure(msg.into()));
618 }
619
620 self.reset();
621 return Ok(None);
622 },
623 None => {
624 let msg = "local echo not found in store";
625 return Err(UIError::Failure(msg.into()));
626 },
627 }
628 },
629 };
630
574631 msg.relates_to = Some(Relation::Replacement(Replacement::new(
575 event_id.clone(),
632 id.to_owned(),
576633 msg.msgtype.clone().into(),
577634 )));
578
579 show_echo = false;
580635 } else if let Some(thread_root) = self.scrollback.thread() {
581636 if let Some(m) = self.get_reply_to(info) {
582637 msg = msg.make_for_thread(m, ReplyWithinThread::Yes, AddMentions::No);
@@ -589,15 +644,10 @@ impl ChatState {
589644 msg = msg.make_reply_to(m, ForwardThread::Yes, AddMentions::No);
590645 }
591646
592 // XXX: second parameter can be a locally unique transaction id.
593 // Useful for doing retries.
594 let resp = room.send(msg.clone()).await.map_err(IambError::from)?;
595 let event_id = resp.response.event_id;
647 room.send_queue().send(msg.into()).await.map_err(IambError::from)?;
596648
597649 // Reset message bar state now that it's been sent.
598650 self.reset();
599
600 (event_id, msg)
601651 },
602652 SendAction::Upload(file) => {
603653 let path = Path::new(file.as_str());
@@ -610,17 +660,10 @@ impl ChatState {
610660 .unwrap_or_else(|| Cow::from("Attachment"));
611661 let config = AttachmentConfig::new();
612662
613 let resp = room
614 .send_attachment(name.as_ref(), &mime, bytes, config)
663 room.send_queue()
664 .send_attachment(name.as_ref(), mime, bytes, config)
615665 .await
616666 .map_err(IambError::from)?;
617
618 // Mock up the local echo message for the scrollback.
619 let msg = TextMessageEventContent::plain(format!("[Attached File: {name}]"));
620 let msg = MessageType::Text(msg);
621 let msg = RoomMessageEventContent::new(msg);
622
623 (resp.event_id, msg)
624667 },
625668 SendAction::UploadImage(width, height, bytes) => {
626669 // Convert to png because arboard does not give us the mime type.
@@ -639,27 +682,11 @@ impl ChatState {
639682 let name = "Clipboard.png";
640683 let config = AttachmentConfig::new();
641684
642 let resp = room
643 .send_attachment(name, &mime, bytes, config)
685 room.send_queue()
686 .send_attachment(name, mime, bytes, config)
644687 .await
645688 .map_err(IambError::from)?;
646
647 // Mock up the local echo message for the scrollback.
648 let msg = TextMessageEventContent::plain(format!("[Attached File: {name}]"));
649 let msg = MessageType::Text(msg);
650 let msg = RoomMessageEventContent::new(msg);
651
652 (resp.event_id, msg)
653689 },
654 };
655
656 if show_echo {
657 let user = store.application.settings.profile.user_id.clone();
658 let key = (MessageTimeStamp::LocalEcho, event_id.clone());
659 let msg = MessageEvent::Local(event_id, msg.into());
660 let msg = Message::new(msg, user, MessageTimeStamp::LocalEcho);
661 let thread = self.scrollback.get_thread_mut(info);
662 thread.insert(key, msg);
663690 }
664691
665692 // Jump to the end of the scrollback to show the message.
src/windows/room/mod.rs +9 −7
@@ -229,13 +229,15 @@ pub async fn room_command(
229229 if !is_unread {
230230 let user_id = store.application.settings.profile.user_id.clone();
231231 let info = store.application.get_room_info(id.to_owned());
232 let messages = info.get_thread(None).expect("room main timeline doesn't exit");
233 if let Some(((_, event_id), _)) = messages.last_key_value() {
234 info.set_receipt(
235 matrix_sdk::ruma::events::receipt::ReceiptThread::Main,
236 user_id,
237 event_id.to_owned(),
238 );
232 let messages = info.get_thread(None).expect("room main timeline doesn't exist");
233 if let Some((key, _)) = messages.last_key_value() {
234 if let Some(event_id) = key.id.as_origin() {
235 info.set_receipt(
236 matrix_sdk::ruma::events::receipt::ReceiptThread::Main,
237 user_id,
238 event_id.to_owned(),
239 );
240 }
239241 }
240242 }
241243
src/windows/room/scrollback.rs +9 −5
@@ -1047,9 +1047,13 @@ impl Promptable<ProgramContext, ProgramStore, IambInfo> for ScrollbackState {
10471047 let err = EditError::Failure(msg.into());
10481048 Err(err)
10491049 } else {
1050 let root = key.1.clone();
1050 let Some(root) = key.id.as_origin() else {
1051 let msg = "Cannot create thread for local echo.";
1052 let err = EditError::Failure(msg.into());
1053 return Err(err);
1054 };
10511055 let room_id = self.room_id.clone();
1052 let id = IambId::Room(room_id, Some(root));
1056 let id = IambId::Room(room_id, Some(root.to_owned()));
10531057 let open = WindowAction::Switch(OpenTarget::Application(id));
10541058 Ok(vec![(open.into(), ctx.clone())])
10551059 }
@@ -1425,8 +1429,8 @@ impl StatefulWidget for Scrollback<'_> {
14251429 let _ = lines.drain(..n);
14261430 }
14271431
1428 if let Some(((ts, event_id), row, _, _)) = lines.first() {
1429 state.viewctx.corner.timestamp = Some((*ts, event_id.clone()));
1432 if let Some((key, row, _, _)) = lines.first() {
1433 state.viewctx.corner.timestamp = Some((*key).clone());
14301434 state.viewctx.corner.text_row = *row;
14311435 }
14321436
@@ -1434,7 +1438,7 @@ impl StatefulWidget for Scrollback<'_> {
14341438 let x = area.left();
14351439
14361440 let mut image_previews = vec![];
1437 for ((_, _), _, txt, line_preview) in lines.into_iter() {
1441 for (_, _, txt, line_preview) in lines.into_iter() {
14381442 let _ = buf.set_line(x, y, &txt, area.width);
14391443 if let Some((backend, msg_x, _)) = line_preview {
14401444 image_previews.push((x + msg_x, y, backend));
src/worker.rs +126 −2
@@ -13,8 +13,12 @@ use std::time::{Duration, Instant};
1313
1414use futures::{stream::FuturesUnordered, StreamExt};
1515use gethostname::gethostname;
16use matrix_sdk::ruma::events::relation::Thread;
17use matrix_sdk::ruma::events::room::message::Relation;
1618use matrix_sdk::ruma::events::room::MediaSource;
1719use matrix_sdk::ruma::events::sticker::StickerEventContent;
20use matrix_sdk::ruma::events::AnyMessageLikeEventContent;
21use matrix_sdk::send_queue::{LocalEcho, LocalEchoContent, RoomSendQueueUpdate, SendQueueUpdate};
1822use ratatui_image::picker::Picker;
1923use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender};
2024use tokio::sync::Semaphore;
@@ -90,8 +94,9 @@ use matrix_sdk::{
9094use modalkit::errors::UIError;
9195use modalkit::prelude::{EditInfo, InfoMessage};
9296
93use crate::base::MessageNeed;
97use crate::base::{EchoLocation, MessageNeed};
9498use crate::config::ImagePreviewSize;
99use crate::message::{Message, MessageEvent, MessageId, MessageKey};
95100use crate::notifications::register_notifications;
96101use crate::preview::load_image;
97102use crate::{
@@ -523,6 +528,122 @@ async fn send_receipts_forever(client: &Client, store: &AsyncProgramStore) {
523528 }
524529}
525530
531fn insert_local_echo(
532 own_user_id: OwnedUserId,
533 info: &mut RoomInfo,
534 echo: LocalEcho,
535) -> Result<(), serde_json::Error> {
536 let LocalEcho { transaction_id, content } = echo;
537
538 match content {
539 LocalEchoContent::Event { serialized_event, send_handle, .. } => {
540 let content = serialized_event.deserialize()?;
541 let AnyMessageLikeEventContent::RoomMessage(msg) = content else {
542 // XXX: Handle other event types
543 return Ok(());
544 };
545
546 let thread = match msg.relates_to.as_ref() {
547 Some(Relation::Replacement(..)) => {
548 // XXX: Show echo on edited message
549 return Ok(());
550 },
551 Some(Relation::Thread(Thread { event_id, .. })) => Some(event_id.to_owned()),
552 _ => None,
553 };
554
555 let ts = send_handle.created_at.into();
556 let key = MessageKey { ts, id: MessageId::Local(transaction_id.clone()) };
557 let msg = MessageEvent::Local(transaction_id.clone(), send_handle, msg.into());
558 let msg = Message::new(msg, own_user_id, ts);
559
560 info.echo_keys
561 .insert(transaction_id, EchoLocation::Message(thread.clone(), key.clone()));
562
563 let thread = info.get_thread_mut(thread);
564 thread.insert(key, msg);
565 },
566 LocalEchoContent::Redaction { .. } => {
567 // Don't show anything locally for the redaction until the server actually does it.
568 },
569 LocalEchoContent::React { .. } => {
570 // XXX: Handle reactions to local echos
571 },
572 }
573 Ok(())
574}
575
576async fn subscribe_sendqueue_forever(client: &Client, store: &AsyncProgramStore) {
577 let own_user_id = client.user_id().unwrap();
578 let mut receiver = client.send_queue().subscribe();
579
580 // load unsent requests
581 if let Ok(room_echos) = client.send_queue().local_echoes().await {
582 let mut locked = store.lock().await;
583 for (room_id, echos) in room_echos {
584 let info = locked.application.get_room_info(room_id);
585 for echo in echos {
586 let _ = insert_local_echo(own_user_id.to_owned(), info, echo);
587 }
588 }
589 }
590
591 while let Ok(SendQueueUpdate { room_id, update }) = receiver.recv().await {
592 let mut locked = store.lock().await;
593 let info = locked.application.get_room_info(room_id);
594 match update {
595 RoomSendQueueUpdate::NewLocalEvent(echo) => {
596 let _ = insert_local_echo(own_user_id.to_owned(), info, echo);
597 },
598 RoomSendQueueUpdate::ReplacedLocalEvent { transaction_id, new_content } => {
599 let Some(EchoLocation::Message(thread, key)) =
600 info.echo_keys.get(&transaction_id).cloned()
601 else {
602 continue;
603 };
604
605 let Ok(content) = new_content.deserialize() else {
606 continue;
607 };
608 let AnyMessageLikeEventContent::RoomMessage(new_content) = content else {
609 // XXX: Handle other event types
610 continue;
611 };
612
613 let Some(msg) = info.get_thread_mut(thread).get_mut(&key) else {
614 continue;
615 };
616
617 let MessageEvent::Local(_, _, msg) = &mut msg.event else {
618 continue;
619 };
620
621 *msg = new_content.into();
622 },
623
624 RoomSendQueueUpdate::SendError { .. } => {
625 // XXX: Show the error to the user
626 },
627 RoomSendQueueUpdate::CancelledLocalEvent { transaction_id } => {
628 info.echo_keys.remove(&transaction_id);
629 },
630 RoomSendQueueUpdate::SentEvent { transaction_id, event_id } => {
631 if let Some(location) = info.echo_keys.get_mut(&transaction_id) {
632 let location = std::mem::replace(location, EchoLocation::Replaced(event_id));
633
634 if let EchoLocation::Message(thread, key) = location {
635 info.get_thread_mut(thread).remove(&key);
636 }
637 }
638 },
639
640 RoomSendQueueUpdate::RetryEvent { .. } | RoomSendQueueUpdate::MediaUpload { .. } => {
641 // Ignore these events
642 },
643 }
644 }
645}
646
526647pub async fn do_first_sync(client: &Client, store: &AsyncProgramStore) -> Result<(), MatrixError> {
527648 // Perform an initial, lazily-loaded sync.
528649 let mut room = RoomEventFilter::default();
@@ -538,6 +659,8 @@ pub async fn do_first_sync(client: &Client, store: &AsyncProgramStore) -> Result
538659
539660 client.sync_once(settings).await?;
540661
662 client.send_queue().respawn_tasks_for_rooms_with_unsent_requests().await;
663
541664 // Populate sync_info with our initial set of rooms/dms/spaces.
542665 refresh_rooms(client, store).await;
543666
@@ -1267,7 +1390,8 @@ impl ClientWorker {
12671390 let rcpt = send_receipts_forever(&client, &store);
12681391 let room = refresh_rooms_forever(&client, &store);
12691392 let notifications = register_notifications(&client, &settings, &store);
1270 let ((), (), (), ()) = tokio::join!(load, rcpt, room, notifications);
1393 let sendqueue = subscribe_sendqueue_forever(&client, &store);
1394 let ((), (), (), (), ()) = tokio::join!(load, rcpt, room, notifications, sendqueue);
12711395 }
12721396 })
12731397 .into();