mirror of
https://github.com/lunaisnotaboy/mastodon.git
synced 2024-08-27 19:04:51 +00:00
* Add editing for published statuses * Fix change of multiple-choice boolean in poll not resetting votes * Remove the ability to update existing media attachments for now
41 lines
1 KiB
Ruby
41 lines
1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class ProcessHashtagsService < BaseService
|
|
def call(status, raw_tags = [])
|
|
@status = status
|
|
@account = status.account
|
|
@raw_tags = status.local? ? Extractor.extract_hashtags(status.text) : raw_tags
|
|
@previous_tags = status.tags.to_a
|
|
@current_tags = []
|
|
|
|
assign_tags!
|
|
update_featured_tags!
|
|
end
|
|
|
|
private
|
|
|
|
def assign_tags!
|
|
@status.tags = @current_tags = Tag.find_or_create_by_names(@raw_tags)
|
|
end
|
|
|
|
def update_featured_tags!
|
|
return unless @status.distributable?
|
|
|
|
added_tags = @current_tags - @previous_tags
|
|
|
|
unless added_tags.empty?
|
|
@account.featured_tags.where(tag_id: added_tags.map(&:id)).each do |featured_tag|
|
|
featured_tag.increment(@status.created_at)
|
|
end
|
|
end
|
|
|
|
removed_tags = @previous_tags - @current_tags
|
|
|
|
unless removed_tags.empty?
|
|
@account.featured_tags.where(tag_id: removed_tags.map(&:id)).each do |featured_tag|
|
|
featured_tag.decrement(@status.id)
|
|
end
|
|
end
|
|
end
|
|
end
|