BlueGit

ict rusty-teams

fix(chat): a sent image keeps showing until the downloaded copy is ready

- Delivery returns the new message id; the local image of the send is kept for that message
- The server row shows the local image while the cached copy is missing or still decoding, and takes its size
- No more "Loading image" box or blank frame between the pending and the sent row

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

metis Daniel Däschle · pushed by metis

Authored 2026-11-11 · 2 weeks ago

Hash
599c5af89cbfbef0e9d8daf3f6d5b23d2e1c5245
Parent
4236dc65
7 files changed +97 −20
crates/app-state/src/outbox.rs +4 −4
@@ -51,9 +51,9 @@ pub fn outgoing_of(record: &OutboxRecord) -> Option<Outgoing> {
51 51 decode(&record.payload, &record.images)
52 52 }
53 53
54 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
54 #[derive(Debug, Clone, PartialEq, Eq)]
55 55 pub enum Delivered {
56 Complete,
56 Complete { message_id: Option<String> },
57 57 /// The post went out but its announcement banner could not be set.
58 58 WithoutBanner,
59 59 }
@@ -122,7 +122,7 @@ pub async fn deliver(
122 122 .attach_link_preview(conversation_id, &record.message_id, preview)
123 123 .await;
124 124 }
125 Ok(Delivered::Complete)
125 Ok(Delivered::Complete { message_id: Some(record.message_id) })
126 126 }
127 127
128 128 fn discard_banner_image(banner: &teams_core::AnnouncementBanner) {
@@ -194,7 +194,7 @@ async fn attempt(
194 194 ) -> teams_core::Result<Delivered> {
195 195 // Graph has no idempotency key: a send cut off by the quit may have gone through.
196 196 if already_sent(engine, record, outgoing).await? {
197 return Ok(Delivered::Complete);
197 return Ok(Delivered::Complete { message_id: None });
198 198 }
199 199 deliver(
200 200 engine,
@@ -51,9 +51,9 @@ pub fn outgoing_of(record: &OutboxRecord) -> Option<Outgoing> {
51 decode(&record.payload, &record.images)
51 decode(&record.payload, &record.images)
52}
52}
53
53
54#[derive(Debug, Clone, Copy, PartialEq, Eq)]
54#[derive(Debug, Clone, PartialEq, Eq)]
55pub enum Delivered {
55pub enum Delivered {
56 Complete,
56 Complete { message_id: Option<String> },
57 /// The post went out but its announcement banner could not be set.
57 /// The post went out but its announcement banner could not be set.
58 WithoutBanner,
58 WithoutBanner,
59}
59}
@@ -122,7 +122,7 @@ pub async fn deliver(
122 .attach_link_preview(conversation_id, &record.message_id, preview)
122 .attach_link_preview(conversation_id, &record.message_id, preview)
123 .await;
123 .await;
124 }
124 }
125 Ok(Delivered::Complete)
125 Ok(Delivered::Complete { message_id: Some(record.message_id) })
126}
126}
127
127
128fn discard_banner_image(banner: &teams_core::AnnouncementBanner) {
128fn discard_banner_image(banner: &teams_core::AnnouncementBanner) {
@@ -194,7 +194,7 @@ async fn attempt(
194) -> teams_core::Result<Delivered> {
194) -> teams_core::Result<Delivered> {
195 // Graph has no idempotency key: a send cut off by the quit may have gone through.
195 // Graph has no idempotency key: a send cut off by the quit may have gone through.
196 if already_sent(engine, record, outgoing).await? {
196 if already_sent(engine, record, outgoing).await? {
197 return Ok(Delivered::Complete);
197 return Ok(Delivered::Complete { message_id: None });
198 }
198 }
199 deliver(
199 deliver(
200 engine,
200 engine,
crates/app-state/src/pending_rows.rs +1 −0
@@ -67,6 +67,7 @@ pub fn pending_row(
67 67 OutgoingImage::Remote(_) => None,
68 68 })
69 69 .collect(),
70 sent_previews: Vec::new(),
70 71 adaptive_cards: Vec::new(),
71 72 link_preview: outgoing.link_preview.clone(),
72 73 meeting_link: teams_core::meeting_link_in_html(&outgoing.html()),
@@ -67,6 +67,7 @@ pub fn pending_row(
67 OutgoingImage::Remote(_) => None,
67 OutgoingImage::Remote(_) => None,
68 })
68 })
69 .collect(),
69 .collect(),
70 sent_previews: Vec::new(),
70 adaptive_cards: Vec::new(),
71 adaptive_cards: Vec::new(),
71 link_preview: outgoing.link_preview.clone(),
72 link_preview: outgoing.link_preview.clone(),
72 meeting_link: teams_core::meeting_link_in_html(&outgoing.html()),
73 meeting_link: teams_core::meeting_link_in_html(&outgoing.html()),
crates/app-state/src/rows.rs +3 −0
@@ -193,6 +193,7 @@ pub struct MessageRow {
193 193 pub reactions: Vec<ReactionChip>,
194 194 pub images: Vec<ImageRef>,
195 195 pub local_images: Vec<LocalImage>,
196 pub sent_previews: Vec<LocalImage>,
196 197 pub files: Vec<FileCard>,
197 198 pub link_preview: Option<LinkPreview>,
198 199 pub meeting_link: Option<String>,
@@ -778,6 +779,7 @@ fn event_row(
778 779 reactions: Vec::new(),
779 780 images: Vec::new(),
780 781 local_images: Vec::new(),
782 sent_previews: Vec::new(),
781 783 files: Vec::new(),
782 784 link_preview: None,
783 785 meeting_link: None,
@@ -910,6 +912,7 @@ fn message_row_with(
910 912 reactions: reaction_chips(&visible_reactions(record, context), context),
911 913 images,
912 914 local_images: Vec::new(),
915 sent_previews: Vec::new(),
913 916 files: files(record),
914 917 link_preview: link_preview(record),
915 918 meeting_link: (!record.deleted)
@@ -193,6 +193,7 @@ pub struct MessageRow {
193 pub reactions: Vec<ReactionChip>,
193 pub reactions: Vec<ReactionChip>,
194 pub images: Vec<ImageRef>,
194 pub images: Vec<ImageRef>,
195 pub local_images: Vec<LocalImage>,
195 pub local_images: Vec<LocalImage>,
196 pub sent_previews: Vec<LocalImage>,
196 pub files: Vec<FileCard>,
197 pub files: Vec<FileCard>,
197 pub link_preview: Option<LinkPreview>,
198 pub link_preview: Option<LinkPreview>,
198 pub meeting_link: Option<String>,
199 pub meeting_link: Option<String>,
@@ -778,6 +779,7 @@ fn event_row(
778 reactions: Vec::new(),
779 reactions: Vec::new(),
779 images: Vec::new(),
780 images: Vec::new(),
780 local_images: Vec::new(),
781 local_images: Vec::new(),
782 sent_previews: Vec::new(),
781 files: Vec::new(),
783 files: Vec::new(),
782 link_preview: None,
784 link_preview: None,
783 meeting_link: None,
785 meeting_link: None,
@@ -910,6 +912,7 @@ fn message_row_with(
910 reactions: reaction_chips(&visible_reactions(record, context), context),
912 reactions: reaction_chips(&visible_reactions(record, context), context),
911 images,
913 images,
912 local_images: Vec::new(),
914 local_images: Vec::new(),
915 sent_previews: Vec::new(),
913 files: files(record),
916 files: files(record),
914 link_preview: link_preview(record),
917 link_preview: link_preview(record),
915 meeting_link: (!record.deleted)
918 meeting_link: (!record.deleted)
crates/app/src/views/attachments.rs +61 −14
@@ -67,8 +67,11 @@ fn declared_size(image: &ImageRef) -> Option<(u32, u32)> {
67 67 image.width.zip(image.height)
68 68 }
69 69
70 pub fn image_size(image: &ImageRef, directory: &Directory) -> (f32, f32) {
71 let loaded = directory.image(&image.url).and_then(|entry| entry.size);
70 fn image_size(image: &ImageRef, directory: &Directory, sent_preview: Option<&LocalImage>) -> (f32, f32) {
71 let loaded = directory
72 .image(&image.url)
73 .and_then(|entry| entry.size)
74 .or_else(|| sent_preview.and_then(|preview| preview.size));
72 75 let max_height = if external_image_url(&image.url).is_some() {
73 76 remote_image::MAX_HEIGHT as f32
74 77 } else {
@@ -77,13 +80,33 @@ pub fn image_size(image: &ImageRef, directory: &Directory) -> (f32, f32) {
77 80 fit_image_within(declared_size(image).or(loaded), max_height)
78 81 }
79 82
83 fn sent_preview<'a>(images: &[ImageRef], position: usize, sent_previews: &'a [LocalImage]) -> Option<&'a LocalImage> {
84 if external_image_url(&images[position].url).is_some() {
85 return None;
86 }
87 let uploaded_before = images[..position]
88 .iter()
89 .filter(|image| external_image_url(&image.url).is_none())
90 .count();
91 sent_previews.get(uploaded_before)
92 }
93
94 fn local_image(image: &LocalImage, id: ElementId) -> Stateful<Img> {
95 img(bounded(image.image.clone()))
96 .id(id)
97 .size_full()
98 .rounded(px(IMAGE_RADIUS))
99 .object_fit(ObjectFit::Cover)
100 }
101
80 102 fn image_view(
81 103 image: &ImageRef,
82 104 id: String,
83 105 directory: &Directory,
84 106 open_image: Option<&ImageActions>,
107 sent_preview: Option<&LocalImage>,
85 108 ) -> AnyElement {
86 let (width, height) = image_size(image, directory);
109 let (width, height) = image_size(image, directory, sent_preview);
87 110 let image_id = ElementId::Name(format!("{id}-image").into());
88 111 let frame = div()
89 112 .id(ElementId::Name(id.into()))
@@ -95,6 +118,9 @@ fn image_view(
95 118 .rounded(px(IMAGE_RADIUS))
96 119 .overflow_hidden();
97 120 let Some(entry) = directory.image(&image.url) else {
121 if let Some(sent) = sent_preview {
122 return frame.child(local_image(sent, image_id)).into_any_element();
123 }
98 124 return frame
99 125 .flex()
100 126 .flex_col()
@@ -118,10 +144,13 @@ fn image_view(
118 144 .cursor_pointer()
119 145 .child(
120 146 img(preview(entry.path.clone()))
121 .id(image_id)
147 .id(image_id.clone())
122 148 .size_full()
123 149 .rounded(px(IMAGE_RADIUS))
124 .object_fit(ObjectFit::Cover),
150 .object_fit(ObjectFit::Cover)
151 .when_some(sent_preview.cloned(), |remote, sent| {
152 remote.with_loading(move || local_image(&sent, image_id.clone()).into_any_element())
153 }),
125 154 )
126 155 .on_click({
127 156 let path = path.clone();
@@ -200,13 +229,7 @@ fn local_image_view(image: &LocalImage, id: String) -> AnyElement {
200 229 .flex_none()
201 230 .rounded(px(IMAGE_RADIUS))
202 231 .overflow_hidden()
203 .child(
204 img(bounded(image.image.clone()))
205 .id(image_id)
206 .size_full()
207 .rounded(px(IMAGE_RADIUS))
208 .object_fit(ObjectFit::Cover),
209 )
232 .child(local_image(image, image_id))
210 233 .into_any_element()
211 234 }
212 235
@@ -423,6 +446,7 @@ pub fn message_body(
423 446 blocks: &[Block],
424 447 images: &[ImageRef],
425 448 local_images: &[LocalImage],
449 sent_previews: &[LocalImage],
426 450 id: &str,
427 451 own: bool,
428 452 directory: &Directory,
@@ -447,6 +471,7 @@ pub fn message_body(
447 471 format!("{key}-image-{position}"),
448 472 directory,
449 473 open_image,
474 sent_preview(images, position, sent_previews),
450 475 )),
451 476 Placement::Local(position) => Some(local_image_view(
452 477 &local_images[position],
@@ -479,6 +504,7 @@ pub fn attachments_view(
479 504 blocks: &[Block],
480 505 images: &[ImageRef],
481 506 local_images: &[LocalImage],
507 sent_previews: &[LocalImage],
482 508 files: &[FileCard],
483 509 id: &str,
484 510 directory: &Directory,
@@ -504,7 +530,13 @@ pub fn attachments_view(
504 530 .gap(px(6.))
505 531 .items_start()
506 532 .children(unplaced_images.into_iter().map(|(index, image)| {
507 image_view(image, format!("{id}-image-{index}"), directory, open_image)
533 image_view(
534 image,
535 format!("{id}-image-{index}"),
536 directory,
537 open_image,
538 sent_preview(images, index, sent_previews),
539 )
508 540 }))
509 541 .children(
510 542 unplaced_local.into_iter().map(|(index, image)| {
@@ -527,8 +559,9 @@ pub fn attachments_view(
527 559 mod tests {
528 560 use super::{
529 561 IMAGE_FALLBACK, Placement, file_subtitle, fit_image, fit_image_within, local_image_index,
530 placement, placements,
562 placement, placements, sent_preview,
531 563 };
564 use crate::rows::LocalImage;
532 565 use crate::render::{Block, TableCell};
533 566 use teams_core::{FileCard, FileKind, ImageRef};
534 567
@@ -546,6 +579,20 @@ mod tests {
546 579 Block::Image { url: url.into() }
547 580 }
548 581
582 #[test]
583 fn sent_previews_follow_the_uploaded_images_and_skip_gifs() {
584 let gif = "https://media.giphy.com/media/x/giphy.gif";
585 let images = [image_ref("hosted-a"), image_ref(gif), image_ref("hosted-b")];
586 let previews: Vec<LocalImage> = [(1, 1), (2, 2)]
587 .into_iter()
588 .map(|size| LocalImage { image: std::sync::Arc::new(gpui_kit::Image::empty()), size: Some(size) })
589 .collect();
590 let size_at = |position| sent_preview(&images, position, &previews).and_then(|preview| preview.size);
591 assert_eq!(size_at(0), Some((1, 1)));
592 assert_eq!(size_at(1), None);
593 assert_eq!(size_at(2), Some((2, 2)));
594 }
595
549 596 #[test]
550 597 fn hosted_content_urls_map_to_zero_based_local_indices() {
551 598 assert_eq!(local_image_index("../hostedContents/2/$value"), Some(1));
@@ -67,8 +67,11 @@ fn declared_size(image: &ImageRef) -> Option<(u32, u32)> {
67 image.width.zip(image.height)
67 image.width.zip(image.height)
68}
68}
69
69
70pub fn image_size(image: &ImageRef, directory: &Directory) -> (f32, f32) {
70fn image_size(image: &ImageRef, directory: &Directory, sent_preview: Option<&LocalImage>) -> (f32, f32) {
71 let loaded = directory.image(&image.url).and_then(|entry| entry.size);
71 let loaded = directory
72 .image(&image.url)
73 .and_then(|entry| entry.size)
74 .or_else(|| sent_preview.and_then(|preview| preview.size));
72 let max_height = if external_image_url(&image.url).is_some() {
75 let max_height = if external_image_url(&image.url).is_some() {
73 remote_image::MAX_HEIGHT as f32
76 remote_image::MAX_HEIGHT as f32
74 } else {
77 } else {
@@ -77,13 +80,33 @@ pub fn image_size(image: &ImageRef, directory: &Directory) -> (f32, f32) {
77 fit_image_within(declared_size(image).or(loaded), max_height)
80 fit_image_within(declared_size(image).or(loaded), max_height)
78}
81}
79
82
83fn sent_preview<'a>(images: &[ImageRef], position: usize, sent_previews: &'a [LocalImage]) -> Option<&'a LocalImage> {
84 if external_image_url(&images[position].url).is_some() {
85 return None;
86 }
87 let uploaded_before = images[..position]
88 .iter()
89 .filter(|image| external_image_url(&image.url).is_none())
90 .count();
91 sent_previews.get(uploaded_before)
92}
93
94fn local_image(image: &LocalImage, id: ElementId) -> Stateful<Img> {
95 img(bounded(image.image.clone()))
96 .id(id)
97 .size_full()
98 .rounded(px(IMAGE_RADIUS))
99 .object_fit(ObjectFit::Cover)
100}
101
80fn image_view(
102fn image_view(
81 image: &ImageRef,
103 image: &ImageRef,
82 id: String,
104 id: String,
83 directory: &Directory,
105 directory: &Directory,
84 open_image: Option<&ImageActions>,
106 open_image: Option<&ImageActions>,
107 sent_preview: Option<&LocalImage>,
85) -> AnyElement {
108) -> AnyElement {
86 let (width, height) = image_size(image, directory);
109 let (width, height) = image_size(image, directory, sent_preview);
87 let image_id = ElementId::Name(format!("{id}-image").into());
110 let image_id = ElementId::Name(format!("{id}-image").into());
88 let frame = div()
111 let frame = div()
89 .id(ElementId::Name(id.into()))
112 .id(ElementId::Name(id.into()))
@@ -95,6 +118,9 @@ fn image_view(
95 .rounded(px(IMAGE_RADIUS))
118 .rounded(px(IMAGE_RADIUS))
96 .overflow_hidden();
119 .overflow_hidden();
97 let Some(entry) = directory.image(&image.url) else {
120 let Some(entry) = directory.image(&image.url) else {
121 if let Some(sent) = sent_preview {
122 return frame.child(local_image(sent, image_id)).into_any_element();
123 }
98 return frame
124 return frame
99 .flex()
125 .flex()
100 .flex_col()
126 .flex_col()
@@ -118,10 +144,13 @@ fn image_view(
118 .cursor_pointer()
144 .cursor_pointer()
119 .child(
145 .child(
120 img(preview(entry.path.clone()))
146 img(preview(entry.path.clone()))
121 .id(image_id)
147 .id(image_id.clone())
122 .size_full()
148 .size_full()
123 .rounded(px(IMAGE_RADIUS))
149 .rounded(px(IMAGE_RADIUS))
124 .object_fit(ObjectFit::Cover),
150 .object_fit(ObjectFit::Cover)
151 .when_some(sent_preview.cloned(), |remote, sent| {
152 remote.with_loading(move || local_image(&sent, image_id.clone()).into_any_element())
153 }),
125 )
154 )
126 .on_click({
155 .on_click({
127 let path = path.clone();
156 let path = path.clone();
@@ -200,13 +229,7 @@ fn local_image_view(image: &LocalImage, id: String) -> AnyElement {
200 .flex_none()
229 .flex_none()
201 .rounded(px(IMAGE_RADIUS))
230 .rounded(px(IMAGE_RADIUS))
202 .overflow_hidden()
231 .overflow_hidden()
203 .child(
232 .child(local_image(image, image_id))
204 img(bounded(image.image.clone()))
205 .id(image_id)
206 .size_full()
207 .rounded(px(IMAGE_RADIUS))
208 .object_fit(ObjectFit::Cover),
209 )
210 .into_any_element()
233 .into_any_element()
211}
234}
212
235
@@ -423,6 +446,7 @@ pub fn message_body(
423 blocks: &[Block],
446 blocks: &[Block],
424 images: &[ImageRef],
447 images: &[ImageRef],
425 local_images: &[LocalImage],
448 local_images: &[LocalImage],
449 sent_previews: &[LocalImage],
426 id: &str,
450 id: &str,
427 own: bool,
451 own: bool,
428 directory: &Directory,
452 directory: &Directory,
@@ -447,6 +471,7 @@ pub fn message_body(
447 format!("{key}-image-{position}"),
471 format!("{key}-image-{position}"),
448 directory,
472 directory,
449 open_image,
473 open_image,
474 sent_preview(images, position, sent_previews),
450 )),
475 )),
451 Placement::Local(position) => Some(local_image_view(
476 Placement::Local(position) => Some(local_image_view(
452 &local_images[position],
477 &local_images[position],
@@ -479,6 +504,7 @@ pub fn attachments_view(
479 blocks: &[Block],
504 blocks: &[Block],
480 images: &[ImageRef],
505 images: &[ImageRef],
481 local_images: &[LocalImage],
506 local_images: &[LocalImage],
507 sent_previews: &[LocalImage],
482 files: &[FileCard],
508 files: &[FileCard],
483 id: &str,
509 id: &str,
484 directory: &Directory,
510 directory: &Directory,
@@ -504,7 +530,13 @@ pub fn attachments_view(
504 .gap(px(6.))
530 .gap(px(6.))
505 .items_start()
531 .items_start()
506 .children(unplaced_images.into_iter().map(|(index, image)| {
532 .children(unplaced_images.into_iter().map(|(index, image)| {
507 image_view(image, format!("{id}-image-{index}"), directory, open_image)
533 image_view(
534 image,
535 format!("{id}-image-{index}"),
536 directory,
537 open_image,
538 sent_preview(images, index, sent_previews),
539 )
508 }))
540 }))
509 .children(
541 .children(
510 unplaced_local.into_iter().map(|(index, image)| {
542 unplaced_local.into_iter().map(|(index, image)| {
@@ -527,8 +559,9 @@ pub fn attachments_view(
527mod tests {
559mod tests {
528 use super::{
560 use super::{
529 IMAGE_FALLBACK, Placement, file_subtitle, fit_image, fit_image_within, local_image_index,
561 IMAGE_FALLBACK, Placement, file_subtitle, fit_image, fit_image_within, local_image_index,
530 placement, placements,
562 placement, placements, sent_preview,
531 };
563 };
564 use crate::rows::LocalImage;
532 use crate::render::{Block, TableCell};
565 use crate::render::{Block, TableCell};
533 use teams_core::{FileCard, FileKind, ImageRef};
566 use teams_core::{FileCard, FileKind, ImageRef};
534
567
@@ -546,6 +579,20 @@ mod tests {
546 Block::Image { url: url.into() }
579 Block::Image { url: url.into() }
547 }
580 }
548
581
582 #[test]
583 fn sent_previews_follow_the_uploaded_images_and_skip_gifs() {
584 let gif = "https://media.giphy.com/media/x/giphy.gif";
585 let images = [image_ref("hosted-a"), image_ref(gif), image_ref("hosted-b")];
586 let previews: Vec<LocalImage> = [(1, 1), (2, 2)]
587 .into_iter()
588 .map(|size| LocalImage { image: std::sync::Arc::new(gpui_kit::Image::empty()), size: Some(size) })
589 .collect();
590 let size_at = |position| sent_preview(&images, position, &previews).and_then(|preview| preview.size);
591 assert_eq!(size_at(0), Some((1, 1)));
592 assert_eq!(size_at(1), None);
593 assert_eq!(size_at(2), Some((2, 2)));
594 }
595
549 #[test]
596 #[test]
550 fn hosted_content_urls_map_to_zero_based_local_indices() {
597 fn hosted_content_urls_map_to_zero_based_local_indices() {
551 assert_eq!(local_image_index("../hostedContents/2/$value"), Some(1));
598 assert_eq!(local_image_index("../hostedContents/2/$value"), Some(1));
crates/app/src/views/conversation.rs +24 −2
@@ -1,5 +1,5 @@
1 1 use std::cell::{Cell, RefCell};
2 use std::collections::{HashMap, HashSet};
2 use std::collections::{HashMap, HashSet, VecDeque};
3 3 use std::path::{Path, PathBuf};
4 4 use std::rc::Rc;
5 5 use std::time::{Duration, Instant};
@@ -92,7 +92,7 @@ use crate::people::{local_names, resolve_names};
92 92 use crate::reaction_model::UNKNOWN_REACTOR;
93 93 use crate::read_state::{ReadTrigger, missed_before_fetch, plan_read};
94 94 use crate::rows::{
95 Delivery, MessageRow, PendingReactions, Receipt, Row, RowContext, StartInfo, api_reaction,
95 Delivery, LocalImage, MessageRow, PendingReactions, Receipt, Row, RowContext, StartInfo, api_reaction,
96 96 apply_pending_reactions, assign_series, changed_indices, diff_keys, flat_rows,
97 97 forward_sender_ids, has_own_reaction, message_draft, message_text, own_reaction_glyph,
98 98 place_local_rows, placeholder_rows, reaction_glyph, reply_excerpt, set_own_reaction,
@@ -115,6 +115,7 @@ pub const MEMBERS_BUTTON: &str = "shell/islands/main/members-button";
115 115 pub const HEADER_DIVIDER: &str = "shell/islands/main/divider-header";
116 116 pub const TIMELINE_TAG: &str = "shell/islands/main/timeline";
117 117 pub const FEED_EDGE_TAG: &str = "shell/islands/main/timeline/divider-feed";
118 const SENT_PREVIEWS_KEPT: usize = 16;
118 119 const POSTED_WITHOUT_BANNER: &str = "Posted, but Teams did not take the banner.";
119 120 const QUIET_RETRY_DELAYS: [Duration; 3] = [
120 121 Duration::from_secs(2),
@@ -243,6 +244,7 @@ pub struct ConversationView {
243 244 saving_edits: HashSet<String>,
244 245 pending_counter: usize,
245 246 pending_outgoing: HashMap<String, Outgoing>,
247 sent_previews: VecDeque<(String, Vec<LocalImage>)>,
246 248 pending_reactions: PendingReactions,
247 249 downloads: Downloads,
248 250 hovered_message: Option<String>,
@@ -597,6 +599,7 @@ impl ConversationView {
597 599 saving_edits: HashSet::new(),
598 600 pending_counter: 0,
599 601 pending_outgoing: HashMap::new(),
602 sent_previews: VecDeque::new(),
600 603 pending_reactions: HashMap::new(),
601 604 downloads: Downloads::default(),
602 605 hovered_message: None,
@@ -1842,6 +1845,9 @@ impl ConversationView {
1842 1845 {
1843 1846 message.receipt = receipts.get(&message.key).copied().unwrap_or_default();
1844 1847 message.receipt_label = receipt_labels.get(&message.key).cloned();
1848 if let Some((_, previews)) = self.sent_previews.iter().find(|(key, _)| key == &message.key) {
1849 message.sent_previews = previews.clone();
1850 }
1845 1851 }
1846 1852 }
1847 1853 if let Some(read_until) = posts_new_after.filter(|_| in_feed) {
@@ -3528,6 +3534,9 @@ impl ConversationView {
3528 3534 if matches!(result, Ok(Ok(Delivered::WithoutBanner))) {
3529 3535 self.notice = Some(POSTED_WITHOUT_BANNER.to_owned());
3530 3536 }
3537 if let Ok(Ok(Delivered::Complete { message_id: Some(message_id) })) = &result {
3538 self.keep_sent_previews(key, message_id);
3539 }
3531 3540 let failure = match result {
3532 3541 Ok(Ok(_)) => None,
3533 3542 Ok(Err(error)) => Some(short_error(&error)),
@@ -3553,6 +3562,19 @@ impl ConversationView {
3553 3562 self.rebuild(false, cx);
3554 3563 }
3555 3564
3565 fn keep_sent_previews(&mut self, pending_key: &str, message_id: &str) {
3566 let Some(row) = self.pending.iter().find(|row| row.key == pending_key) else {
3567 return;
3568 };
3569 if row.local_images.is_empty() {
3570 return;
3571 }
3572 self.sent_previews.push_back((message_id.to_owned(), row.local_images.clone()));
3573 if self.sent_previews.len() > SENT_PREVIEWS_KEPT {
3574 self.sent_previews.pop_front();
3575 }
3576 }
3577
3556 3578 fn render_drop_overlay(&self, cx: &mut Context<Self>) -> impl IntoElement {
3557 3579 let target = match self.current.as_ref().map(|current| &current.selection) {
3558 3580 Some(Selection::Chat(_)) => DropTarget::Chat,
@@ -1,5 +1,5 @@
1use std::cell::{Cell, RefCell};
1use std::cell::{Cell, RefCell};
2use std::collections::{HashMap, HashSet};
2use std::collections::{HashMap, HashSet, VecDeque};
3use std::path::{Path, PathBuf};
3use std::path::{Path, PathBuf};
4use std::rc::Rc;
4use std::rc::Rc;
5use std::time::{Duration, Instant};
5use std::time::{Duration, Instant};
@@ -92,7 +92,7 @@ use crate::people::{local_names, resolve_names};
92use crate::reaction_model::UNKNOWN_REACTOR;
92use crate::reaction_model::UNKNOWN_REACTOR;
93use crate::read_state::{ReadTrigger, missed_before_fetch, plan_read};
93use crate::read_state::{ReadTrigger, missed_before_fetch, plan_read};
94use crate::rows::{
94use crate::rows::{
95 Delivery, MessageRow, PendingReactions, Receipt, Row, RowContext, StartInfo, api_reaction,
95 Delivery, LocalImage, MessageRow, PendingReactions, Receipt, Row, RowContext, StartInfo, api_reaction,
96 apply_pending_reactions, assign_series, changed_indices, diff_keys, flat_rows,
96 apply_pending_reactions, assign_series, changed_indices, diff_keys, flat_rows,
97 forward_sender_ids, has_own_reaction, message_draft, message_text, own_reaction_glyph,
97 forward_sender_ids, has_own_reaction, message_draft, message_text, own_reaction_glyph,
98 place_local_rows, placeholder_rows, reaction_glyph, reply_excerpt, set_own_reaction,
98 place_local_rows, placeholder_rows, reaction_glyph, reply_excerpt, set_own_reaction,
@@ -115,6 +115,7 @@ pub const MEMBERS_BUTTON: &str = "shell/islands/main/members-button";
115pub const HEADER_DIVIDER: &str = "shell/islands/main/divider-header";
115pub const HEADER_DIVIDER: &str = "shell/islands/main/divider-header";
116pub const TIMELINE_TAG: &str = "shell/islands/main/timeline";
116pub const TIMELINE_TAG: &str = "shell/islands/main/timeline";
117pub const FEED_EDGE_TAG: &str = "shell/islands/main/timeline/divider-feed";
117pub const FEED_EDGE_TAG: &str = "shell/islands/main/timeline/divider-feed";
118const SENT_PREVIEWS_KEPT: usize = 16;
118const POSTED_WITHOUT_BANNER: &str = "Posted, but Teams did not take the banner.";
119const POSTED_WITHOUT_BANNER: &str = "Posted, but Teams did not take the banner.";
119const QUIET_RETRY_DELAYS: [Duration; 3] = [
120const QUIET_RETRY_DELAYS: [Duration; 3] = [
120 Duration::from_secs(2),
121 Duration::from_secs(2),
@@ -243,6 +244,7 @@ pub struct ConversationView {
243 saving_edits: HashSet<String>,
244 saving_edits: HashSet<String>,
244 pending_counter: usize,
245 pending_counter: usize,
245 pending_outgoing: HashMap<String, Outgoing>,
246 pending_outgoing: HashMap<String, Outgoing>,
247 sent_previews: VecDeque<(String, Vec<LocalImage>)>,
246 pending_reactions: PendingReactions,
248 pending_reactions: PendingReactions,
247 downloads: Downloads,
249 downloads: Downloads,
248 hovered_message: Option<String>,
250 hovered_message: Option<String>,
@@ -597,6 +599,7 @@ impl ConversationView {
597 saving_edits: HashSet::new(),
599 saving_edits: HashSet::new(),
598 pending_counter: 0,
600 pending_counter: 0,
599 pending_outgoing: HashMap::new(),
601 pending_outgoing: HashMap::new(),
602 sent_previews: VecDeque::new(),
600 pending_reactions: HashMap::new(),
603 pending_reactions: HashMap::new(),
601 downloads: Downloads::default(),
604 downloads: Downloads::default(),
602 hovered_message: None,
605 hovered_message: None,
@@ -1842,6 +1845,9 @@ impl ConversationView {
1842 {
1845 {
1843 message.receipt = receipts.get(&message.key).copied().unwrap_or_default();
1846 message.receipt = receipts.get(&message.key).copied().unwrap_or_default();
1844 message.receipt_label = receipt_labels.get(&message.key).cloned();
1847 message.receipt_label = receipt_labels.get(&message.key).cloned();
1848 if let Some((_, previews)) = self.sent_previews.iter().find(|(key, _)| key == &message.key) {
1849 message.sent_previews = previews.clone();
1850 }
1845 }
1851 }
1846 }
1852 }
1847 if let Some(read_until) = posts_new_after.filter(|_| in_feed) {
1853 if let Some(read_until) = posts_new_after.filter(|_| in_feed) {
@@ -3528,6 +3534,9 @@ impl ConversationView {
3528 if matches!(result, Ok(Ok(Delivered::WithoutBanner))) {
3534 if matches!(result, Ok(Ok(Delivered::WithoutBanner))) {
3529 self.notice = Some(POSTED_WITHOUT_BANNER.to_owned());
3535 self.notice = Some(POSTED_WITHOUT_BANNER.to_owned());
3530 }
3536 }
3537 if let Ok(Ok(Delivered::Complete { message_id: Some(message_id) })) = &result {
3538 self.keep_sent_previews(key, message_id);
3539 }
3531 let failure = match result {
3540 let failure = match result {
3532 Ok(Ok(_)) => None,
3541 Ok(Ok(_)) => None,
3533 Ok(Err(error)) => Some(short_error(&error)),
3542 Ok(Err(error)) => Some(short_error(&error)),
@@ -3553,6 +3562,19 @@ impl ConversationView {
3553 self.rebuild(false, cx);
3562 self.rebuild(false, cx);
3554 }
3563 }
3555
3564
3565 fn keep_sent_previews(&mut self, pending_key: &str, message_id: &str) {
3566 let Some(row) = self.pending.iter().find(|row| row.key == pending_key) else {
3567 return;
3568 };
3569 if row.local_images.is_empty() {
3570 return;
3571 }
3572 self.sent_previews.push_back((message_id.to_owned(), row.local_images.clone()));
3573 if self.sent_previews.len() > SENT_PREVIEWS_KEPT {
3574 self.sent_previews.pop_front();
3575 }
3576 }
3577
3556 fn render_drop_overlay(&self, cx: &mut Context<Self>) -> impl IntoElement {
3578 fn render_drop_overlay(&self, cx: &mut Context<Self>) -> impl IntoElement {
3557 let target = match self.current.as_ref().map(|current| &current.selection) {
3579 let target = match self.current.as_ref().map(|current| &current.selection) {
3558 Some(Selection::Chat(_)) => DropTarget::Chat,
3580 Some(Selection::Chat(_)) => DropTarget::Chat,
crates/app/src/views/message_row.rs +2 −0
@@ -303,6 +303,7 @@ fn bubble(
303 303 &row.blocks,
304 304 &row.images,
305 305 &row.local_images,
306 &row.sent_previews,
306 307 &row.files,
307 308 &format!("message-{index}"),
308 309 directory,
@@ -327,6 +328,7 @@ fn bubble(
327 328 padded_blocks.as_deref().unwrap_or(&row.blocks),
328 329 &row.images,
329 330 &row.local_images,
331 &row.sent_previews,
330 332 &format!("message-{index}"),
331 333 own,
332 334 directory,
@@ -303,6 +303,7 @@ fn bubble(
303 &row.blocks,
303 &row.blocks,
304 &row.images,
304 &row.images,
305 &row.local_images,
305 &row.local_images,
306 &row.sent_previews,
306 &row.files,
307 &row.files,
307 &format!("message-{index}"),
308 &format!("message-{index}"),
308 directory,
309 directory,
@@ -327,6 +328,7 @@ fn bubble(
327 padded_blocks.as_deref().unwrap_or(&row.blocks),
328 padded_blocks.as_deref().unwrap_or(&row.blocks),
328 &row.images,
329 &row.images,
329 &row.local_images,
330 &row.local_images,
331 &row.sent_previews,
330 &format!("message-{index}"),
332 &format!("message-{index}"),
331 own,
333 own,
332 directory,
334 directory,
crates/app/src/views/post_card.rs +2 −0
@@ -117,6 +117,7 @@ fn message_content(
117 117 &row.blocks,
118 118 &row.images,
119 119 &row.local_images,
120 &row.sent_previews,
120 121 &format!("message-{index}"),
121 122 false,
122 123 directory,
@@ -129,6 +130,7 @@ fn message_content(
129 130 &row.blocks,
130 131 &row.images,
131 132 &row.local_images,
133 &row.sent_previews,
132 134 &row.files,
133 135 &format!("message-{index}"),
134 136 directory,
@@ -117,6 +117,7 @@ fn message_content(
117 &row.blocks,
117 &row.blocks,
118 &row.images,
118 &row.images,
119 &row.local_images,
119 &row.local_images,
120 &row.sent_previews,
120 &format!("message-{index}"),
121 &format!("message-{index}"),
121 false,
122 false,
122 directory,
123 directory,
@@ -129,6 +130,7 @@ fn message_content(
129 &row.blocks,
130 &row.blocks,
130 &row.images,
131 &row.images,
131 &row.local_images,
132 &row.local_images,
133 &row.sent_previews,
132 &row.files,
134 &row.files,
133 &format!("message-{index}"),
135 &format!("message-{index}"),
134 directory,
136 directory,