forge
Explore
Log in

Don't you dare go Hollow

Reply quotes: multi-line bodies spilled over the chat (whitespace now flattened to one line), clicking a quote jumps to the message, and quotes follow edits / vanish on delete like the server's ON DELETE SET NULL

Browse files at this commit

4f81f38e4d6e883e786adfeee3afbde53cf4ba02Ahmet Kaan GümüşParent: 787d3e8
  • fix
    • reply quotes: multi-line bodies spilled over the chat (whitespace now flattened to one line), clicking a quote jumps to the message, and quotes follow edits / vanish on delete like the server's ON DELETE SET NULL
Show full message
🐛 fix: reply quotes: multi-line bodies spilled over the chat (whitespace now flattened to one line), clicking a quote jumps to the message, and quotes follow edits / vanish on delete like the server's ON DELETE SET NULL
crates/client/src/gui/chat.rsmodified+25 -2
@@ -660,7 +660,14 @@ impl Chat {
660 .iter_mut()660 .iter_mut()
661 .find(|existing| existing.id == message.id)661 .find(|existing| existing.id == message.id)
662 {662 {
663- *existing = message;663+ *existing = message.clone();
664+ }
665+ let body = match &message.poll {
666+ Some(poll) if message.body.is_empty() => poll.question.clone(),
667+ _ => message.body.clone(),
668+ };
669+ for quote in self.quotes_of(message.id) {
670+ quote.body = body.clone();
664 }671 }
665 }672 }
666 }673 }
@@ -868,8 +875,24 @@ impl Chat {
868 .any(|community| community.id == community_id)875 .any(|community| community.id == community_id)
869 }876 }
870 877
878+ fn quotes_of(&mut self, message_id: Id) -> impl Iterator<Item = &mut common::model::Quote> {
879+ self.messages
880+ .iter_mut()
881+ .filter_map(|message| message.reply.as_mut())
882+ .filter(move |quote| quote.message_id == message_id)
883+ }
884+
871 fn forget_message(&mut self, message_id: Id) {885 fn forget_message(&mut self, message_id: Id) {
872 self.messages.retain(|existing| existing.id != message_id);886 self.messages.retain(|existing| existing.id != message_id);
887+ for message in &mut self.messages {
888+ if message
889+ .reply
890+ .as_ref()
891+ .is_some_and(|quote| quote.message_id == message_id)
892+ {
893+ message.reply = None;
894+ }
895+ }
873 896
874 match &mut self.composer {897 match &mut self.composer {
875 Composer::Select { ids } => ids.retain(|id| *id != message_id),898 Composer::Select { ids } => ids.retain(|id| *id != message_id),
@@ -3619,7 +3642,7 @@ fn render_message(
3619 .flex()3642 .flex()
3620 .flex_col()3643 .flex_col()
3621 .gap(px(space::SM))3644 .gap(px(space::SM))
3622- .children(message_actions::quote_line(message, chat, palette))3645+ .children(message_actions::quote_line(message, chat, entity, palette))
3623 .when(!message.body.is_empty(), |this| {3646 .when(!message.body.is_empty(), |this| {
3624 this.child(3647 this.child(
3625 div()3648 div()
crates/client/src/gui/message_actions.rsmodified+15 -3
@@ -138,10 +138,10 @@ pub fn react_popover(
138 }138 }
139 139
140 pub fn quote_text(body: &str, attachments: u32) -> String {140 pub fn quote_text(body: &str, attachments: u32) -> String {
141- if body.is_empty() {141+ if body.trim().is_empty() {
142 w().message_actions.attachments(attachments)142 w().message_actions.attachments(attachments)
143 } else {143 } else {
144- body.to_string()144+ body.split_whitespace().collect::<Vec<_>>().join(" ")
145 }145 }
146 }146 }
147 147
@@ -152,12 +152,24 @@ pub fn message_text(message: &Message) -> String {
152 }152 }
153 }153 }
154 154
155-pub fn quote_line(message: &Message, chat: &Chat, palette: Palette) -> Option<impl IntoElement> {155+pub fn quote_line(
156+ message: &Message,
157+ chat: &Chat,
158+ entity: &Entity<Yumush>,
159+ palette: Palette,
160+) -> Option<impl IntoElement> {
156 let quote = message.reply.as_ref()?;161 let quote = message.reply.as_ref()?;
157 let author = chat.author(quote.user_id);162 let author = chat.author(quote.user_id);
163+ let target = quote.message_id;
164+ let entity = entity.clone();
158 165
159 Some(166 Some(
160 div()167 div()
168+ .id(format!("quote_{}", message.id))
169+ .cursor_pointer()
170+ .on_click(move |_, window, cx| {
171+ entity.update(cx, |yumush, cx| yumush.go_to_message(target, window, cx))
172+ })
161 .flex()173 .flex()
162 .items_center()174 .items_center()
163 .gap(px(space::SM))175 .gap(px(space::SM))