]> cat aescling's git repositories - mastodon.git/blob - app/models/encrypted_message.rb
Bump aws-sdk-s3 from 1.89.0 to 1.91.0 (#15879)
[mastodon.git] / app / models / encrypted_message.rb
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
18 class EncryptedMessage < ApplicationRecord
19 self.inheritance_column = nil
20
21 include Paginable
22
23 scope :up_to, ->(id) { where(arel_table[:id].lteq(id)) }
24
25 belongs_to :device
26 belongs_to :from_account, class_name: 'Account'
27
28 around_create Mastodon::Snowflake::Callbacks
29
30 after_commit :push_to_streaming_api
31
32 private
33
34 def push_to_streaming_api
35 return if destroyed? || !subscribed_to_timeline?
36
37 PushEncryptedMessageWorker.perform_async(id)
38 end
39
40 def subscribed_to_timeline?
41 Redis.current.exists?("subscribed:#{streaming_channel}")
42 end
43
44 def streaming_channel
45 "timeline:#{device.account_id}:#{device.device_id}"
46 end
47 end
This page took 0.072848 seconds and 4 git commands to generate.