chinwagsocial/app/services/process_hashtags_service.rb

14 lines
404 B
Ruby
Raw Normal View History

# frozen_string_literal: true
2016-11-06 01:20:05 +11:00
class ProcessHashtagsService < BaseService
def call(status, tags = [])
tags = status.text.scan(Tag::HASHTAG_RE).map(&:first) if status.local?
2016-11-06 01:20:05 +11:00
tags.map { |str| str.mb_chars.downcase }.uniq(&:to_s).each do |tag|
2016-11-06 01:20:05 +11:00
status.tags << Tag.where(name: tag).first_or_initialize(name: tag)
end
status.update(sensitive: true) if tags.include?('nsfw')
2016-11-06 01:20:05 +11:00
end
end