mirror of
https://github.com/discourse/discourse.git
synced 2025-03-27 08:21:42 +08:00
REFACTOR: Simplify extraction of mentions
This commit is contained in:
parent
75dac31323
commit
886ef7251d
@ -454,21 +454,17 @@ class PostAlerter
|
|||||||
# TODO: Move to post-analyzer?
|
# TODO: Move to post-analyzer?
|
||||||
def extract_mentions(post)
|
def extract_mentions(post)
|
||||||
mentions = post.raw_mentions
|
mentions = post.raw_mentions
|
||||||
|
return if mentions.blank?
|
||||||
return unless mentions && mentions.length > 0
|
|
||||||
|
|
||||||
groups = Group.where('LOWER(name) IN (?)', mentions)
|
groups = Group.where('LOWER(name) IN (?)', mentions)
|
||||||
|
mentions -= groups.map(&:name).map(&:downcase)
|
||||||
|
groups = nil if groups.empty?
|
||||||
|
|
||||||
if groups.empty?
|
if mentions.present?
|
||||||
groups = nil
|
users = User.where(username_lower: mentions).where.not(id: post.user_id)
|
||||||
else
|
users = nil if users.empty?
|
||||||
mentions -= groups.map(&:name).map(&:downcase)
|
|
||||||
return [groups, nil] unless mentions && mentions.length > 0
|
|
||||||
end
|
end
|
||||||
|
|
||||||
users = User.where(username_lower: mentions).where.not(id: post.user_id)
|
|
||||||
users = nil if users.empty?
|
|
||||||
|
|
||||||
[groups, users]
|
[groups, users]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user