This commit is contained in:
mgabdev
2020-04-17 01:35:46 -04:00
parent 35852e7fee
commit 4d7aee59c9
37 changed files with 568 additions and 319 deletions

View File

@@ -41,19 +41,28 @@ class Notification < ApplicationRecord
validates :account_id, uniqueness: { scope: [:activity_type, :activity_id] }
validates :activity_type, inclusion: { in: TYPE_CLASS_MAP.values }
scope :browserable, ->(exclude_types = [], account_id = nil) {
scope :browserable, ->(exclude_types = [], account_id = nil, only_verified = false, only_following = false) {
types = TYPE_CLASS_MAP.values - activity_types_from_types(exclude_types + [:follow_request])
# if account_id.nil?
puts "-----VERTS------"
Notification.includes(:from_account).where(activity_type: types, accounts: {
is_verified: true
})
# joins(:account).where({ 'from_account.id' => 6 })
# is_verified: false
# )
# els
# where(activity_type: types, from_account_id: account_id)
# end
# Notification.includes(:from_account).where(activity_type: types, accounts: {
# is_verified: true
# })
theOptions = { :activity_type => types }
if !account_id.nil?
theOptions.from_account_id = account_id
end
if only_verified
theOptions[:accounts] = {
:is_verified => true
}
Notification.includes(:from_account).where(theOptions)
else
where(theOptions)
end
}
cache_associated :from_account, status: STATUS_INCLUDES, mention: [status: STATUS_INCLUDES], favourite: [:account, status: STATUS_INCLUDES], follow: :account, poll: [status: STATUS_INCLUDES]