2016-11-16 00:56:29 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-09-04 21:43:00 +09:00
|
|
|
class RemoveStatusService < BaseService
|
2017-02-11 10:12:05 +09:00
|
|
|
include StreamEntryRenderer
|
|
|
|
|
2016-09-04 21:43:00 +09:00
|
|
|
def call(status)
|
2017-06-12 00:13:43 +09: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-13 07:44:41 +09:00
|
|
|
@stream_entry = @stream_entry.reload
|
|
|
|
|
|
|
|
remove_from_remote_followers
|
|
|
|
remove_from_remote_affected
|
2016-09-05 08:59:46 +09:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-06-12 00:13:43 +09:00
|
|
|
def remove_from_self
|
|
|
|
unpush(:home, @account, @status)
|
2016-09-05 08:59:46 +09:00
|
|
|
end
|
|
|
|
|
2017-06-12 00:13:43 +09:00
|
|
|
def remove_from_followers
|
2017-06-12 10:11:12 +09:00
|
|
|
@account.followers.local.find_each do |follower|
|
|
|
|
unpush(:home, follower, @status)
|
2016-09-05 08:59:46 +09:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-13 07:44:41 +09: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
|
2017-08-29 04:38:59 +09:00
|
|
|
ActivityPub::DeliveryWorker.push_bulk(target_accounts.select(&:activitypub?).uniq(&:inbox_url)) do |target_account|
|
|
|
|
[signed_activity_json, @account.id, target_account.inbox_url]
|
2017-08-13 07:44:41 +09:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def remove_from_remote_followers
|
|
|
|
# OStatus
|
|
|
|
Pubsubhubbub::DistributionWorker.perform_async(@stream_entry.id)
|
2017-02-12 09:38:29 +09:00
|
|
|
|
2017-08-13 07:44:41 +09:00
|
|
|
# ActivityPub
|
|
|
|
ActivityPub::DeliveryWorker.push_bulk(@account.followers.inboxes) do |inbox_url|
|
2017-08-26 20:47:38 +09:00
|
|
|
[signed_activity_json, @account.id, inbox_url]
|
2016-09-05 08:59:46 +09:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-13 07:44:41 +09:00
|
|
|
def salmon_xml
|
|
|
|
@salmon_xml ||= stream_entry_to_xml(@stream_entry)
|
|
|
|
end
|
|
|
|
|
2017-08-26 20:47:38 +09:00
|
|
|
def signed_activity_json
|
|
|
|
@signed_activity_json ||= Oj.dump(ActivityPub::LinkedDataSignature.new(activity_json).sign!(@account))
|
|
|
|
end
|
|
|
|
|
2017-08-13 07:44:41 +09:00
|
|
|
def activity_json
|
|
|
|
@activity_json ||= ActiveModelSerializers::SerializableResource.new(
|
|
|
|
@status,
|
2017-08-26 22:32:40 +09:00
|
|
|
serializer: @status.reblog? ? ActivityPub::UndoAnnounceSerializer : ActivityPub::DeleteSerializer,
|
2017-08-13 07:44:41 +09:00
|
|
|
adapter: ActivityPub::Adapter
|
2017-08-26 20:47:38 +09:00
|
|
|
).as_json
|
2017-08-13 07:44:41 +09:00
|
|
|
end
|
|
|
|
|
2017-06-12 00:13:43 +09: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 08:59:46 +09:00
|
|
|
|
2017-06-12 00:13:43 +09:00
|
|
|
@reblogs.each do |reblog|
|
2016-09-30 04:28:21 +09:00
|
|
|
RemoveStatusService.new.call(reblog)
|
2016-09-05 08:59:46 +09:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def unpush(type, receiver, status)
|
2017-02-22 23:52:47 +09:00
|
|
|
if status.reblog? && !redis.zscore(FeedManager.instance.key(type, receiver.id), status.reblog_of_id).nil?
|
2017-01-07 23:44:22 +09: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 09:26:59 +09:00
|
|
|
Redis.current.publish("timeline:#{receiver.id}", @payload)
|
2016-09-05 08:59:46 +09:00
|
|
|
end
|
|
|
|
|
2017-06-12 00:13:43 +09:00
|
|
|
def remove_from_hashtags
|
|
|
|
@tags.each do |hashtag|
|
2017-04-06 11:03:23 +09:00
|
|
|
Redis.current.publish("timeline:hashtag:#{hashtag}", @payload)
|
2017-06-12 00:13:43 +09:00
|
|
|
Redis.current.publish("timeline:hashtag:#{hashtag}:local", @payload) if @status.local?
|
2016-11-10 03:16:27 +09:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-12 00:13:43 +09:00
|
|
|
def remove_from_public
|
2017-04-06 11:03:23 +09:00
|
|
|
Redis.current.publish('timeline:public', @payload)
|
2017-06-12 00:13:43 +09:00
|
|
|
Redis.current.publish('timeline:public:local', @payload) if @status.local?
|
2016-11-10 03:16:27 +09:00
|
|
|
end
|
|
|
|
|
2016-09-05 08:59:46 +09:00
|
|
|
def redis
|
2016-11-16 00:56:29 +09:00
|
|
|
Redis.current
|
2016-09-04 21:43:00 +09:00
|
|
|
end
|
|
|
|
end
|