about summary refs log tree commit diff
path: root/app/models/status.rb
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2023-03-22 19:50:11 +0100
committerClaire <claire.github-309c@sitedethib.com>2023-03-22 19:50:11 +0100
commit5ac380c1226a8225a84835f6c70b7bdf00f99fb2 (patch)
tree432e2dce315060938ecc0ba05a9ae20fdb1da2d7 /app/models/status.rb
parent02ac94490a67659c7cc669ead5b107b724db6e68 (diff)
parent2626097869c9520c21aaba73c9bcfe72c0f25f28 (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/status.rb')
-rw-r--r--app/models/status.rb15
1 files changed, 15 insertions, 0 deletions
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