2016-11-15 10:56:29 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-09-04 08:43:00 -04:00
|
|
|
class RemoveStatusService < BaseService
|
2017-02-10 20:12:05 -05:00
|
|
|
include StreamEntryRenderer
|
|
|
|
|
2016-09-04 08:43:00 -04:00
|
|
|
def call(status)
|
2017-06-11 11:13:43 -04: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-04 19:59:46 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-06-11 11:13:43 -04:00
|
|
|
def remove_from_self
|
|
|
|
unpush(:home, @account, @status)
|
2016-09-04 19:59:46 -04:00
|
|
|
end
|
|
|
|
|
2017-06-11 11:13:43 -04:00
|
|
|
def remove_from_followers
|
2017-06-11 21:11:12 -04:00
|
|
|
@account.followers.local.find_each do |follower|
|
|
|
|
unpush(:home, follower, @status)
|
2016-09-04 19:59:46 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-11 11:13:43 -04: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-11 19:38:29 -05:00
|
|
|
|
2017-06-11 11:13:43 -04:00
|
|
|
NotificationWorker.push_bulk(target_accounts) do |target_account|
|
|
|
|
[salmon_xml, stream_entry.account_id, target_account.id]
|
2016-09-04 19:59:46 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-11 11:13:43 -04: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-04 19:59:46 -04:00
|
|
|
|
2017-06-11 11:13:43 -04:00
|
|
|
@reblogs.each do |reblog|
|
2016-09-29 15:28:21 -04:00
|
|
|
RemoveStatusService.new.call(reblog)
|
2016-09-04 19:59:46 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def unpush(type, receiver, status)
|
2017-02-22 09:52:47 -05:00
|
|
|
if status.reblog? && !redis.zscore(FeedManager.instance.key(type, receiver.id), status.reblog_of_id).nil?
|
2017-01-07 09:44:22 -05: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-05 20:26:59 -04:00
|
|
|
Redis.current.publish("timeline:#{receiver.id}", @payload)
|
2016-09-04 19:59:46 -04:00
|
|
|
end
|
|
|
|
|
2017-06-11 11:13:43 -04:00
|
|
|
def remove_from_hashtags
|
|
|
|
@tags.each do |hashtag|
|
2017-04-05 22:03:23 -04:00
|
|
|
Redis.current.publish("timeline:hashtag:#{hashtag}", @payload)
|
2017-06-11 11:13:43 -04:00
|
|
|
Redis.current.publish("timeline:hashtag:#{hashtag}:local", @payload) if @status.local?
|
2016-11-09 13:16:27 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-11 11:13:43 -04:00
|
|
|
def remove_from_public
|
2017-04-05 22:03:23 -04:00
|
|
|
Redis.current.publish('timeline:public', @payload)
|
2017-06-11 11:13:43 -04:00
|
|
|
Redis.current.publish('timeline:public:local', @payload) if @status.local?
|
2016-11-09 13:16:27 -05:00
|
|
|
end
|
|
|
|
|
2016-09-04 19:59:46 -04:00
|
|
|
def redis
|
2016-11-15 10:56:29 -05:00
|
|
|
Redis.current
|
2016-09-04 08:43:00 -04:00
|
|
|
end
|
|
|
|
end
|