From afc74a89b2f8eb6b2f10085ee0aefe0661267c70 Mon Sep 17 00:00:00 2001 From: Emelia Smith Date: Tue, 9 Jul 2024 21:46:23 +0200 Subject: [PATCH] Add after unblock domain from account service --- app/models/account_domain_block.rb | 6 ++++++ .../after_unblock_domain_from_account_service.rb | 12 ++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 app/services/after_unblock_domain_from_account_service.rb diff --git a/app/models/account_domain_block.rb b/app/models/account_domain_block.rb index 753935d6af6..0614ce6c1d4 100644 --- a/app/models/account_domain_block.rb +++ b/app/models/account_domain_block.rb @@ -18,6 +18,8 @@ class AccountDomainBlock < ApplicationRecord belongs_to :account validates :domain, presence: true, uniqueness: { scope: :account_id }, domain: true + after_destroy :notify_streaming + after_commit :invalidate_domain_blocking_cache after_commit :invalidate_follow_recommendations_cache @@ -31,4 +33,8 @@ class AccountDomainBlock < ApplicationRecord def invalidate_follow_recommendations_cache Rails.cache.delete("follow_recommendations/#{account_id}") end + + def notify_streaming + AfterUnblockDomainFromAccountService.call(account_id, domain) + end end diff --git a/app/services/after_unblock_domain_from_account_service.rb b/app/services/after_unblock_domain_from_account_service.rb new file mode 100644 index 00000000000..351207c8bee --- /dev/null +++ b/app/services/after_unblock_domain_from_account_service.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +class AfterUnblockDomainFromAccountService < BaseService + include Redisable + + # This service does not delete an AccountDomainBlock record, + # it's meant to be called after such a record has been created + # synchronously, to "clean up" + def call(account, domain) + redis.publish('system', Oj.dump(event: :domain_blocks_changed, account: account.id, target_domain: domain)) + end +end