From 28b542092b20aba1007a914f93f3fec1590824fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sun, 29 Nov 2026 07:48:23 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20reply=20to=20a=20deleted=20?= =?UTF-8?q?message=20shows=20'Deleted=20message'=20(Reply=20enum:=20Quote?= =?UTF-8?q?=20|=20Deleted;=20reply=5Fto=20no=20longer=20nulled=20on=20dele?= =?UTF-8?q?te),=20and=20the=20composer's=20'Replying=20to'=20bar=20jumps?= =?UTF-8?q?=20to=20the=20original=20on=20click?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/client/lang/en/message_actions.txt | 1 + crates/client/lang/tr/message_actions.txt | 1 + crates/client/src/gui/chat.rs | 19 ++++++++++---- crates/client/src/gui/composer.rs | 30 ++++++++++++++++++----- crates/client/src/gui/message_actions.rs | 28 ++++++++++++--------- crates/common/src/model.rs | 17 ++++++++++++- crates/server/src/db/message.rs | 11 +++++---- crates/server/src/db/schema.sql | 2 +- 8 files changed, 79 insertions(+), 30 deletions(-) diff --git a/crates/client/lang/en/message_actions.txt b/crates/client/lang/en/message_actions.txt index ec7cc7e..59c4317 100644 --- a/crates/client/lang/en/message_actions.txt +++ b/crates/client/lang/en/message_actions.txt @@ -10,3 +10,4 @@ confirm = Confirm delete = Delete send = Send people = People +deleted = Deleted message diff --git a/crates/client/lang/tr/message_actions.txt b/crates/client/lang/tr/message_actions.txt index 952587d..20aa177 100644 --- a/crates/client/lang/tr/message_actions.txt +++ b/crates/client/lang/tr/message_actions.txt @@ -10,3 +10,4 @@ confirm = Onayla delete = Sil send = Gönder people = Kişiler +deleted = Silinmiş mesaj diff --git a/crates/client/src/gui/chat.rs b/crates/client/src/gui/chat.rs index b7cebe0..cb12456 100644 --- a/crates/client/src/gui/chat.rs +++ b/crates/client/src/gui/chat.rs @@ -43,7 +43,7 @@ use common::{ model::{ Account, AdminActionKind, AdminLogEntry, AttachmentInfo, Ban, BanScope, CallLog, Community, CommunityKind, CommunitySummary, CommunityUsage, DayStat, Friends, Id, Invitation, - InviteCode, LogEntry, Member, Message, MessageHit, Overview, Presence, Rank, Report, + InviteCode, LogEntry, Member, Message, MessageHit, Overview, Presence, Rank, Reply, Report, ReportStatus, ServerBan, SessionInfo, Unread, Usage, User, VoiceRoom, mentions, }, permission, @@ -878,8 +878,10 @@ impl Chat { fn quotes_of(&mut self, message_id: Id) -> impl Iterator { self.messages .iter_mut() - .filter_map(|message| message.reply.as_mut()) - .filter(move |quote| quote.message_id == message_id) + .filter_map(move |message| match &mut message.reply { + Some(Reply::Quote(quote)) if quote.message_id == message_id => Some(quote), + _ => None, + }) } fn forget_message(&mut self, message_id: Id) { @@ -888,9 +890,10 @@ impl Chat { if message .reply .as_ref() + .and_then(Reply::quote) .is_some_and(|quote| quote.message_id == message_id) { - message.reply = None; + message.reply = Some(Reply::Deleted); } } @@ -1081,7 +1084,13 @@ impl Chat { .chain(&self.pins) .flat_map(|message| { std::iter::once(message.user_id) - .chain(message.reply.as_ref().map(|quote| quote.user_id)) + .chain( + message + .reply + .as_ref() + .and_then(Reply::quote) + .map(|quote| quote.user_id), + ) .chain(message.poll.iter().flat_map(|poll| { poll.options .iter() diff --git a/crates/client/src/gui/composer.rs b/crates/client/src/gui/composer.rs index d10de32..c06c2e9 100644 --- a/crates/client/src/gui/composer.rs +++ b/crates/client/src/gui/composer.rs @@ -18,7 +18,8 @@ use common::{ }; use gpui_kit::{ Anchor, AnyElement, App, Context, Div, ElementId, Entity, FontWeight, InteractiveElement, - IntoElement, KeyBinding, MouseButton, ParentElement, Styled, Window, actions, + IntoElement, KeyBinding, MouseButton, ParentElement, StatefulInteractiveElement as _, Styled, + Window, actions, assets::IconName, component::{ WindowExt, @@ -150,15 +151,32 @@ fn reply_bar( .map(super::message_actions::message_text) .unwrap_or_default(); + let jump = entity.clone(); + bar(palette) - .child(w().composer.replying_to) .child( div() - .font_weight(FontWeight::SEMIBOLD) - .text_color(palette.text) - .child(author), + .id("reply_jump") + .flex_1() + .min_w_0() + .flex() + .items_center() + .gap(px(space::SM)) + .cursor_pointer() + .on_click(move |_, window, cx| { + jump.update(cx, |yumush, cx| { + yumush.go_to_message(message_id, window, cx) + }) + }) + .child(w().composer.replying_to) + .child( + div() + .font_weight(FontWeight::SEMIBOLD) + .text_color(palette.text) + .child(author), + ) + .child(div().flex_1().min_w_0().truncate().child(quote)), ) - .child(div().flex_1().min_w_0().truncate().child(quote)) .child(cancel_button(entity, palette)) } diff --git a/crates/client/src/gui/message_actions.rs b/crates/client/src/gui/message_actions.rs index fb7ee33..d7ee619 100644 --- a/crates/client/src/gui/message_actions.rs +++ b/crates/client/src/gui/message_actions.rs @@ -4,7 +4,7 @@ use common::model::Id; use common::{ call::{Pin, React, ReportMessage, ReportUser}, constant::REACTIONS, - model::{Message, User}, + model::{Message, Reply, User}, }; use gpui_kit::{ Anchor, Context, Div, Entity, Focusable as _, FontWeight, InteractiveElement, IntoElement, @@ -158,26 +158,30 @@ pub fn quote_line( entity: &Entity, palette: Palette, ) -> Option { - let quote = message.reply.as_ref()?; + let frame = div() + .id(format!("quote_{}", message.id)) + .flex() + .items_center() + .gap(px(space::SM)) + .pl(px(space::SM)) + .border_l_2() + .border_color(palette.border) + .text_size(text(text::CAPTION)) + .text_color(palette.muted); + let quote = match message.reply.as_ref()? { + Reply::Quote(quote) => quote, + Reply::Deleted => return Some(frame.italic().child(w().message_actions.deleted)), + }; let author = chat.author(quote.user_id); let target = quote.message_id; let entity = entity.clone(); Some( - div() - .id(format!("quote_{}", message.id)) + frame .cursor_pointer() .on_click(move |_, window, cx| { entity.update(cx, |yumush, cx| yumush.go_to_message(target, window, cx)) }) - .flex() - .items_center() - .gap(px(space::SM)) - .pl(px(space::SM)) - .border_l_2() - .border_color(palette.border) - .text_size(text(text::CAPTION)) - .text_color(palette.muted) .children(author.map(|user| { avatar( palette, diff --git a/crates/common/src/model.rs b/crates/common/src/model.rs index 787db0e..3c8d5c6 100644 --- a/crates/common/src/model.rs +++ b/crates/common/src/model.rs @@ -529,6 +529,21 @@ pub struct Quote { pub attachments: u32, } +#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)] +pub enum Reply { + Quote(Quote), + Deleted, +} + +impl Reply { + pub fn quote(&self) -> Option<&Quote> { + match self { + Reply::Quote(quote) => Some(quote), + Reply::Deleted => None, + } + } +} + #[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)] pub struct SnippetMessage { pub id: Id, @@ -580,7 +595,7 @@ pub struct Message { pub body: String, pub attachments: Vec, pub reactions: Vec, - pub reply: Option, + pub reply: Option, pub snippet: Option, pub poll: Option, pub edited: bool, diff --git a/crates/server/src/db/message.rs b/crates/server/src/db/message.rs index bd4025c..415532b 100644 --- a/crates/server/src/db/message.rs +++ b/crates/server/src/db/message.rs @@ -1,7 +1,7 @@ use common::{ constant::{MAXIMUM_FORWARD_MESSAGES, MAXIMUM_QUOTE_LENGTH, MESSAGE_PAGE_LIMIT}, error::{Error, Field, Problem}, - model::{CallLog, Id, Message, MessageHit, Quote, Reaction, SnippetMessage}, + model::{CallLog, Id, Message, MessageHit, Quote, Reaction, Reply, SnippetMessage}, time::now_ms, }; @@ -11,7 +11,7 @@ use crate::error::{ServerError, ensure_with}; const SEARCH_LIMIT: u32 = 200; const PAGE_LIMIT: u32 = MESSAGE_PAGE_LIMIT as u32; -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"; +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"; fn row(r: &mut Reader) -> Result { let id = r.get()?; @@ -20,6 +20,7 @@ fn row(r: &mut Reader) -> Result { let created_at = r.get()?; let body = r.get()?; let edited = r.get()?; + let reply_to: Option = r.get()?; let reply_id: Option = r.get()?; let reply_user_id: Option = r.get()?; let reply_body: Option = r.get()?; @@ -29,13 +30,13 @@ fn row(r: &mut Reader) -> Result { let pinned = r.get()?; let reply = match (reply_id, reply_user_id, reply_body) { - (Some(message_id), Some(user_id), Some(body)) => Some(Quote { + (Some(message_id), Some(user_id), Some(body)) => Some(Reply::Quote(Quote { message_id, user_id, body: body.chars().take(MAXIMUM_QUOTE_LENGTH).collect(), attachments: reply_attachments, - }), - _ => None, + })), + _ => reply_to.map(|_| Reply::Deleted), }; Ok(Message { diff --git a/crates/server/src/db/schema.sql b/crates/server/src/db/schema.sql index 2a09c2f..0cb37f3 100644 --- a/crates/server/src/db/schema.sql +++ b/crates/server/src/db/schema.sql @@ -83,7 +83,7 @@ CREATE TABLE message ( user_id INTEGER NOT NULL REFERENCES user (id) ON DELETE CASCADE, created_at INTEGER NOT NULL, body TEXT NOT NULL, - reply_to INTEGER REFERENCES message (id) ON DELETE SET NULL, + reply_to INTEGER, edited INTEGER NOT NULL DEFAULT 0, pinned INTEGER NOT NULL DEFAULT 0, call TEXT,