about summary refs log tree commit diff
path: root/app/lib/access_token_extension.rb
diff options
context:
space:
mode:
authorThibaut Girka <thib@sitedethib.com>2020-11-14 00:30:36 +0100
committerThibaut Girka <thib@sitedethib.com>2020-11-14 00:30:36 +0100
commitde5cc20dd8e15eb7e90d65392a6e6f9145746913 (patch)
tree2391ed3e8c3cb95c50d7e5fe3d35b36148989cb7 /app/lib/access_token_extension.rb
parent8ffae82fa61385a33f819e037aa741d0b3e99187 (diff)
parent0a4d0e8320ae9fc5c446828743008db3b45bcb13 (diff)
Merge branch 'master' into glitch-soc/merge-upstream
Conflicts:
- `app/controllers/concerns/sign_in_token_authentication_concern.rb`:
  Conflict caused because of glitch-soc's theming system.
  Took upstream's new code and applied the theming system changes on top
  of it.
- `app/controllers/concerns/two_factor_authentication_concern.rb`:
  Conflict caused because of glitch-soc's theming system.
  Took upstream's new code and applied the theming system changes on top
  of it.
Diffstat (limited to 'app/lib/access_token_extension.rb')
-rw-r--r--app/lib/access_token_extension.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/app/lib/access_token_extension.rb b/app/lib/access_token_extension.rb
new file mode 100644
index 000000000..3e184e775
--- /dev/null
+++ b/app/lib/access_token_extension.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+module AccessTokenExtension
+  extend ActiveSupport::Concern
+
+  included do
+    after_commit :push_to_streaming_api
+  end
+
+  def revoke(clock = Time)
+    update(revoked_at: clock.now.utc)
+  end
+
+  def push_to_streaming_api
+    Redis.current.publish("timeline:access_token:#{id}", Oj.dump(event: :kill)) if revoked? || destroyed?
+  end
+end