access_token_extension.rb 612 B

12345678910111213141516171819202122232425
  1. # frozen_string_literal: true
  2. module AccessTokenExtension
  3. extend ActiveSupport::Concern
  4. included do
  5. include Redisable
  6. has_many :web_push_subscriptions, class_name: 'Web::PushSubscription', inverse_of: :access_token
  7. after_commit :push_to_streaming_api
  8. end
  9. def revoke(clock = Time)
  10. update(revoked_at: clock.now.utc)
  11. end
  12. def update_last_used(request, clock = Time)
  13. update(last_used_at: clock.now.utc, last_used_ip: request.remote_ip)
  14. end
  15. def push_to_streaming_api
  16. redis.publish("timeline:access_token:#{id}", Oj.dump(event: :kill)) if revoked? || destroyed?
  17. end
  18. end