mirror of
https://github.com/mastodon/mastodon.git
synced 2024-10-20 16:46:08 +00:00
e2491680e6
* services: scan spoiler_text for hashtags (#699) * views: link hashtags from spoiler_texts This covers linking hashtags from within the spoiler text on the server-generated pages. * services: fix string concat going into hashtag RE Cleaner Ruby syntax, may handle immutable strings better
15 lines
470 B
Ruby
15 lines
470 B
Ruby
# frozen_string_literal: true
|
|
|
|
class ProcessHashtagsService < BaseService
|
|
def call(status, tags = [])
|
|
text = [status.text, status.spoiler_text].reject(&:empty?).join(' ')
|
|
tags = text.scan(Tag::HASHTAG_RE).map(&:first) if status.local?
|
|
|
|
tags.map { |str| str.mb_chars.downcase }.uniq(&:to_s).each do |tag|
|
|
status.tags << Tag.where(name: tag).first_or_initialize(name: tag)
|
|
end
|
|
|
|
status.update(sensitive: true) if tags.include?('nsfw')
|
|
end
|
|
end
|