FIX: chat message bookmark title update (#35788)

Better descriptions for bookmarked messages in direct message chat
channels. Previously with direct message channels the message would read
"Message in jim", switched to use "with jim".

### How it looks

<img width="256" height="108" alt="Screenshot 2025-11-04 at 12 55 00 PM"
src="https://github.com/user-attachments/assets/b623d597-3055-49cb-bf23-cbba6409b2ba"
/>
This commit is contained in:
David Battersby
2025-11-04 17:07:14 +04:00
committed by GitHub
parent 2f23e1224f
commit 772d23faa3
3 changed files with 44 additions and 5 deletions
+2 -1
View File
@@ -193,7 +193,8 @@ en:
is_already_in_use: "is already in use"
bookmarkable:
notification_title: "message in %{channel_name}"
notification_title_channel: "message in %{channel_name}"
notification_title_direct_message: "message with %{channel_name}"
personal_chat: "personal chat"
+12 -2
View File
@@ -44,13 +44,23 @@ module Chat
end
def self.reminder_handler(bookmark)
channel = bookmark.bookmarkable.chat_channel
channel_type =
(
if channel.direct_message_channel? && !channel.direct_message_group?
"direct_message"
else
"channel"
end
)
send_reminder_notification(
bookmark,
data: {
title:
I18n.t(
"chat.bookmarkable.notification_title",
channel_name: bookmark.bookmarkable.chat_channel.title(bookmark.user),
"chat.bookmarkable.notification_title_#{channel_type}",
channel_name: channel.title(bookmark.user),
),
bookmarkable_url: bookmark.bookmarkable.url,
},
@@ -10,6 +10,8 @@ describe Chat::MessageBookmarkable do
fab!(:category_channel) { Fabricate(:category_channel, chatable: other_category) }
fab!(:private_category) { Fabricate(:private_category, group: Fabricate(:group)) }
fab!(:channel, :category_channel)
fab!(:direct_message)
fab!(:direct_message_channel) { Fabricate(:direct_message_channel, chatable: direct_message) }
before do
register_test_bookmarkable(described_class)
@@ -47,7 +49,6 @@ describe Chat::MessageBookmarkable do
end
it "does not return bookmarks for messages inside direct message chat channels the user cannot access" do
direct_message = Fabricate(:direct_message)
channel.update(chatable: direct_message)
expect(registered_bookmarkable.perform_list_query(user, guardian)).to eq(nil)
Chat::DirectMessageUser.create(user: user, direct_message: direct_message)
@@ -137,7 +138,7 @@ describe Chat::MessageBookmarkable do
{
title:
I18n.t(
"chat.bookmarkable.notification_title",
"chat.bookmarkable.notification_title_channel",
channel_name: bookmark1.bookmarkable.chat_channel.title(bookmark1.user),
),
bookmarkable_url: bookmark1.bookmarkable.url,
@@ -149,6 +150,33 @@ describe Chat::MessageBookmarkable do
}.to_json,
)
end
it "returns the correct notification title for direct messages" do
message = Fabricate(:chat_message, chat_channel: direct_message_channel)
bookmark = Fabricate(:bookmark, user: user, bookmarkable: message)
expect { registered_bookmarkable.send_reminder_notification(bookmark) }.to change {
Notification.count
}.by(1)
notification = user.notifications.last
expect(notification.notification_type).to eq(Notification.types[:bookmark_reminder])
expect(notification.data).to eq(
{
title:
I18n.t(
"chat.bookmarkable.notification_title_direct_message",
channel_name: direct_message_channel.title(user),
),
bookmarkable_url: bookmark.bookmarkable.url,
display_username: bookmark.user.username,
bookmark_name: bookmark.name,
bookmark_id: bookmark.id,
bookmarkable_type: bookmark.bookmarkable_type,
bookmarkable_id: bookmark.bookmarkable_id,
}.to_json,
)
end
end
describe "#can_see?" do