1
0
Fork 0
forked from gitea/nas

Merge remote-tracking branch 'parent/main' into upstream-20240308

This commit is contained in:
KMY 2024-03-08 08:08:34 +09:00
commit fa96bf2e87
106 changed files with 1107 additions and 253 deletions

View file

@ -12,6 +12,7 @@
# account_id :bigint(8) not null
# from_account_id :bigint(8) not null
# type :string
# filtered :boolean default(FALSE), not null
#
class Notification < ApplicationRecord
@ -112,7 +113,7 @@ class Notification < ApplicationRecord
end
class << self
def browserable(types: [], exclude_types: [], from_account_id: nil)
def browserable(types: [], exclude_types: [], from_account_id: nil, include_filtered: false)
requested_types = if types.empty?
TYPES
else
@ -122,6 +123,7 @@ class Notification < ApplicationRecord
requested_types -= exclude_types.map(&:to_sym)
all.tap do |scope|
scope.merge!(where(filtered: false)) unless include_filtered || from_account_id.present?
scope.merge!(where(from_account_id: from_account_id)) if from_account_id.present?
scope.merge!(where(type: requested_types)) unless requested_types.size == TYPES.size
end
@ -182,6 +184,8 @@ class Notification < ApplicationRecord
after_initialize :set_from_account
before_validation :set_from_account
after_destroy :remove_from_notification_request
private
def set_from_account
@ -196,4 +200,9 @@ class Notification < ApplicationRecord
self.from_account_id = activity&.id
end
end
def remove_from_notification_request
notification_request = NotificationRequest.find_by(account_id: account_id, from_account_id: from_account_id)
notification_request&.reconsider_existence!
end
end