diff options
author | Fire Demon <firedemon@creature.cafe> | 2020-06-27 14:22:30 -0500 |
---|---|---|
committer | Fire Demon <firedemon@creature.cafe> | 2020-09-08 03:37:04 -0500 |
commit | 9d4f18b984d6699bdf96e5f5963edfe80063426c (patch) | |
tree | e00fb54963769a259cd9bbe97754a2a872d028be /app/services/publish_status_service.rb | |
parent | 437d71bddf967573df3912ee5976f7c5a5a7b4c7 (diff) |
Monsterfork v2 Kaiju Commit 2020.06.27.1 - 2020.09.05.5
Diffstat (limited to 'app/services/publish_status_service.rb')
-rw-r--r-- | app/services/publish_status_service.rb | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/app/services/publish_status_service.rb b/app/services/publish_status_service.rb new file mode 100644 index 000000000..e95c3dacd --- /dev/null +++ b/app/services/publish_status_service.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true +class PublishStatusService < BaseService + include Redisable + + def call(status) + return if status.published? + + @status = status + + update_status! + reset_status_caches + distribute + bump_potential_friendship! + end + + private + + def update_status! + @status.update!(published: true, publish_at: nil, expires_at: @status.expires_at.blank? ? nil : Time.now.utc + (@status.expires_at - @status.created_at)) + ProcessMentionsService.new.call(@status) + end + + def reset_status_caches + Rails.cache.delete_matched("statuses/#{@status.id}-*") + Rails.cache.delete("statuses/#{@status.id}") + Rails.cache.delete(@status) + Rails.cache.delete_matched("format:#{@status.id}:*") + redis.zremrangebyscore("spam_check:#{@status.account.id}", @status.id, @status.id) + end + + def distribute + LinkCrawlWorker.perform_in(rand(1..30).seconds, @status.id) unless @status.spoiler_text? + DistributionWorker.perform_async(@status.id) + ActivityPub::DistributionWorker.perform_async(@status.id) if @status.local? && !@status.local_only? + end + + def bump_potential_friendship! + return if !@status.reply? || @status.account.id == @status.in_reply_to_account_id + + ActivityTracker.increment('activity:interactions') + return if @status.account.following?(@status.in_reply_to_account_id) + + PotentialFriendshipTracker.record(@status.account.id, @status.in_reply_to_account_id, :reply) + end +end |