A platform for community discussion. Free, open, simple.
DEV: better split create_notification! and send_notifications logic (#20562)
Andrei Prigorshneve292c45924bb
diff --git a/plugins/chat/app/jobs/regular/chat_notify_mentioned.rb b/plugins/chat/app/jobs/regular/chat_notify_mentioned.rbindex aa8feafb221..f0102aa7a68 100644--- a/plugins/chat/app/jobs/regular/chat_notify_mentioned.rb+++ b/plugins/chat/app/jobs/regular/chat_notify_mentioned.rb@@ -100,9 +100,9 @@ module Jobspayloadend- def create_notification!(membership, notification_data, mention)+ def create_notification!(membership, mention, mention_type)+ notification_data = build_data_for(membership, identifier_type: mention_type)is_read = Chat::ChatNotifier.user_has_seen_message?(membership, @chat_message.id)-notification =Notification.create!(notification_type: Notification.types[:chat_mention],@@ -115,22 +115,19 @@ module Jobsmention.update!(notification: notification)end- def send_notifications(membership, notification_data, os_payload)- mention = ChatMention.find_by(user: membership.user, chat_message: @chat_message)- return if mention.blank?-- create_notification!(membership, notification_data, mention)+ def send_notifications(membership, mention_type)+ payload = build_payload_for(membership, identifier_type: mention_type)if !membership.desktop_notifications_never? && !membership.muted?MessageBus.publish("/chat/notification-alert/#{membership.user_id}",- os_payload,+ payload,user_ids: [membership.user_id],)endif !membership.mobile_notifications_never? && !membership.muted?- PostAlerter.push_notification(membership.user, os_payload)+ PostAlerter.push_notification(membership.user, payload)endend@@ -138,10 +135,11 @@ module Jobsmemberships = get_memberships(user_ids)memberships.each do |membership|- notification_data = build_data_for(membership, identifier_type: mention_type)- payload = build_payload_for(membership, identifier_type: mention_type)-- send_notifications(membership, notification_data, payload)+ mention = ChatMention.find_by(user: membership.user, chat_message: @chat_message)+ if mention.present?+ create_notification!(membership, mention, mention_type)+ send_notifications(membership, mention_type)+ endendendend