DEV: Extract mentions.count method (#21116)

This commit is contained in:
Andrei Prigorshnev 2023-04-21 17:54:02 +04:00 committed by GitHub
parent e7292e1682
commit ea5dec82a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 6 deletions

View File

@ -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)

View File

@ -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