2016-11-15 07:56:29 -08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-09-04 05:43:00 -07:00
|
|
|
class RemoveStatusService < BaseService
|
2017-02-10 17:12:05 -08:00
|
|
|
include StreamEntryRenderer
|
|
|
|
|
2016-09-04 05:43:00 -07:00
|
|
|
def call(status)
|
2017-06-11 08:13:43 -07: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?
|
|
|
|
|
2017-08-12 15:44:41 -07:00
|
|
|
@stream_entry = @stream_entry.reload
|
|
|
|
|
|
|
|
remove_from_remote_followers
|
|
|
|
remove_from_remote_affected
|
2016-09-04 16:59:46 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-06-11 08:13:43 -07:00
|
|
|
def remove_from_self
|
|
|
|
unpush(:home, @account, @status)
|
2016-09-04 16:59:46 -07:00
|
|
|
end
|
|
|
|
|
2017-06-11 08:13:43 -07:00
|
|
|
def remove_from_followers
|
2017-06-11 18:11:12 -07:00
|
|
|
@account.followers.local.find_each do |follower|
|
|
|
|
unpush(:home, follower, @status)
|
2016-09-04 16:59:46 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-12 15:44:41 -07:00
|
|
|
def remove_from_remote_affected
|
|
|
|
# People who got mentioned in the status, or who
|
|
|
|
# reblogged it from someone else might not follow
|
|
|
|
# the author and wouldn't normally receive the
|
|
|
|
# delete notification - so here, we explicitly
|
|
|
|
# send it to them
|
|
|
|
|
|
|
|
target_accounts = (@mentions.map(&:account).reject(&:local?) + @reblogs.map(&:account).reject(&:local?)).uniq(&:id)
|
|
|
|
|
|
|
|
# Ostatus
|
|
|
|
NotificationWorker.push_bulk(target_accounts.select(&:ostatus?).uniq(&:domain)) do |target_account|
|
|
|
|
[salmon_xml, @account.id, target_account.id]
|
|
|
|
end
|
|
|
|
|
|
|
|
# ActivityPub
|
|
|
|
ActivityPub::DeliveryWorker.push_bulk(target_accounts.select(&:activitypub?).uniq(&:inbox_url)) do |inbox_url|
|
|
|
|
[activity_json, @account.id, inbox_url]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def remove_from_remote_followers
|
|
|
|
# OStatus
|
|
|
|
Pubsubhubbub::DistributionWorker.perform_async(@stream_entry.id)
|
2017-02-11 16:38:29 -08:00
|
|
|
|
2017-08-12 15:44:41 -07:00
|
|
|
# ActivityPub
|
|
|
|
ActivityPub::DeliveryWorker.push_bulk(@account.followers.inboxes) do |inbox_url|
|
|
|
|
[activity_json, @account.id, inbox_url]
|
2016-09-04 16:59:46 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-12 15:44:41 -07:00
|
|
|
def salmon_xml
|
|
|
|
@salmon_xml ||= stream_entry_to_xml(@stream_entry)
|
|
|
|
end
|
|
|
|
|
|
|
|
def activity_json
|
|
|
|
@activity_json ||= ActiveModelSerializers::SerializableResource.new(
|
|
|
|
@status,
|
|
|
|
serializer: ActivityPub::DeleteSerializer,
|
|
|
|
adapter: ActivityPub::Adapter
|
|
|
|
).to_json
|
|
|
|
end
|
|
|
|
|
2017-06-11 08:13:43 -07: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 16:59:46 -07:00
|
|
|
|
2017-06-11 08:13:43 -07:00
|
|
|
@reblogs.each do |reblog|
|
2016-09-29 12:28:21 -07:00
|
|
|
RemoveStatusService.new.call(reblog)
|
2016-09-04 16:59:46 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def unpush(type, receiver, status)
|
2017-02-22 06:52:47 -08:00
|
|
|
if status.reblog? && !redis.zscore(FeedManager.instance.key(type, receiver.id), status.reblog_of_id).nil?
|
2017-01-07 06:44:22 -08: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 17:26:59 -07:00
|
|
|
Redis.current.publish("timeline:#{receiver.id}", @payload)
|
2016-09-04 16:59:46 -07:00
|
|
|
end
|
|
|
|
|
2017-06-11 08:13:43 -07:00
|
|
|
def remove_from_hashtags
|
|
|
|
@tags.each do |hashtag|
|
2017-04-05 19:03:23 -07:00
|
|
|
Redis.current.publish("timeline:hashtag:#{hashtag}", @payload)
|
2017-06-11 08:13:43 -07:00
|
|
|
Redis.current.publish("timeline:hashtag:#{hashtag}:local", @payload) if @status.local?
|
2016-11-09 10:16:27 -08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-11 08:13:43 -07:00
|
|
|
def remove_from_public
|
2017-04-05 19:03:23 -07:00
|
|
|
Redis.current.publish('timeline:public', @payload)
|
2017-06-11 08:13:43 -07:00
|
|
|
Redis.current.publish('timeline:public:local', @payload) if @status.local?
|
2016-11-09 10:16:27 -08:00
|
|
|
end
|
|
|
|
|
2016-09-04 16:59:46 -07:00
|
|
|
def redis
|
2016-11-15 07:56:29 -08:00
|
|
|
Redis.current
|
2016-09-04 05:43:00 -07:00
|
|
|
end
|
|
|
|
end
|