Skip to content

A platform for community discussion. Free, open, simple.

DEV: Extract mentions.count method (#21116)

Andrei Prigorshnevea5dec82a602
diff --git a/plugins/chat/lib/chat/message_mentions.rb b/plugins/chat/lib/chat/message_mentions.rb
index 613b8aead1f..cd8f3d78dc8 100644
--- a/plugins/chat/lib/chat/message_mentions.rb
+++ b/plugins/chat/lib/chat/message_mentions.rb
@@ -31,6 +31,16 @@ module Chat
end
end
+ def count
+ @count ||=
+ begin
+ result = @parsed_direct_mentions.length + @parsed_group_mentions.length
+ result += 1 if @has_global_mention
+ result += 1 if @has_here_mention
+ result
+ end
+ end
+
def global_mentions
return User.none unless @has_global_mention
channel_members.where.not(username_lower: @parsed_direct_mentions)
diff --git a/plugins/chat/lib/chat/notifier.rb b/plugins/chat/lib/chat/notifier.rb
index d06d75dc7b3..7d4e879a4f5 100644
--- a/plugins/chat/lib/chat/notifier.rb
+++ b/plugins/chat/lib/chat/notifier.rb
@@ -108,12 +108,7 @@ module Chat
private
def list_users_to_notify
- mentions_count =
- @mentions.parsed_direct_mentions.length + @mentions.parsed_group_mentions.length
- mentions_count += 1 if @mentions.has_global_mention
- mentions_count += 1 if @mentions.has_here_mention
-
- skip_notifications = mentions_count > SiteSetting.max_mentions_per_chat_message
+ skip_notifications = @mentions.count > SiteSetting.max_mentions_per_chat_message
{}.tap do |to_notify|
# The order of these methods is the precedence