Skip to content

Commit

Permalink
FEATURE: Link chat notifications directly to message (#23617)
Browse files Browse the repository at this point in the history
- Updates `Chat::Message#url` to work in threads and for subfolder
- Updates Jobs::Chat::NotifyWatching to use message URL instead of channel url
  • Loading branch information
davidtaylorhq committed Sep 16, 2023
1 parent ebe68e1 commit 2791e75
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion plugins/chat/app/jobs/regular/chat/notify_watching.rb
Expand Up @@ -64,7 +64,7 @@ def send_notifications(membership)
payload = {
username: @creator.username,
notification_type: ::Notification.types[:chat_message],
post_url: @chat_channel.relative_url,
post_url: @chat_message.url,
translated_title: ::I18n.t(translation_key, translation_args),
tag: ::Chat::Notifier.push_notification_tag(:message, @chat_channel.id),
excerpt: @chat_message.push_notification_excerpt,
Expand Down
6 changes: 5 additions & 1 deletion plugins/chat/app/models/chat/message.rb
Expand Up @@ -250,7 +250,11 @@ def full_url
end

def url
"/chat/c/-/#{self.chat_channel_id}/#{self.id}"
if in_thread?
"#{Discourse.base_path}/chat/c/-/#{self.chat_channel_id}/t/#{self.thread_id}/#{self.id}"
else
"#{Discourse.base_path}/chat/c/-/#{self.chat_channel_id}/#{self.id}"
end
end

def create_mentions
Expand Down
8 changes: 4 additions & 4 deletions plugins/chat/spec/jobs/regular/chat/notify_watching_spec.rb
Expand Up @@ -50,7 +50,7 @@ def notification_messages_for(user)
{
username: user1.username,
notification_type: Notification.types[:chat_message],
post_url: channel.relative_url,
post_url: message.url,
translated_title:
I18n.t(
"discourse_push_notifications.popup.new_chat_message",
Expand Down Expand Up @@ -87,7 +87,7 @@ def notification_messages_for(user)
{
username: user1.username,
notification_type: Notification.types[:chat_message],
post_url: channel.relative_url,
post_url: message.url,
translated_title:
I18n.t(
"discourse_push_notifications.popup.new_chat_message",
Expand Down Expand Up @@ -190,7 +190,7 @@ def notification_messages_for(user)
{
username: user1.username,
notification_type: Notification.types[:chat_message],
post_url: channel.relative_url,
post_url: message.url,
translated_title:
I18n.t(
"discourse_push_notifications.popup.new_direct_chat_message",
Expand Down Expand Up @@ -227,7 +227,7 @@ def notification_messages_for(user)
{
username: user1.username,
notification_type: Notification.types[:chat_message],
post_url: channel.relative_url,
post_url: message.url,
translated_title:
I18n.t(
"discourse_push_notifications.popup.new_direct_chat_message",
Expand Down
14 changes: 14 additions & 0 deletions plugins/chat/spec/models/chat/message_spec.rb
Expand Up @@ -589,4 +589,18 @@
expect(message.chat_mentions.pluck(:id)).to include(*existing_mention_ids) # the mentions weren't recreated
end
end

describe "#url" do
it "returns message permalink" do
expect(message.url).to eq("/chat/c/-/#{message.chat_channel_id}/#{message.id}")
end

it "returns message permalink when in thread" do
thread = Fabricate(:chat_thread)
first_message = thread.chat_messages.first
expect(first_message.url).to eq(
"/chat/c/-/#{first_message.chat_channel_id}/t/#{first_message.thread_id}/#{first_message.id}",
)
end
end
end

0 comments on commit 2791e75

Please sign in to comment.