1
0

encrypted_message.rb 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # frozen_string_literal: true
  2. # == Schema Information
  3. #
  4. # Table name: encrypted_messages
  5. #
  6. # id :bigint(8) not null, primary key
  7. # device_id :bigint(8)
  8. # from_account_id :bigint(8)
  9. # from_device_id :string default(""), not null
  10. # type :integer default(0), not null
  11. # body :text default(""), not null
  12. # digest :text default(""), not null
  13. # message_franking :text default(""), not null
  14. # created_at :datetime not null
  15. # updated_at :datetime not null
  16. #
  17. class EncryptedMessage < ApplicationRecord
  18. self.inheritance_column = nil
  19. include Paginable
  20. include Redisable
  21. scope :up_to, ->(id) { where(arel_table[:id].lteq(id)) }
  22. belongs_to :device
  23. belongs_to :from_account, class_name: 'Account'
  24. around_create Mastodon::Snowflake::Callbacks
  25. after_commit :push_to_streaming_api
  26. private
  27. def push_to_streaming_api
  28. return if destroyed? || !subscribed_to_timeline?
  29. PushEncryptedMessageWorker.perform_async(id)
  30. end
  31. def subscribed_to_timeline?
  32. redis.exists?("subscribed:#{streaming_channel}")
  33. end
  34. def streaming_channel
  35. "timeline:#{device.account_id}:#{device.device_id}"
  36. end
  37. end