BlueGit

ict rusty-teams

fix(chat): no jump when a message with a link preview is sent

- The preview is written to the local message before the server PUT, so the sent row has it at once
- The send completes right after the POST; the preview PUT runs on its own, so the pending row no longer sits beside the sent one

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-11-17 · 2 weeks ago

Hash
72edd8242b1947c116563f4b376b6cda03ee87a3
Parent
51f7fbe9
2 files changed +21 −10
crates/app-state/src/outbox.rs +20 −8
@@ -1,4 +1,5 @@
1 1 use std::collections::HashMap;
2 use std::sync::Arc;
2 3 use std::time::Duration;
3 4
4 5 use chrono::{DateTime, Utc};
@@ -61,7 +62,7 @@ pub enum Delivered {
61 62 }
62 63
63 64 pub async fn deliver(
64 engine: &Engine,
65 engine: &Arc<Engine>,
65 66 conversation_id: &str,
66 67 target: OutboxTarget,
67 68 thread_root_id: Option<&str>,
@@ -121,10 +122,17 @@ pub async fn deliver(
121 122 .await
122 123 }
123 124 }?;
124 if let Some(preview) = &outgoing.link_preview {
125 let _ = engine
126 .attach_link_preview(conversation_id, &record.message_id, preview)
127 .await;
125 if let Some(preview) = outgoing.link_preview.clone() {
126 let (engine, conversation_id, message_id) = (
127 engine.clone(),
128 conversation_id.to_owned(),
129 record.message_id.clone(),
130 );
131 runtime::handle().spawn(async move {
132 let _ = engine
133 .attach_link_preview(&conversation_id, &message_id, &preview)
134 .await;
135 });
128 136 }
129 137 Ok(Delivered::Complete {
130 138 message_id: Some(record.message_id),
@@ -194,7 +202,7 @@ async fn already_sent(
194 202 }
195 203
196 204 async fn attempt(
197 engine: &Engine,
205 engine: &Arc<Engine>,
198 206 record: &OutboxRecord,
199 207 outgoing: &Outgoing,
200 208 ) -> teams_core::Result<Delivered> {
@@ -212,7 +220,11 @@ async fn attempt(
212 220 .await
213 221 }
214 222
215 async fn resend(engine: &Engine, record: &OutboxRecord, outgoing: &Outgoing) -> Result<(), String> {
223 async fn resend(
224 engine: &Arc<Engine>,
225 record: &OutboxRecord,
226 outgoing: &Outgoing,
227 ) -> Result<(), String> {
216 228 let mut failure = String::new();
217 229 for attempt_number in 0..=RETRY_BACKOFF.len() {
218 230 if let Some(delay) = attempt_number
@@ -230,7 +242,7 @@ async fn resend(engine: &Engine, record: &OutboxRecord, outgoing: &Outgoing) ->
230 242 Err(failure)
231 243 }
232 244
233 async fn resend_record(engine: &Engine, record: OutboxRecord) {
245 async fn resend_record(engine: &Arc<Engine>, record: OutboxRecord) {
234 246 let store = engine.store();
235 247 let outcome = match outgoing_of(&record) {
236 248 Some(outgoing) => resend(engine, &record, &outgoing).await,
@@ -1,4 +1,5 @@
1use std::collections::HashMap;
1use std::collections::HashMap;
2use std::sync::Arc;
2use std::time::Duration;
3use std::time::Duration;
3
4
4use chrono::{DateTime, Utc};
5use chrono::{DateTime, Utc};
@@ -61,7 +62,7 @@ pub enum Delivered {
61}
62}
62
63
63pub async fn deliver(
64pub async fn deliver(
64 engine: &Engine,
65 engine: &Arc<Engine>,
65 conversation_id: &str,
66 conversation_id: &str,
66 target: OutboxTarget,
67 target: OutboxTarget,
67 thread_root_id: Option<&str>,
68 thread_root_id: Option<&str>,
@@ -121,10 +122,17 @@ pub async fn deliver(
121 .await
122 .await
122 }
123 }
123 }?;
124 }?;
124 if let Some(preview) = &outgoing.link_preview {
125 if let Some(preview) = outgoing.link_preview.clone() {
125 let _ = engine
126 let (engine, conversation_id, message_id) = (
126 .attach_link_preview(conversation_id, &record.message_id, preview)
127 engine.clone(),
127 .await;
128 conversation_id.to_owned(),
129 record.message_id.clone(),
130 );
131 runtime::handle().spawn(async move {
132 let _ = engine
133 .attach_link_preview(&conversation_id, &message_id, &preview)
134 .await;
135 });
128 }
136 }
129 Ok(Delivered::Complete {
137 Ok(Delivered::Complete {
130 message_id: Some(record.message_id),
138 message_id: Some(record.message_id),
@@ -194,7 +202,7 @@ async fn already_sent(
194}
202}
195
203
196async fn attempt(
204async fn attempt(
197 engine: &Engine,
205 engine: &Arc<Engine>,
198 record: &OutboxRecord,
206 record: &OutboxRecord,
199 outgoing: &Outgoing,
207 outgoing: &Outgoing,
200) -> teams_core::Result<Delivered> {
208) -> teams_core::Result<Delivered> {
@@ -212,7 +220,11 @@ async fn attempt(
212 .await
220 .await
213}
221}
214
222
215async fn resend(engine: &Engine, record: &OutboxRecord, outgoing: &Outgoing) -> Result<(), String> {
223async fn resend(
224 engine: &Arc<Engine>,
225 record: &OutboxRecord,
226 outgoing: &Outgoing,
227) -> Result<(), String> {
216 let mut failure = String::new();
228 let mut failure = String::new();
217 for attempt_number in 0..=RETRY_BACKOFF.len() {
229 for attempt_number in 0..=RETRY_BACKOFF.len() {
218 if let Some(delay) = attempt_number
230 if let Some(delay) = attempt_number
@@ -230,7 +242,7 @@ async fn resend(engine: &Engine, record: &OutboxRecord, outgoing: &Outgoing) ->
230 Err(failure)
242 Err(failure)
231}
243}
232
244
233async fn resend_record(engine: &Engine, record: OutboxRecord) {
245async fn resend_record(engine: &Arc<Engine>, record: OutboxRecord) {
234 let store = engine.store();
246 let store = engine.store();
235 let outcome = match outgoing_of(&record) {
247 let outcome = match outgoing_of(&record) {
236 Some(outgoing) => resend(engine, &record, &outgoing).await,
248 Some(outgoing) => resend(engine, &record, &outgoing).await,
crates/core/src/actions.rs +1 −2
@@ -441,14 +441,13 @@ impl<R: Remote> SyncEngine<R> {
441 441 ) -> Result<()> {
442 442 let target = self.message_target(conversation_id, message_id)?;
443 443 let links_json = preview.links_json();
444 self.remote.set_message_links(&target, &links_json).await?;
445 444 if self
446 445 .store
447 446 .set_message_links(conversation_id, message_id, &links_json)?
448 447 {
449 448 self.announce(conversation_id, true);
450 449 }
451 Ok(())
450 self.remote.set_message_links(&target, &links_json).await
452 451 }
453 452
454 453 pub async fn mark_read(&self, conversation_id: &str) -> Result<()> {
@@ -441,14 +441,13 @@ impl<R: Remote> SyncEngine<R> {
441 ) -> Result<()> {
441 ) -> Result<()> {
442 let target = self.message_target(conversation_id, message_id)?;
442 let target = self.message_target(conversation_id, message_id)?;
443 let links_json = preview.links_json();
443 let links_json = preview.links_json();
444 self.remote.set_message_links(&target, &links_json).await?;
445 if self
444 if self
446 .store
445 .store
447 .set_message_links(conversation_id, message_id, &links_json)?
446 .set_message_links(conversation_id, message_id, &links_json)?
448 {
447 {
449 self.announce(conversation_id, true);
448 self.announce(conversation_id, true);
450 }
449 }
451 Ok(())
450 self.remote.set_message_links(&target, &links_json).await
452 }
451 }
453
452
454 pub async fn mark_read(&self, conversation_id: &str) -> Result<()> {
453 pub async fn mark_read(&self, conversation_id: &str) -> Result<()> {