2016-11-15 10:56:29 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-05 10:20:05 -04:00
|
|
|
class ProcessHashtagsService < BaseService
|
|
|
|
def call(status, tags = [])
|
2017-05-10 18:28:10 -04:00
|
|
|
text = [status.text, status.spoiler_text].reject(&:blank?).join(' ')
|
2017-05-09 22:47:25 -04:00
|
|
|
tags = text.scan(Tag::HASHTAG_RE).map(&:first) if status.local?
|
2016-11-05 10:20:05 -04:00
|
|
|
|
2017-01-23 15:36:08 -05:00
|
|
|
tags.map { |str| str.mb_chars.downcase }.uniq(&:to_s).each do |tag|
|
2016-11-05 10:20:05 -04:00
|
|
|
status.tags << Tag.where(name: tag).first_or_initialize(name: tag)
|
|
|
|
end
|
2016-12-11 16:49:25 -05:00
|
|
|
|
|
|
|
status.update(sensitive: true) if tags.include?('nsfw')
|
2016-11-05 10:20:05 -04:00
|
|
|
end
|
|
|
|
end
|