You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.2 KiB

  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. scope :up_to, ->(id) { where(arel_table[:id].lteq(id)) }
  21. belongs_to :device
  22. belongs_to :from_account, class_name: 'Account'
  23. around_create Mastodon::Snowflake::Callbacks
  24. after_commit :push_to_streaming_api
  25. private
  26. def push_to_streaming_api
  27. return if destroyed? || !subscribed_to_timeline?
  28. PushEncryptedMessageWorker.perform_async(id)
  29. end
  30. def subscribed_to_timeline?
  31. Redis.current.exists?("subscribed:#{streaming_channel}")
  32. end
  33. def streaming_channel
  34. "timeline:#{device.account_id}:#{device.device_id}"
  35. end
  36. end