2016-11-15 15:56:29 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-05 14:20:05 +00:00
|
|
|
class ProcessHashtagsService < BaseService
|
|
|
|
def call(status, tags = [])
|
2019-02-04 03:25:59 +00:00
|
|
|
tags = Extractor.extract_hashtags(status.text) if status.local?
|
|
|
|
records = []
|
2016-11-05 14:20:05 +00:00
|
|
|
|
2019-07-28 03:59:51 +00:00
|
|
|
Tag.find_or_create_by_names(tags) do |tag|
|
2018-05-27 19:45:30 +00:00
|
|
|
status.tags << tag
|
2019-02-04 03:25:59 +00:00
|
|
|
records << tag
|
2021-11-25 12:07:38 +00:00
|
|
|
tag.update(last_status_at: status.created_at) if tag.last_status_at.nil? || (tag.last_status_at < status.created_at && tag.last_status_at < 12.hours.ago)
|
2016-11-05 14:20:05 +00:00
|
|
|
end
|
2019-02-04 03:25:59 +00:00
|
|
|
|
2019-07-08 10:03:45 +00:00
|
|
|
return unless status.distributable?
|
2019-02-04 03:25:59 +00:00
|
|
|
|
|
|
|
status.account.featured_tags.where(tag_id: records.map(&:id)).each do |featured_tag|
|
|
|
|
featured_tag.increment(status.created_at)
|
|
|
|
end
|
2016-11-05 14:20:05 +00:00
|
|
|
end
|
|
|
|
end
|