Reload notifications when accepted notifications are merged (streaming only) (#31419)
This commit is contained in:
parent
d4f135bc6d
commit
53c183f899
11 changed files with 192 additions and 24 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
class UnfilterNotificationsWorker
|
||||
include Sidekiq::Worker
|
||||
include Redisable
|
||||
|
||||
# Earlier versions of the feature passed a `notification_request` ID
|
||||
# If `to_account_id` is passed, the first argument is an account ID
|
||||
|
@ -9,19 +10,20 @@ class UnfilterNotificationsWorker
|
|||
def perform(notification_request_or_account_id, from_account_id = nil)
|
||||
if from_account_id.present?
|
||||
@notification_request = nil
|
||||
@from_account = Account.find(from_account_id)
|
||||
@recipient = Account.find(notification_request_or_account_id)
|
||||
@from_account = Account.find_by(id: from_account_id)
|
||||
@recipient = Account.find_by(id: notification_request_or_account_id)
|
||||
else
|
||||
@notification_request = NotificationRequest.find(notification_request_or_account_id)
|
||||
@from_account = @notification_request.from_account
|
||||
@recipient = @notification_request.account
|
||||
@notification_request = NotificationRequest.find_by(id: notification_request_or_account_id)
|
||||
@from_account = @notification_request&.from_account
|
||||
@recipient = @notification_request&.account
|
||||
end
|
||||
|
||||
return if @from_account.nil? || @recipient.nil?
|
||||
|
||||
push_to_conversations!
|
||||
unfilter_notifications!
|
||||
remove_request!
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
true
|
||||
decrement_worker_count!
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -45,4 +47,17 @@ class UnfilterNotificationsWorker
|
|||
def notifications_with_private_mentions
|
||||
filtered_notifications.where(type: :mention).joins(mention: :status).merge(Status.where(visibility: :direct)).includes(mention: :status)
|
||||
end
|
||||
|
||||
def decrement_worker_count!
|
||||
value = redis.decr("notification_unfilter_jobs:#{@recipient.id}")
|
||||
push_streaming_event! if value <= 0 && subscribed_to_streaming_api?
|
||||
end
|
||||
|
||||
def push_streaming_event!
|
||||
redis.publish("timeline:#{@recipient.id}:notifications", Oj.dump(event: :notifications_merged, payload: '1'))
|
||||
end
|
||||
|
||||
def subscribed_to_streaming_api?
|
||||
redis.exists?("subscribed:timeline:#{@recipient.id}") || redis.exists?("subscribed:timeline:#{@recipient.id}:notifications")
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue