Add option to be notified when a followed user posts (#13546)

* Add bell button

Fix #4890

* Remove duplicate type from post-deployment migration

* Fix legacy class type mappings

* Improve query performance with better index

* Fix validation

* Remove redundant index from notifications
This commit is contained in:
Eugen Rochko
2020-09-18 17:26:45 +02:00
committed by GitHub
parent 75e4bd9413
commit 974b1b79ce
42 changed files with 330 additions and 112 deletions

View File

@ -23,7 +23,10 @@ class FeedInsertWorker
private
def check_and_insert
perform_push unless feed_filtered?
return if feed_filtered?
perform_push
perform_notify if notify?
end
def feed_filtered?
@ -35,6 +38,12 @@ class FeedInsertWorker
end
end
def notify?
return false if @type != :home || @status.reblog? || (@status.reply? && @status.in_reply_to_account_id != @status.account_id)
Follow.find_by(account: @follower, target_account: @status.account)&.notify?
end
def perform_push
case @type
when :home
@ -43,4 +52,8 @@ class FeedInsertWorker
FeedManager.instance.push_to_list(@list, @status)
end
end
def perform_notify
NotifyService.new.call(@follower, :status, @status)
end
end

View File

@ -3,7 +3,7 @@
class LocalNotificationWorker
include Sidekiq::Worker
def perform(receiver_account_id, activity_id = nil, activity_class_name = nil)
def perform(receiver_account_id, activity_id = nil, activity_class_name = nil, type = nil)
if activity_id.nil? && activity_class_name.nil?
activity = Mention.find(receiver_account_id)
receiver = activity.account
@ -12,7 +12,7 @@ class LocalNotificationWorker
activity = activity_class_name.constantize.find(activity_id)
end
NotifyService.new.call(receiver, activity)
NotifyService.new.call(receiver, type || activity_class_name.underscore, activity)
rescue ActiveRecord::RecordNotFound
true
end

View File

@ -11,12 +11,12 @@ class PollExpirationNotifyWorker
# Notify poll owner and remote voters
if poll.local?
ActivityPub::DistributePollUpdateWorker.perform_async(poll.status.id)
NotifyService.new.call(poll.account, poll)
NotifyService.new.call(poll.account, :poll, poll)
end
# Notify local voters
poll.votes.includes(:account).map(&:account).select(&:local?).each do |account|
NotifyService.new.call(account, poll)
NotifyService.new.call(account, :poll, poll)
end
rescue ActiveRecord::RecordNotFound
true

View File

@ -11,6 +11,7 @@ class RefollowWorker
target_account.passive_relationships.where(account: Account.where(domain: nil)).includes(:account).reorder(nil).find_each do |follow|
reblogs = follow.show_reblogs?
notify = follow.notify?
# Locally unfollow remote account
follower = follow.account
@ -18,7 +19,7 @@ class RefollowWorker
# Schedule re-follow
begin
FollowService.new.call(follower, target_account, reblogs: reblogs)
FollowService.new.call(follower, target_account, reblogs: reblogs, notify: notify)
rescue Mastodon::NotPermittedError, ActiveRecord::RecordNotFound, Mastodon::UnexpectedResponseError, HTTP::Error, OpenSSL::SSL::SSLError
next
end

View File

@ -10,10 +10,11 @@ class UnfollowFollowWorker
old_target_account = Account.find(old_target_account_id)
new_target_account = Account.find(new_target_account_id)
follow = follower_account.active_relationships.find_by(target_account: old_target_account)
follow = follower_account.active_relationships.find_by(target_account: old_target_account)
reblogs = follow&.show_reblogs?
notify = follow&.notify?
FollowService.new.call(follower_account, new_target_account, reblogs: reblogs, bypass_locked: bypass_locked)
FollowService.new.call(follower_account, new_target_account, reblogs: reblogs, notify: notify, bypass_locked: bypass_locked)
UnfollowService.new.call(follower_account, old_target_account, skip_unmerge: true)
rescue ActiveRecord::RecordNotFound, Mastodon::NotPermittedError
true