mirror of
https://github.com/discourse/discourse.git
synced 2025-06-04 23:36:11 +08:00
DEV: Always create chat mention records (#20470)
Before this commit, we created a chat mention record only in case we wanted to send a notification about that mention to the user. Notifications were the only use case for the chat_mention db table. Now we want to use that table for other features, so we have to always create a chat_mention record.
This commit is contained in:

committed by
GitHub

parent
1f88354c5e
commit
fa543cda06
@ -66,6 +66,10 @@ class Chat::ChatNotifier
|
||||
### Public API
|
||||
|
||||
def notify_new
|
||||
if @mentions.all_mentioned_users_ids.present?
|
||||
@chat_message.create_mentions(@mentions.all_mentioned_users_ids)
|
||||
end
|
||||
|
||||
to_notify = list_users_to_notify
|
||||
mentioned_user_ids = to_notify.extract!(:all_mentioned_user_ids)[:all_mentioned_user_ids]
|
||||
|
||||
@ -82,6 +86,8 @@ class Chat::ChatNotifier
|
||||
end
|
||||
|
||||
def notify_edit
|
||||
@chat_message.update_mentions(@mentions.all_mentioned_users_ids)
|
||||
|
||||
existing_notifications =
|
||||
ChatMention.includes(:user, :notification).where(chat_message: @chat_message)
|
||||
already_notified_user_ids = existing_notifications.map(&:user_id)
|
||||
@ -139,6 +145,7 @@ class Chat::ChatNotifier
|
||||
if has_all_mention && @chat_channel.allow_channel_wide_mentions && !skip
|
||||
to_notify[:global_mentions] = @mentions
|
||||
.global_mentions
|
||||
.not_suspended
|
||||
.where(user_options: { ignore_channel_wide_mention: [false, nil] })
|
||||
.where.not(id: already_covered_ids)
|
||||
.pluck(:id)
|
||||
@ -155,6 +162,7 @@ class Chat::ChatNotifier
|
||||
if has_here_mention && @chat_channel.allow_channel_wide_mentions && !skip
|
||||
to_notify[:here_mentions] = @mentions
|
||||
.here_mentions
|
||||
.not_suspended
|
||||
.where(user_options: { ignore_channel_wide_mention: [false, nil] })
|
||||
.where.not(id: already_covered_ids)
|
||||
.pluck(:id)
|
||||
@ -192,7 +200,7 @@ class Chat::ChatNotifier
|
||||
if skip
|
||||
direct_mentions = []
|
||||
else
|
||||
direct_mentions = @mentions.direct_mentions.where.not(id: already_covered_ids)
|
||||
direct_mentions = @mentions.direct_mentions.not_suspended.where.not(id: already_covered_ids)
|
||||
end
|
||||
|
||||
grouped = group_users_to_notify(direct_mentions)
|
||||
@ -209,6 +217,7 @@ class Chat::ChatNotifier
|
||||
reached_by_group =
|
||||
@mentions
|
||||
.group_mentions
|
||||
.not_suspended
|
||||
.where("user_count <= ?", SiteSetting.max_users_notified_per_group_mention)
|
||||
.where.not(id: already_covered_ids)
|
||||
|
||||
|
Reference in New Issue
Block a user