diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2016-11-20 00:33:02 +0100 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2016-11-20 19:39:58 +0100 |
commit | da2ef4d676ff71e6ab3edf8d1a7cee8bf6b6d353 (patch) | |
tree | f73fa34a3323a70d5dcba360f781bce5325e3ed1 /app/models | |
parent | 3838e6836d47797a4e8ca20afa70eebefb68da26 (diff) |
Adding unified streamable notifications
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/notification.rb | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/app/models/notification.rb b/app/models/notification.rb new file mode 100644 index 000000000..66aefcb74 --- /dev/null +++ b/app/models/notification.rb @@ -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 |