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]

View File

@@ -87,7 +87,8 @@ class Status < ApplicationRecord
scope :remote, -> { where(local: false).or(where.not(uri: nil)) }
scope :local, -> { where(local: true).or(where(uri: nil)) }
scope :without_replies, -> { where('statuses.reply = FALSE OR statuses.in_reply_to_account_id = statuses.account_id') }
scope :only_replies, -> { where('statuses.reply = TRUE') }
scope :without_replies, -> { where('statuses.reply = FALSE') }
scope :without_reblogs, -> { where('statuses.reblog_of_id IS NULL') }
scope :with_public_visibility, -> { where(visibility: :public) }
scope :tagged_with, ->(tag) { joins(:statuses_tags).where(statuses_tags: { tag_id: tag }) }