DEV: cleanup chat desktop notification data (#28943)

Makes channel_id and is_direct_message_channel consistent across desktop notifications, which also removes the need to lookup the channel from Chat Notification Manager.
This commit is contained in:
David Battersby 2024-10-03 12:43:17 +04:00 committed by GitHub
parent ad8f46f4f1
commit 9eaf908e63
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 11 additions and 19 deletions

View File

@ -15,6 +15,7 @@ module Jobs
@creator = @chat_message.user
@chat_channel = @chat_message.chat_channel
@is_direct_message_channel = @chat_channel.direct_message_channel?
@already_notified_user_ids = args[:already_notified_user_ids] || []
user_ids_to_notify = args[:to_notify_ids_map] || {}
user_ids_to_notify.each { |mention_type, ids| process_mentions(ids, mention_type.to_sym) }
@ -37,7 +38,7 @@ module Jobs
chat_message_id: @chat_message.id,
chat_channel_id: @chat_channel.id,
mentioned_by_username: @creator.username,
is_direct_message_channel: @chat_channel.direct_message_channel?,
is_direct_message_channel: @is_direct_message_channel,
}
data[:chat_thread_id] = @chat_message.thread_id if @chat_message.in_thread?
@ -76,6 +77,8 @@ module Jobs
tag: ::Chat::Notifier.push_notification_tag(:mention, @chat_channel.id),
excerpt: @chat_message.push_notification_excerpt,
post_url: post_url,
channel_id: @chat_channel.id,
is_direct_message_channel: @is_direct_message_channel,
}
translation_prefix =

View File

@ -81,6 +81,7 @@ module Jobs
tag: ::Chat::Notifier.push_notification_tag(:message, @chat_channel.id),
excerpt: @chat_message.push_notification_excerpt,
channel_id: @chat_channel.id,
is_direct_message_channel: @is_direct_message_channel,
}
if @chat_message.in_thread? && !membership.muted?

View File

@ -40,7 +40,7 @@ export default {
if (
indicatorType === INDICATOR_PREFERENCES.dm_and_mentions &&
!data.isDirectMessageChannel &&
!data.is_direct_message_channel &&
!isMention
) {
return;

View File

@ -1,4 +1,3 @@
import { action } from "@ember/object";
import Service, { service } from "@ember/service";
import {
alertChannel,
@ -146,13 +145,6 @@ export default class ChatNotificationManager extends Service {
}
}
@action
async fetchChannel(channelId) {
return await this.chatChannelsManager.find(channelId, {
fetchIfNotFound: false,
});
}
@bind
async onMessage(data) {
if (data.channel_id === this.chat.activeChannel?.id) {
@ -160,12 +152,6 @@ export default class ChatNotificationManager extends Service {
}
if (this.site.desktopView) {
const channel = await this.fetchChannel(data.channel_id);
if (channel) {
data.isDirectMessageChannel = channel.isDirectMessageChannel ?? false;
}
return onDesktopNotification(
data,
this.siteSettings,

View File

@ -257,6 +257,8 @@ describe Jobs::Chat::NotifyMentioned do
excerpt: message.push_notification_excerpt,
post_url: "/chat/c/#{public_channel.slug}/#{public_channel.id}/#{message.id}",
translated_title: payload_translated_title,
channel_id: public_channel.id,
is_direct_message_channel: false,
},
)

View File

@ -63,7 +63,7 @@ RSpec.describe "User menu notifications | sidebar", type: :system do
end
expect(find("#quick-access-chat-notifications")).to have_link(
I18n.t("js.notifications.popup.direct_message_chat_mention.direct"),
href: "/discuss/chat/c/#{other_user.username}/#{dm_channel_1.id}/#{message.id}",
href: "/discuss/chat/c/-/#{dm_channel_1.id}/#{message.id}",
)
end
end

View File

@ -85,7 +85,7 @@ module("Discourse Chat | Unit | chat-audio", function (hooks) {
this.currentUser.user_option.chat_header_indicator_preference =
"dm_and_mentions";
this.handleNotification({ isDirectMessageChannel: true });
this.handleNotification({ is_direct_message_channel: true });
assert.ok(this.playStub.calledOnce);
});
@ -94,7 +94,7 @@ module("Discourse Chat | Unit | chat-audio", function (hooks) {
this.currentUser.user_option.chat_header_indicator_preference =
"dm_and_mentions";
this.handleNotification({ isDirectMessageChannel: false });
this.handleNotification({ is_direct_message_channel: false });
assert.ok(this.playStub.notCalled);
});