2016-11-15 16:56:29 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-05 15:20:05 +01:00
|
|
|
class ProcessHashtagsService < BaseService
|
|
|
|
def call(status, tags = [])
|
2019-02-04 04:25:59 +01:00
|
|
|
tags = Extractor.extract_hashtags(status.text) if status.local?
|
|
|
|
records = []
|
2016-11-05 15:20:05 +01:00
|
|
|
|
2018-05-27 21:45:30 +02:00
|
|
|
tags.map { |str| str.mb_chars.downcase }.uniq(&:to_s).each do |name|
|
|
|
|
tag = Tag.where(name: name).first_or_create(name: name)
|
2019-02-04 04:25:59 +01:00
|
|
|
|
2018-05-27 21:45:30 +02:00
|
|
|
status.tags << tag
|
2019-02-04 04:25:59 +01:00
|
|
|
records << tag
|
|
|
|
|
2018-05-31 16:47:28 +02:00
|
|
|
TrendingTags.record_use!(tag, status.account, status.created_at) if status.public_visibility?
|
2016-11-05 15:20:05 +01:00
|
|
|
end
|
2019-02-04 04:25:59 +01:00
|
|
|
|
|
|
|
return unless status.public_visibility? || status.unlisted_visibility?
|
|
|
|
|
|
|
|
status.account.featured_tags.where(tag_id: records.map(&:id)).each do |featured_tag|
|
|
|
|
featured_tag.increment(status.created_at)
|
|
|
|
end
|
2016-11-05 15:20:05 +01:00
|
|
|
end
|
|
|
|
end
|