BlueGit

ict rusty-teams

feat(chat): show an edit right away with a saving indicator

- the edited text appears at once, the clock shows until the server confirms
- a failed edit restores the old text

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

metis Daniel Däschle · pushed by metis

Authored 2026-11-09 · 3 weeks ago

Hash
c7845d940b1c02e35ed22680ed68257c9317a19c
Parent
bedc3918
1 file changed +25 −1
crates/app/src/views/conversation.rs +25 −1
@@ -231,6 +231,7 @@ pub struct ConversationView {
231 231 rows: Rc<RefCell<Vec<Row>>>,
232 232 current: Option<Current>,
233 233 pending: Vec<MessageRow>,
234 saving_edits: HashSet<String>,
234 235 pending_counter: usize,
235 236 pending_outgoing: HashMap<String, Outgoing>,
236 237 pending_reactions: PendingReactions,
@@ -582,6 +583,7 @@ impl ConversationView {
582 583 rows: Rc::new(RefCell::new(Vec::new())),
583 584 current: None,
584 585 pending: Vec::new(),
586 saving_edits: HashSet::new(),
585 587 pending_counter: 0,
586 588 pending_outgoing: HashMap::new(),
587 589 pending_reactions: HashMap::new(),
@@ -1827,7 +1829,15 @@ impl ConversationView {
1827 1829 }
1828 1830 }
1829 1831
1830 fn apply_rows(&mut self, new_rows: Vec<Row>, reset: bool, cx: &mut Context<Self>) {
1832 fn apply_rows(&mut self, mut new_rows: Vec<Row>, reset: bool, cx: &mut Context<Self>) {
1833 for row in &mut new_rows {
1834 if let Row::Message(message) = row
1835 && message.delivery == Delivery::Delivered
1836 && self.saving_edits.contains(&message.key)
1837 {
1838 message.delivery = Delivery::Sending;
1839 }
1840 }
1831 1841 let old_rows = std::mem::replace(&mut *self.rows.borrow_mut(), new_rows);
1832 1842 self.drop_stale_reaction_details();
1833 1843 let new_len = self.rows.borrow().len();
@@ -3095,6 +3105,15 @@ impl ConversationView {
3095 3105 cx.notify();
3096 3106 return;
3097 3107 };
3108 let original = self.own_record(&edit.message_id, cx);
3109 if let Some(mut record) = original.clone() {
3110 record.body_html = outgoing.html();
3111 record.edited_at = Some(Utc::now());
3112 let _ = store.upsert_messages(std::slice::from_ref(&record));
3113 }
3114 let message_id = edit.message_id.clone();
3115 self.saving_edits.insert(message_id.clone());
3116 self.rebuild(false, cx);
3098 3117 let sent = outgoing.clone();
3099 3118 let receiver = runtime::spawn(async move {
3100 3119 engine
@@ -3109,6 +3128,11 @@ impl ConversationView {
3109 3128 cx.spawn_in(window, async move |this, cx| {
3110 3129 let failed = !matches!(receiver.await, Ok(Ok(())));
3111 3130 this.update_in(cx, |this, window, cx| {
3131 this.saving_edits.remove(&message_id);
3132 if failed && let Some(record) = &original {
3133 let _ = store.upsert_messages(std::slice::from_ref(record));
3134 }
3135 this.rebuild(false, cx);
3112 3136 if failed {
3113 3137 this.show_main_composer(cx);
3114 3138 if this.composer.read(cx).is_empty(cx) {
@@ -231,6 +231,7 @@ pub struct ConversationView {
231 rows: Rc<RefCell<Vec<Row>>>,
231 rows: Rc<RefCell<Vec<Row>>>,
232 current: Option<Current>,
232 current: Option<Current>,
233 pending: Vec<MessageRow>,
233 pending: Vec<MessageRow>,
234 saving_edits: HashSet<String>,
234 pending_counter: usize,
235 pending_counter: usize,
235 pending_outgoing: HashMap<String, Outgoing>,
236 pending_outgoing: HashMap<String, Outgoing>,
236 pending_reactions: PendingReactions,
237 pending_reactions: PendingReactions,
@@ -582,6 +583,7 @@ impl ConversationView {
582 rows: Rc::new(RefCell::new(Vec::new())),
583 rows: Rc::new(RefCell::new(Vec::new())),
583 current: None,
584 current: None,
584 pending: Vec::new(),
585 pending: Vec::new(),
586 saving_edits: HashSet::new(),
585 pending_counter: 0,
587 pending_counter: 0,
586 pending_outgoing: HashMap::new(),
588 pending_outgoing: HashMap::new(),
587 pending_reactions: HashMap::new(),
589 pending_reactions: HashMap::new(),
@@ -1827,7 +1829,15 @@ impl ConversationView {
1827 }
1829 }
1828 }
1830 }
1829
1831
1830 fn apply_rows(&mut self, new_rows: Vec<Row>, reset: bool, cx: &mut Context<Self>) {
1832 fn apply_rows(&mut self, mut new_rows: Vec<Row>, reset: bool, cx: &mut Context<Self>) {
1833 for row in &mut new_rows {
1834 if let Row::Message(message) = row
1835 && message.delivery == Delivery::Delivered
1836 && self.saving_edits.contains(&message.key)
1837 {
1838 message.delivery = Delivery::Sending;
1839 }
1840 }
1831 let old_rows = std::mem::replace(&mut *self.rows.borrow_mut(), new_rows);
1841 let old_rows = std::mem::replace(&mut *self.rows.borrow_mut(), new_rows);
1832 self.drop_stale_reaction_details();
1842 self.drop_stale_reaction_details();
1833 let new_len = self.rows.borrow().len();
1843 let new_len = self.rows.borrow().len();
@@ -3095,6 +3105,15 @@ impl ConversationView {
3095 cx.notify();
3105 cx.notify();
3096 return;
3106 return;
3097 };
3107 };
3108 let original = self.own_record(&edit.message_id, cx);
3109 if let Some(mut record) = original.clone() {
3110 record.body_html = outgoing.html();
3111 record.edited_at = Some(Utc::now());
3112 let _ = store.upsert_messages(std::slice::from_ref(&record));
3113 }
3114 let message_id = edit.message_id.clone();
3115 self.saving_edits.insert(message_id.clone());
3116 self.rebuild(false, cx);
3098 let sent = outgoing.clone();
3117 let sent = outgoing.clone();
3099 let receiver = runtime::spawn(async move {
3118 let receiver = runtime::spawn(async move {
3100 engine
3119 engine
@@ -3109,6 +3128,11 @@ impl ConversationView {
3109 cx.spawn_in(window, async move |this, cx| {
3128 cx.spawn_in(window, async move |this, cx| {
3110 let failed = !matches!(receiver.await, Ok(Ok(())));
3129 let failed = !matches!(receiver.await, Ok(Ok(())));
3111 this.update_in(cx, |this, window, cx| {
3130 this.update_in(cx, |this, window, cx| {
3131 this.saving_edits.remove(&message_id);
3132 if failed && let Some(record) = &original {
3133 let _ = store.upsert_messages(std::slice::from_ref(record));
3134 }
3135 this.rebuild(false, cx);
3112 if failed {
3136 if failed {
3113 this.show_main_composer(cx);
3137 this.show_main_composer(cx);
3114 if this.composer.read(cx).is_empty(cx) {
3138 if this.composer.read(cx).is_empty(cx) {