Reply to a deleted message shows 'Deleted message' (Reply enum: Quote | Deleted
Browse files at this commit28b542092b20aba1007a914f93f3fec1590824fcParent: 4f81f38- feat
- reply to a deleted message shows 'Deleted message' (Reply enum: Quote | Deleted
- reply_to no longer nulled on delete), and the composer's 'Replying to' bar jumps to the original on click
8 changed files +79 -30
- crates/client/lang/en/message_actions.txt +1 -0
- crates/client/lang/tr/message_actions.txt +1 -0
- crates/client/src/gui/chat.rs +14 -5
- crates/client/src/gui/composer.rs +24 -6
- crates/client/src/gui/message_actions.rs +16 -12
- crates/common/src/model.rs +16 -1
- crates/server/src/db/message.rs +6 -5
- crates/server/src/db/schema.sql +1 -1
crates/client/lang/en/message_actions.txtmodified+1 -0
| @@ -10,3 +10,4 @@ confirm = Confirm | |||
| 10 | delete = Delete | 10 | delete = Delete |
| 11 | send = Send | 11 | send = Send |
| 12 | people = People | 12 | people = People |
| 13 | +deleted = Deleted message | ||
crates/client/lang/tr/message_actions.txtmodified+1 -0
| @@ -10,3 +10,4 @@ confirm = Onayla | |||
| 10 | delete = Sil | 10 | delete = Sil |
| 11 | send = Gönder | 11 | send = Gönder |
| 12 | people = Kişiler | 12 | people = Kişiler |
| 13 | +deleted = Silinmiş mesaj | ||
crates/client/src/gui/chat.rsmodified+14 -5
| @@ -43,7 +43,7 @@ use common::{ | |||
| 43 | model::{ | 43 | model::{ |
| 44 | Account, AdminActionKind, AdminLogEntry, AttachmentInfo, Ban, BanScope, CallLog, Community, | 44 | Account, AdminActionKind, AdminLogEntry, AttachmentInfo, Ban, BanScope, CallLog, Community, |
| 45 | CommunityKind, CommunitySummary, CommunityUsage, DayStat, Friends, Id, Invitation, | 45 | CommunityKind, CommunitySummary, CommunityUsage, DayStat, Friends, Id, Invitation, |
| 46 | - InviteCode, LogEntry, Member, Message, MessageHit, Overview, Presence, Rank, Report, | 46 | + InviteCode, LogEntry, Member, Message, MessageHit, Overview, Presence, Rank, Reply, Report, |
| 47 | ReportStatus, ServerBan, SessionInfo, Unread, Usage, User, VoiceRoom, mentions, | 47 | ReportStatus, ServerBan, SessionInfo, Unread, Usage, User, VoiceRoom, mentions, |
| 48 | }, | 48 | }, |
| 49 | permission, | 49 | permission, |
| @@ -878,8 +878,10 @@ impl Chat { | |||
| 878 | fn quotes_of(&mut self, message_id: Id) -> impl Iterator<Item = &mut common::model::Quote> { | 878 | fn quotes_of(&mut self, message_id: Id) -> impl Iterator<Item = &mut common::model::Quote> { |
| 879 | self.messages | 879 | self.messages |
| 880 | .iter_mut() | 880 | .iter_mut() |
| 881 | - .filter_map(|message| message.reply.as_mut()) | 881 | + .filter_map(move |message| match &mut message.reply { |
| 882 | - .filter(move |quote| quote.message_id == message_id) | 882 | + Some(Reply::Quote(quote)) if quote.message_id == message_id => Some(quote), |
| 883 | + _ => None, | ||
| 884 | + }) | ||
| 883 | } | 885 | } |
| 884 | 886 | ||
| 885 | fn forget_message(&mut self, message_id: Id) { | 887 | fn forget_message(&mut self, message_id: Id) { |
| @@ -888,9 +890,10 @@ impl Chat { | |||
| 888 | if message | 890 | if message |
| 889 | .reply | 891 | .reply |
| 890 | .as_ref() | 892 | .as_ref() |
| 893 | + .and_then(Reply::quote) | ||
| 891 | .is_some_and(|quote| quote.message_id == message_id) | 894 | .is_some_and(|quote| quote.message_id == message_id) |
| 892 | { | 895 | { |
| 893 | - message.reply = None; | 896 | + message.reply = Some(Reply::Deleted); |
| 894 | } | 897 | } |
| 895 | } | 898 | } |
| 896 | 899 | ||
| @@ -1081,7 +1084,13 @@ impl Chat { | |||
| 1081 | .chain(&self.pins) | 1084 | .chain(&self.pins) |
| 1082 | .flat_map(|message| { | 1085 | .flat_map(|message| { |
| 1083 | std::iter::once(message.user_id) | 1086 | std::iter::once(message.user_id) |
| 1084 | - .chain(message.reply.as_ref().map(|quote| quote.user_id)) | 1087 | + .chain( |
| 1088 | + message | ||
| 1089 | + .reply | ||
| 1090 | + .as_ref() | ||
| 1091 | + .and_then(Reply::quote) | ||
| 1092 | + .map(|quote| quote.user_id), | ||
| 1093 | + ) | ||
| 1085 | .chain(message.poll.iter().flat_map(|poll| { | 1094 | .chain(message.poll.iter().flat_map(|poll| { |
| 1086 | poll.options | 1095 | poll.options |
| 1087 | .iter() | 1096 | .iter() |
crates/client/src/gui/composer.rsmodified+24 -6
| @@ -18,7 +18,8 @@ use common::{ | |||
| 18 | }; | 18 | }; |
| 19 | use gpui_kit::{ | 19 | use gpui_kit::{ |
| 20 | Anchor, AnyElement, App, Context, Div, ElementId, Entity, FontWeight, InteractiveElement, | 20 | Anchor, AnyElement, App, Context, Div, ElementId, Entity, FontWeight, InteractiveElement, |
| 21 | - IntoElement, KeyBinding, MouseButton, ParentElement, Styled, Window, actions, | 21 | + IntoElement, KeyBinding, MouseButton, ParentElement, StatefulInteractiveElement as _, Styled, |
| 22 | + Window, actions, | ||
| 22 | assets::IconName, | 23 | assets::IconName, |
| 23 | component::{ | 24 | component::{ |
| 24 | WindowExt, | 25 | WindowExt, |
| @@ -150,15 +151,32 @@ fn reply_bar( | |||
| 150 | .map(super::message_actions::message_text) | 151 | .map(super::message_actions::message_text) |
| 151 | .unwrap_or_default(); | 152 | .unwrap_or_default(); |
| 152 | 153 | ||
| 154 | + let jump = entity.clone(); | ||
| 155 | + | ||
| 153 | bar(palette) | 156 | bar(palette) |
| 154 | - .child(w().composer.replying_to) | ||
| 155 | .child( | 157 | .child( |
| 156 | div() | 158 | div() |
| 157 | - .font_weight(FontWeight::SEMIBOLD) | 159 | + .id("reply_jump") |
| 158 | - .text_color(palette.text) | 160 | + .flex_1() |
| 159 | - .child(author), | 161 | + .min_w_0() |
| 162 | + .flex() | ||
| 163 | + .items_center() | ||
| 164 | + .gap(px(space::SM)) | ||
| 165 | + .cursor_pointer() | ||
| 166 | + .on_click(move |_, window, cx| { | ||
| 167 | + jump.update(cx, |yumush, cx| { | ||
| 168 | + yumush.go_to_message(message_id, window, cx) | ||
| 169 | + }) | ||
| 170 | + }) | ||
| 171 | + .child(w().composer.replying_to) | ||
| 172 | + .child( | ||
| 173 | + div() | ||
| 174 | + .font_weight(FontWeight::SEMIBOLD) | ||
| 175 | + .text_color(palette.text) | ||
| 176 | + .child(author), | ||
| 177 | + ) | ||
| 178 | + .child(div().flex_1().min_w_0().truncate().child(quote)), | ||
| 160 | ) | 179 | ) |
| 161 | - .child(div().flex_1().min_w_0().truncate().child(quote)) | ||
| 162 | .child(cancel_button(entity, palette)) | 180 | .child(cancel_button(entity, palette)) |
| 163 | } | 181 | } |
| 164 | 182 | ||
crates/client/src/gui/message_actions.rsmodified+16 -12
| @@ -4,7 +4,7 @@ use common::model::Id; | |||
| 4 | use common::{ | 4 | use common::{ |
| 5 | call::{Pin, React, ReportMessage, ReportUser}, | 5 | call::{Pin, React, ReportMessage, ReportUser}, |
| 6 | constant::REACTIONS, | 6 | constant::REACTIONS, |
| 7 | - model::{Message, User}, | 7 | + model::{Message, Reply, User}, |
| 8 | }; | 8 | }; |
| 9 | use gpui_kit::{ | 9 | use gpui_kit::{ |
| 10 | Anchor, Context, Div, Entity, Focusable as _, FontWeight, InteractiveElement, IntoElement, | 10 | Anchor, Context, Div, Entity, Focusable as _, FontWeight, InteractiveElement, IntoElement, |
| @@ -158,26 +158,30 @@ pub fn quote_line( | |||
| 158 | entity: &Entity<Yumush>, | 158 | entity: &Entity<Yumush>, |
| 159 | palette: Palette, | 159 | palette: Palette, |
| 160 | ) -> Option<impl IntoElement> { | 160 | ) -> Option<impl IntoElement> { |
| 161 | - let quote = message.reply.as_ref()?; | 161 | + let frame = div() |
| 162 | + .id(format!("quote_{}", message.id)) | ||
| 163 | + .flex() | ||
| 164 | + .items_center() | ||
| 165 | + .gap(px(space::SM)) | ||
| 166 | + .pl(px(space::SM)) | ||
| 167 | + .border_l_2() | ||
| 168 | + .border_color(palette.border) | ||
| 169 | + .text_size(text(text::CAPTION)) | ||
| 170 | + .text_color(palette.muted); | ||
| 171 | + let quote = match message.reply.as_ref()? { | ||
| 172 | + Reply::Quote(quote) => quote, | ||
| 173 | + Reply::Deleted => return Some(frame.italic().child(w().message_actions.deleted)), | ||
| 174 | + }; | ||
| 162 | let author = chat.author(quote.user_id); | 175 | let author = chat.author(quote.user_id); |
| 163 | let target = quote.message_id; | 176 | let target = quote.message_id; |
| 164 | let entity = entity.clone(); | 177 | let entity = entity.clone(); |
| 165 | 178 | ||
| 166 | Some( | 179 | Some( |
| 167 | - div() | 180 | + frame |
| 168 | - .id(format!("quote_{}", message.id)) | ||
| 169 | .cursor_pointer() | 181 | .cursor_pointer() |
| 170 | .on_click(move |_, window, cx| { | 182 | .on_click(move |_, window, cx| { |
| 171 | entity.update(cx, |yumush, cx| yumush.go_to_message(target, window, cx)) | 183 | entity.update(cx, |yumush, cx| yumush.go_to_message(target, window, cx)) |
| 172 | }) | 184 | }) |
| 173 | - .flex() | ||
| 174 | - .items_center() | ||
| 175 | - .gap(px(space::SM)) | ||
| 176 | - .pl(px(space::SM)) | ||
| 177 | - .border_l_2() | ||
| 178 | - .border_color(palette.border) | ||
| 179 | - .text_size(text(text::CAPTION)) | ||
| 180 | - .text_color(palette.muted) | ||
| 181 | .children(author.map(|user| { | 185 | .children(author.map(|user| { |
| 182 | avatar( | 186 | avatar( |
| 183 | palette, | 187 | palette, |
crates/common/src/model.rsmodified+16 -1
| @@ -529,6 +529,21 @@ pub struct Quote { | |||
| 529 | pub attachments: u32, | 529 | pub attachments: u32, |
| 530 | } | 530 | } |
| 531 | 531 | ||
| 532 | +#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)] | ||
| 533 | +pub enum Reply { | ||
| 534 | + Quote(Quote), | ||
| 535 | + Deleted, | ||
| 536 | +} | ||
| 537 | + | ||
| 538 | +impl Reply { | ||
| 539 | + pub fn quote(&self) -> Option<&Quote> { | ||
| 540 | + match self { | ||
| 541 | + Reply::Quote(quote) => Some(quote), | ||
| 542 | + Reply::Deleted => None, | ||
| 543 | + } | ||
| 544 | + } | ||
| 545 | +} | ||
| 546 | + | ||
| 532 | #[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)] | 547 | #[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)] |
| 533 | pub struct SnippetMessage { | 548 | pub struct SnippetMessage { |
| 534 | pub id: Id, | 549 | pub id: Id, |
| @@ -580,7 +595,7 @@ pub struct Message { | |||
| 580 | pub body: String, | 595 | pub body: String, |
| 581 | pub attachments: Vec<Attachment>, | 596 | pub attachments: Vec<Attachment>, |
| 582 | pub reactions: Vec<Reaction>, | 597 | pub reactions: Vec<Reaction>, |
| 583 | - pub reply: Option<Quote>, | 598 | + pub reply: Option<Reply>, |
| 584 | pub snippet: Option<Snippet>, | 599 | pub snippet: Option<Snippet>, |
| 585 | pub poll: Option<Poll>, | 600 | pub poll: Option<Poll>, |
| 586 | pub edited: bool, | 601 | pub edited: bool, |
crates/server/src/db/message.rsmodified+6 -5
| @@ -1,7 +1,7 @@ | |||
| 1 | use common::{ | 1 | use common::{ |
| 2 | constant::{MAXIMUM_FORWARD_MESSAGES, MAXIMUM_QUOTE_LENGTH, MESSAGE_PAGE_LIMIT}, | 2 | constant::{MAXIMUM_FORWARD_MESSAGES, MAXIMUM_QUOTE_LENGTH, MESSAGE_PAGE_LIMIT}, |
| 3 | error::{Error, Field, Problem}, | 3 | error::{Error, Field, Problem}, |
| 4 | - model::{CallLog, Id, Message, MessageHit, Quote, Reaction, SnippetMessage}, | 4 | + model::{CallLog, Id, Message, MessageHit, Quote, Reaction, Reply, SnippetMessage}, |
| 5 | time::now_ms, | 5 | time::now_ms, |
| 6 | }; | 6 | }; |
| 7 | 7 | ||
| @@ -11,7 +11,7 @@ use crate::error::{ServerError, ensure_with}; | |||
| 11 | const SEARCH_LIMIT: u32 = 200; | 11 | const SEARCH_LIMIT: u32 = 200; |
| 12 | const PAGE_LIMIT: u32 = MESSAGE_PAGE_LIMIT as u32; | 12 | const PAGE_LIMIT: u32 = MESSAGE_PAGE_LIMIT as u32; |
| 13 | 13 | ||
| 14 | -const SELECT: &str = "SELECT m.id, m.user_id, m.community_id, m.created_at, m.body, m.edited, r.id, r.user_id, COALESCE(NULLIF(r.body, ''), (SELECT question FROM poll p WHERE p.message_id = r.id), r.body), (SELECT COUNT(*) FROM attachment a WHERE a.message_id = r.id AND a.snippet_position IS NULL), m.call, m.call_seconds, m.pinned FROM message m LEFT JOIN message r ON r.id = m.reply_to"; | 14 | +const SELECT: &str = "SELECT m.id, m.user_id, m.community_id, m.created_at, m.body, m.edited, m.reply_to, r.id, r.user_id, COALESCE(NULLIF(r.body, ''), (SELECT question FROM poll p WHERE p.message_id = r.id), r.body), (SELECT COUNT(*) FROM attachment a WHERE a.message_id = r.id AND a.snippet_position IS NULL), m.call, m.call_seconds, m.pinned FROM message m LEFT JOIN message r ON r.id = m.reply_to"; |
| 15 | 15 | ||
| 16 | fn row(r: &mut Reader) -> Result<Message, ServerError> { | 16 | fn row(r: &mut Reader) -> Result<Message, ServerError> { |
| 17 | let id = r.get()?; | 17 | let id = r.get()?; |
| @@ -20,6 +20,7 @@ fn row(r: &mut Reader) -> Result<Message, ServerError> { | |||
| 20 | let created_at = r.get()?; | 20 | let created_at = r.get()?; |
| 21 | let body = r.get()?; | 21 | let body = r.get()?; |
| 22 | let edited = r.get()?; | 22 | let edited = r.get()?; |
| 23 | + let reply_to: Option<Id> = r.get()?; | ||
| 23 | let reply_id: Option<Id> = r.get()?; | 24 | let reply_id: Option<Id> = r.get()?; |
| 24 | let reply_user_id: Option<Id> = r.get()?; | 25 | let reply_user_id: Option<Id> = r.get()?; |
| 25 | let reply_body: Option<String> = r.get()?; | 26 | let reply_body: Option<String> = r.get()?; |
| @@ -29,13 +30,13 @@ fn row(r: &mut Reader) -> Result<Message, ServerError> { | |||
| 29 | let pinned = r.get()?; | 30 | let pinned = r.get()?; |
| 30 | 31 | ||
| 31 | let reply = match (reply_id, reply_user_id, reply_body) { | 32 | let reply = match (reply_id, reply_user_id, reply_body) { |
| 32 | - (Some(message_id), Some(user_id), Some(body)) => Some(Quote { | 33 | + (Some(message_id), Some(user_id), Some(body)) => Some(Reply::Quote(Quote { |
| 33 | message_id, | 34 | message_id, |
| 34 | user_id, | 35 | user_id, |
| 35 | body: body.chars().take(MAXIMUM_QUOTE_LENGTH).collect(), | 36 | body: body.chars().take(MAXIMUM_QUOTE_LENGTH).collect(), |
| 36 | attachments: reply_attachments, | 37 | attachments: reply_attachments, |
| 37 | - }), | 38 | + })), |
| 38 | - _ => None, | 39 | + _ => reply_to.map(|_| Reply::Deleted), |
| 39 | }; | 40 | }; |
| 40 | 41 | ||
| 41 | Ok(Message { | 42 | Ok(Message { |
crates/server/src/db/schema.sqlmodified+1 -1
| @@ -83,7 +83,7 @@ CREATE TABLE message ( | |||
| 83 | user_id INTEGER NOT NULL REFERENCES user (id) ON DELETE CASCADE, | 83 | user_id INTEGER NOT NULL REFERENCES user (id) ON DELETE CASCADE, |
| 84 | created_at INTEGER NOT NULL, | 84 | created_at INTEGER NOT NULL, |
| 85 | body TEXT NOT NULL, | 85 | body TEXT NOT NULL, |
| 86 | - reply_to INTEGER REFERENCES message (id) ON DELETE SET NULL, | 86 | + reply_to INTEGER, |
| 87 | edited INTEGER NOT NULL DEFAULT 0, | 87 | edited INTEGER NOT NULL DEFAULT 0, |
| 88 | pinned INTEGER NOT NULL DEFAULT 0, | 88 | pinned INTEGER NOT NULL DEFAULT 0, |
| 89 | call TEXT, | 89 | call TEXT, |