2016-11-15 17:56:29 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-09-04 15:43:00 +03:00
|
|
|
class RemoveStatusService < BaseService
|
2017-02-11 03:12:05 +02:00
|
|
|
include StreamEntryRenderer
|
|
|
|
|
2016-09-04 15:43:00 +03:00
|
|
|
def call(status)
|
2017-06-11 18:13:43 +03:00
|
|
|
@payload = Oj.dump(event: :delete, payload: status.id)
|
|
|
|
@status = status
|
|
|
|
@account = status.account
|
|
|
|
@tags = status.tags.pluck(:name).to_a
|
|
|
|
@mentions = status.mentions.includes(:account).to_a
|
|
|
|
@reblogs = status.reblogs.to_a
|
|
|
|
@stream_entry = status.stream_entry
|
|
|
|
|
|
|
|
remove_from_self if status.account.local?
|
|
|
|
remove_from_followers
|
|
|
|
remove_reblogs
|
|
|
|
remove_from_hashtags
|
|
|
|
remove_from_public
|
|
|
|
|
|
|
|
@status.destroy!
|
|
|
|
|
|
|
|
return unless @account.local?
|
|
|
|
|
|
|
|
remove_from_mentioned(@stream_entry.reload)
|
|
|
|
Pubsubhubbub::DistributionWorker.perform_async(@stream_entry.id)
|
2016-09-05 02:59:46 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-06-11 18:13:43 +03:00
|
|
|
def remove_from_self
|
|
|
|
unpush(:home, @account, @status)
|
2016-09-05 02:59:46 +03:00
|
|
|
end
|
|
|
|
|
2017-06-11 18:13:43 +03:00
|
|
|
def remove_from_followers
|
2017-06-12 04:11:12 +03:00
|
|
|
@account.followers.local.find_each do |follower|
|
|
|
|
unpush(:home, follower, @status)
|
2016-09-05 02:59:46 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-11 18:13:43 +03:00
|
|
|
def remove_from_mentioned(stream_entry)
|
|
|
|
salmon_xml = stream_entry_to_xml(stream_entry)
|
|
|
|
target_accounts = @mentions.map(&:account).reject(&:local?).uniq(&:domain)
|
2017-02-12 02:38:29 +02:00
|
|
|
|
2017-06-11 18:13:43 +03:00
|
|
|
NotificationWorker.push_bulk(target_accounts) do |target_account|
|
|
|
|
[salmon_xml, stream_entry.account_id, target_account.id]
|
2016-09-05 02:59:46 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-11 18:13:43 +03:00
|
|
|
def remove_reblogs
|
|
|
|
# We delete reblogs of the status before the original status,
|
|
|
|
# because once original status is gone, reblogs will disappear
|
|
|
|
# without us being able to do all the fancy stuff
|
2016-09-05 02:59:46 +03:00
|
|
|
|
2017-06-11 18:13:43 +03:00
|
|
|
@reblogs.each do |reblog|
|
2016-09-29 22:28:21 +03:00
|
|
|
RemoveStatusService.new.call(reblog)
|
2016-09-05 02:59:46 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def unpush(type, receiver, status)
|
2017-02-22 16:52:47 +02:00
|
|
|
if status.reblog? && !redis.zscore(FeedManager.instance.key(type, receiver.id), status.reblog_of_id).nil?
|
2017-01-07 16:44:22 +02:00
|
|
|
redis.zadd(FeedManager.instance.key(type, receiver.id), status.reblog_of_id, status.reblog_of_id)
|
|
|
|
else
|
|
|
|
redis.zremrangebyscore(FeedManager.instance.key(type, receiver.id), status.id, status.id)
|
|
|
|
end
|
|
|
|
|
2017-04-06 03:26:59 +03:00
|
|
|
Redis.current.publish("timeline:#{receiver.id}", @payload)
|
2016-09-05 02:59:46 +03:00
|
|
|
end
|
|
|
|
|
2017-06-11 18:13:43 +03:00
|
|
|
def remove_from_hashtags
|
|
|
|
@tags.each do |hashtag|
|
2017-04-06 05:03:23 +03:00
|
|
|
Redis.current.publish("timeline:hashtag:#{hashtag}", @payload)
|
2017-06-11 18:13:43 +03:00
|
|
|
Redis.current.publish("timeline:hashtag:#{hashtag}:local", @payload) if @status.local?
|
2016-11-09 20:16:27 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-11 18:13:43 +03:00
|
|
|
def remove_from_public
|
2017-04-06 05:03:23 +03:00
|
|
|
Redis.current.publish('timeline:public', @payload)
|
2017-06-11 18:13:43 +03:00
|
|
|
Redis.current.publish('timeline:public:local', @payload) if @status.local?
|
2016-11-09 20:16:27 +02:00
|
|
|
end
|
|
|
|
|
2016-09-05 02:59:46 +03:00
|
|
|
def redis
|
2016-11-15 17:56:29 +02:00
|
|
|
Redis.current
|
2016-09-04 15:43:00 +03:00
|
|
|
end
|
|
|
|
end
|