闭社主体 forked from https://github.com/tootsuite/mastodon
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.

50 lines
1.3 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. Rails.logger.info(streaming_channel)
  28. Rails.logger.info(subscribed_to_timeline?)
  29. return if destroyed? || !subscribed_to_timeline?
  30. PushEncryptedMessageWorker.perform_async(id)
  31. end
  32. def subscribed_to_timeline?
  33. Redis.current.exists("subscribed:#{streaming_channel}")
  34. end
  35. def streaming_channel
  36. "timeline:#{device.account_id}:#{device.device_id}"
  37. end
  38. end