1 # frozen_string_literal: true
2 # == Schema Information
4 # Table name: encrypted_messages
6 # id :bigint(8) not null, primary key
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
18 class EncryptedMessage
< ApplicationRecord
19 self.inheritance_column
= nil
23 scope
:up_to, ->(id
) { where(arel_table
[:id].lteq(id
)) }
26 belongs_to
:from_account, class_name
: 'Account'
28 around_create Mastodon
::Snowflake::Callbacks
30 after_commit
:push_to_streaming_api
34 def push_to_streaming_api
35 return if destroyed
? || !subscribed_to_timeline
?
37 PushEncryptedMessageWorker
.perform_async(id
)
40 def subscribed_to_timeline
?
41 Redis
.current
.exists
?("subscribed:#{streaming_channel}")
45 "timeline:#{device.account_id}:#{device.device_id}"