mirror of
https://github.com/mastodon/mastodon.git
synced 2025-09-06 01:41:08 +00:00
Add notifications for inbound quotes (#35618)
This commit is contained in:
parent
d09f866daa
commit
29a5f059d2
|
@ -73,6 +73,9 @@ class Notification < ApplicationRecord
|
||||||
'admin.report': {
|
'admin.report': {
|
||||||
filterable: false,
|
filterable: false,
|
||||||
}.freeze,
|
}.freeze,
|
||||||
|
quote: {
|
||||||
|
filterable: true,
|
||||||
|
}.freeze,
|
||||||
}.freeze
|
}.freeze
|
||||||
|
|
||||||
TYPES = PROPERTIES.keys.freeze
|
TYPES = PROPERTIES.keys.freeze
|
||||||
|
@ -81,6 +84,7 @@ class Notification < ApplicationRecord
|
||||||
status: :status,
|
status: :status,
|
||||||
reblog: [status: :reblog],
|
reblog: [status: :reblog],
|
||||||
mention: [mention: :status],
|
mention: [mention: :status],
|
||||||
|
quote: [quote: :status],
|
||||||
favourite: [favourite: :status],
|
favourite: [favourite: :status],
|
||||||
poll: [poll: :status],
|
poll: [poll: :status],
|
||||||
update: :status,
|
update: :status,
|
||||||
|
@ -102,6 +106,7 @@ class Notification < ApplicationRecord
|
||||||
belongs_to :account_relationship_severance_event, inverse_of: false
|
belongs_to :account_relationship_severance_event, inverse_of: false
|
||||||
belongs_to :account_warning, inverse_of: false
|
belongs_to :account_warning, inverse_of: false
|
||||||
belongs_to :generated_annual_report, inverse_of: false
|
belongs_to :generated_annual_report, inverse_of: false
|
||||||
|
belongs_to :quote, inverse_of: :notification
|
||||||
end
|
end
|
||||||
|
|
||||||
validates :type, inclusion: { in: TYPES }
|
validates :type, inclusion: { in: TYPES }
|
||||||
|
@ -122,6 +127,8 @@ class Notification < ApplicationRecord
|
||||||
favourite&.status
|
favourite&.status
|
||||||
when :mention
|
when :mention
|
||||||
mention&.status
|
mention&.status
|
||||||
|
when :quote
|
||||||
|
quote&.status
|
||||||
when :poll
|
when :poll
|
||||||
poll&.status
|
poll&.status
|
||||||
end
|
end
|
||||||
|
@ -174,6 +181,8 @@ class Notification < ApplicationRecord
|
||||||
notification.mention.status = cached_status
|
notification.mention.status = cached_status
|
||||||
when :poll
|
when :poll
|
||||||
notification.poll.status = cached_status
|
notification.poll.status = cached_status
|
||||||
|
when :quote
|
||||||
|
notification.quote.status = cached_status
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -192,7 +201,7 @@ class Notification < ApplicationRecord
|
||||||
return unless new_record?
|
return unless new_record?
|
||||||
|
|
||||||
case activity_type
|
case activity_type
|
||||||
when 'Status', 'Follow', 'Favourite', 'FollowRequest', 'Poll', 'Report'
|
when 'Status', 'Follow', 'Favourite', 'FollowRequest', 'Poll', 'Report', 'Quote'
|
||||||
self.from_account_id = activity&.account_id
|
self.from_account_id = activity&.account_id
|
||||||
when 'Mention'
|
when 'Mention'
|
||||||
self.from_account_id = activity&.status&.account_id
|
self.from_account_id = activity&.status&.account_id
|
||||||
|
|
|
@ -49,6 +49,6 @@ class NotificationRequest < ApplicationRecord
|
||||||
private
|
private
|
||||||
|
|
||||||
def prepare_notifications_count
|
def prepare_notifications_count
|
||||||
self.notifications_count = Notification.where(account: account, from_account: from_account, type: :mention, filtered: true).limit(MAX_MEANINGFUL_COUNT).count
|
self.notifications_count = Notification.where(account: account, from_account: from_account, type: [:mention, :quote], filtered: true).limit(MAX_MEANINGFUL_COUNT).count
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
class Quote < ApplicationRecord
|
class Quote < ApplicationRecord
|
||||||
include Paginable
|
include Paginable
|
||||||
|
|
||||||
|
has_one :notification, as: :activity, dependent: :destroy
|
||||||
|
|
||||||
BACKGROUND_REFRESH_INTERVAL = 1.week.freeze
|
BACKGROUND_REFRESH_INTERVAL = 1.week.freeze
|
||||||
REFRESH_DEADLINE = 6.hours
|
REFRESH_DEADLINE = 6.hours
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ class REST::NotificationSerializer < ActiveModel::Serializer
|
||||||
end
|
end
|
||||||
|
|
||||||
def status_type?
|
def status_type?
|
||||||
[:favourite, :reblog, :status, :mention, :poll, :update].include?(object.type)
|
[:favourite, :reblog, :status, :mention, :poll, :update, :quote].include?(object.type)
|
||||||
end
|
end
|
||||||
|
|
||||||
def report_type?
|
def report_type?
|
||||||
|
|
|
@ -40,6 +40,7 @@ class FanOutOnWriteService < BaseService
|
||||||
deliver_to_self!
|
deliver_to_self!
|
||||||
|
|
||||||
unless @options[:skip_notifications]
|
unless @options[:skip_notifications]
|
||||||
|
notify_quoted_account!
|
||||||
notify_mentioned_accounts!
|
notify_mentioned_accounts!
|
||||||
notify_about_update! if update?
|
notify_about_update! if update?
|
||||||
end
|
end
|
||||||
|
@ -69,6 +70,12 @@ class FanOutOnWriteService < BaseService
|
||||||
FeedManager.instance.push_to_home(@account, @status, update: update?) if @account.local?
|
FeedManager.instance.push_to_home(@account, @status, update: update?) if @account.local?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def notify_quoted_account!
|
||||||
|
return unless @status.quote&.quoted_account&.local? && @status.quote&.accepted?
|
||||||
|
|
||||||
|
LocalNotificationWorker.perform_async(@status.quote.quoted_account_id, @status.quote.id, 'Quote', 'quote')
|
||||||
|
end
|
||||||
|
|
||||||
def notify_mentioned_accounts!
|
def notify_mentioned_accounts!
|
||||||
@status.active_mentions.where.not(id: @options[:silenced_account_ids] || []).joins(:account).merge(Account.local).select(:id, :account_id).reorder(nil).find_in_batches do |mentions|
|
@status.active_mentions.where.not(id: @options[:silenced_account_ids] || []).joins(:account).merge(Account.local).select(:id, :account_id).reorder(nil).find_in_batches do |mentions|
|
||||||
LocalNotificationWorker.push_bulk(mentions) do |mention|
|
LocalNotificationWorker.push_bulk(mentions) do |mention|
|
||||||
|
|
|
@ -247,7 +247,7 @@ class NotifyService < BaseService
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_notification_request!
|
def update_notification_request!
|
||||||
return unless @notification.type == :mention
|
return unless %i(mention quote).include?(@notification.type)
|
||||||
|
|
||||||
notification_request = NotificationRequest.find_or_initialize_by(account_id: @recipient.id, from_account_id: @notification.from_account_id)
|
notification_request = NotificationRequest.find_or_initialize_by(account_id: @recipient.id, from_account_id: @notification.from_account_id)
|
||||||
notification_request.last_status_id = @notification.target_status.id
|
notification_request.last_status_id = @notification.target_status.id
|
||||||
|
|
Loading…
Reference in New Issue
Block a user