Adding unified streamable notifications
This commit is contained in:
parent
3838e6836d
commit
da2ef4d676
20 changed files with 205 additions and 44 deletions
44
app/models/notification.rb
Normal file
44
app/models/notification.rb
Normal file
|
@ -0,0 +1,44 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Notification < ApplicationRecord
|
||||
include Paginable
|
||||
|
||||
belongs_to :account
|
||||
belongs_to :activity, polymorphic: true
|
||||
|
||||
belongs_to :mention, foreign_type: 'Mention', foreign_key: 'activity_id'
|
||||
belongs_to :status, foreign_type: 'Status', foreign_key: 'activity_id'
|
||||
belongs_to :follow, foreign_type: 'Follow', foreign_key: 'activity_id'
|
||||
belongs_to :favourite, foreign_type: 'Favourite', foreign_key: 'activity_id'
|
||||
|
||||
STATUS_INCLUDES = [:account, :media_attachments, mentions: :account, reblog: [:account, mentions: :account]].freeze
|
||||
|
||||
scope :with_includes, -> { includes(status: STATUS_INCLUDES, mention: [status: STATUS_INCLUDES], favourite: [:account, status: STATUS_INCLUDES], follow: :account) }
|
||||
|
||||
def type
|
||||
case activity_type
|
||||
when 'Status'
|
||||
:reblog
|
||||
else
|
||||
activity_type.downcase.to_sym
|
||||
end
|
||||
end
|
||||
|
||||
def from_account
|
||||
case type
|
||||
when :mention
|
||||
activity.status.account
|
||||
when :follow, :favourite, :reblog
|
||||
activity.account
|
||||
end
|
||||
end
|
||||
|
||||
def target_status
|
||||
case type
|
||||
when :reblog
|
||||
activity.reblog
|
||||
when :favourite, :mention
|
||||
activity.status
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue