diff options
author | Claire <claire.github-309c@sitedethib.com> | 2023-03-22 19:50:11 +0100 |
---|---|---|
committer | Claire <claire.github-309c@sitedethib.com> | 2023-03-22 19:50:11 +0100 |
commit | 5ac380c1226a8225a84835f6c70b7bdf00f99fb2 (patch) | |
tree | 432e2dce315060938ecc0ba05a9ae20fdb1da2d7 /app/models | |
parent | 02ac94490a67659c7cc669ead5b107b724db6e68 (diff) | |
parent | 2626097869c9520c21aaba73c9bcfe72c0f25f28 (diff) |
Merge branch 'main' into glitch-soc/merge-upstream
Conflicts: - `app/models/status.rb`: Upstream added lines close to a glitch-soc only line, not a real conflict. Applied upstream's changes (added hooks) while keeping glitch-soc's changes (`local_only` scope). - `config/environments/production.rb`: Upstream removed a header, while we have glitch-soc specific ones. Removed the header removed upstream.
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/account.rb | 7 | ||||
-rw-r--r-- | app/models/concerns/account_interactions.rb | 15 | ||||
-rw-r--r-- | app/models/concerns/status_threading_concern.rb | 14 | ||||
-rw-r--r-- | app/models/status.rb | 15 | ||||
-rw-r--r-- | app/models/webhook.rb | 3 |
5 files changed, 41 insertions, 13 deletions
diff --git a/app/models/account.rb b/app/models/account.rb index 2a5a33ca7..f2ed871e7 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -126,6 +126,8 @@ class Account < ApplicationRecord scope :not_excluded_by_account, ->(account) { where.not(id: account.excluded_from_timeline_account_ids) } scope :not_domain_blocked_by_account, ->(account) { where(arel_table[:domain].eq(nil).or(arel_table[:domain].not_in(account.excluded_from_timeline_domains))) } + after_update_commit :trigger_update_webhooks + delegate :email, :unconfirmed_email, :current_sign_in_at, @@ -591,4 +593,9 @@ class Account < ApplicationRecord CanonicalEmailBlock.where(reference_account: self).delete_all end + + # NOTE: the `account.created` webhook is triggered by the `User` model, not `Account`. + def trigger_update_webhooks + TriggerWebhookWorker.perform_async('account.updated', 'Account', id) if local? + end end diff --git a/app/models/concerns/account_interactions.rb b/app/models/concerns/account_interactions.rb index 1898516b0..48ab1349d 100644 --- a/app/models/concerns/account_interactions.rb +++ b/app/models/concerns/account_interactions.rb @@ -292,6 +292,21 @@ module AccountInteractions end end + def relations_map(account_ids, domains = nil, **options) + relations = { + blocked_by: Account.blocked_by_map(account_ids, id), + following: Account.following_map(account_ids, id), + } + + return relations if options[:skip_blocking_and_muting] + + relations.merge!({ + blocking: Account.blocking_map(account_ids, id), + muting: Account.muting_map(account_ids, id), + domain_blocking_by_domain: Account.domain_blocking_map_by_domain(domains, id), + }) + end + private def remove_potential_friendship(other_account) diff --git a/app/models/concerns/status_threading_concern.rb b/app/models/concerns/status_threading_concern.rb index 8b628beea..2ca3b66c2 100644 --- a/app/models/concerns/status_threading_concern.rb +++ b/app/models/concerns/status_threading_concern.rb @@ -79,7 +79,7 @@ module StatusThreadingConcern statuses = Status.with_accounts(ids).to_a account_ids = statuses.map(&:account_id).uniq domains = statuses.filter_map(&:account_domain).uniq - relations = relations_map_for_account(account, account_ids, domains) + relations = account&.relations_map(account_ids, domains) || {} statuses.reject! { |status| StatusFilter.new(status, account, relations).filtered? } @@ -108,16 +108,4 @@ module StatusThreadingConcern arr end - - def relations_map_for_account(account, account_ids, domains) - return {} if account.nil? - - { - blocking: Account.blocking_map(account_ids, account.id), - blocked_by: Account.blocked_by_map(account_ids, account.id), - muting: Account.muting_map(account_ids, account.id), - following: Account.following_map(account_ids, account.id), - domain_blocking_by_domain: Account.domain_blocking_map_by_domain(domains, account.id), - } - end end diff --git a/app/models/status.rb b/app/models/status.rb index bf102120e..e01ddb5c5 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -116,6 +116,9 @@ class Status < ApplicationRecord scope :not_local_only, -> { where(local_only: [false, nil]) } + after_create_commit :trigger_create_webhooks + after_update_commit :trigger_update_webhooks + cache_associated :application, :media_attachments, :conversation, @@ -142,6 +145,10 @@ class Status < ApplicationRecord REAL_TIME_WINDOW = 6.hours + def cache_key + "v2:#{super}" + end + def searchable_by(preloaded = nil) ids = [] @@ -597,4 +604,12 @@ class Status < ApplicationRecord reblog&.decrement_count!(:reblogs_count) if reblog? thread&.decrement_count!(:replies_count) if in_reply_to_id.present? && distributable? end + + def trigger_create_webhooks + TriggerWebhookWorker.perform_async('status.created', 'Status', id) if local? + end + + def trigger_update_webhooks + TriggerWebhookWorker.perform_async('status.updated', 'Status', id) if local? + end end diff --git a/app/models/webhook.rb b/app/models/webhook.rb index 4aafb1257..9a056a386 100644 --- a/app/models/webhook.rb +++ b/app/models/webhook.rb @@ -17,7 +17,10 @@ class Webhook < ApplicationRecord EVENTS = %w( account.approved account.created + account.updated report.created + status.created + status.updated ).freeze scope :enabled, -> { where(enabled: true) } |