Add setting to notify mentions email only for dm
This commit is contained in:
parent
17ecde6a6e
commit
2faf4c44f7
|
@ -96,7 +96,7 @@ class Settings::PreferencesController < Settings::BaseController
|
|||
:setting_default_search_searchability,
|
||||
:setting_show_reload_button,
|
||||
notification_emails: %i(follow follow_request reblog favourite emoji_reaction status_reference mention digest report pending_account trending_tag),
|
||||
interactions: %i(must_be_follower must_be_following must_be_following_dm)
|
||||
interactions: %i(must_be_follower must_be_following must_be_following_dm must_be_dm_to_send_email)
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -67,6 +67,10 @@ class NotifyService < BaseService
|
|||
@recipient.user.settings.interactions['must_be_following'] && !following_sender?
|
||||
end
|
||||
|
||||
def optional_non_direct_message?
|
||||
message? && @recipient.user.settings.interactions['must_be_dm_to_send_email'] && !@notification.target_status.direct_visibility?
|
||||
end
|
||||
|
||||
def message?
|
||||
@notification.type == :mention
|
||||
end
|
||||
|
@ -199,7 +203,7 @@ class NotifyService < BaseService
|
|||
end
|
||||
|
||||
def send_email!
|
||||
return if @notification.activity.nil?
|
||||
return if @notification.activity.nil? || optional_non_direct_message?
|
||||
NotificationMailer.public_send(@notification.type, @recipient, @notification).deliver_later(wait: 2.minutes)
|
||||
end
|
||||
|
||||
|
|
|
@ -37,3 +37,4 @@
|
|||
= ff.input :must_be_follower, as: :boolean, wrapper: :with_label
|
||||
= ff.input :must_be_following, as: :boolean, wrapper: :with_label
|
||||
= ff.input :must_be_following_dm, as: :boolean, wrapper: :with_label
|
||||
= ff.input :must_be_dm_to_send_email, as: :boolean, wrapper: :with_label, fedibird_features: true
|
||||
|
|
|
@ -303,6 +303,7 @@ en:
|
|||
show_reblogs: Show boost
|
||||
timeline: Timeline
|
||||
interactions:
|
||||
must_be_dm_to_send_email: Block e-mail notifications from mentions to you other than direct messages
|
||||
must_be_follower: Block notifications from non-followers
|
||||
must_be_following: Block notifications from people you don't follow
|
||||
must_be_following_dm: Block direct messages from people you don't follow
|
||||
|
|
|
@ -307,6 +307,7 @@ ja:
|
|||
show_reblogs: ブーストを表示
|
||||
timeline: タイムライン
|
||||
interactions:
|
||||
must_be_dm_to_send_email: ダイレクトメッセージ以外のメンションからの電子メール通知をブロックする
|
||||
must_be_follower: フォロワー以外からの通知をブロック
|
||||
must_be_following: フォローしていないユーザーからの通知をブロック
|
||||
must_be_following_dm: フォローしていないユーザーからのダイレクトメッセージをブロック
|
||||
|
|
|
@ -78,6 +78,7 @@ defaults: &defaults
|
|||
pending_account: true
|
||||
trending_tag: true
|
||||
interactions:
|
||||
must_be_dm_to_send_email: false
|
||||
must_be_follower: false
|
||||
must_be_following: false
|
||||
must_be_following_dm: false
|
||||
|
|
|
@ -161,5 +161,54 @@ RSpec.describe NotifyService, type: :service do
|
|||
is_expected.to_not change(ActionMailer::Base.deliveries, :count).from(0)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with mentions' do
|
||||
let(:type) { :mention }
|
||||
|
||||
before do
|
||||
user.settings.notification_emails = user.settings.notification_emails.merge('mention' => true)
|
||||
user.settings.interactions = user.settings.interactions.merge('must_be_dm_to_send_email' => enabled)
|
||||
end
|
||||
|
||||
context 'if must_be_dm_to_send_email is true' do
|
||||
let(:enabled) { true }
|
||||
|
||||
describe 'with direct messsages' do
|
||||
let(:activity) { Fabricate(:mention, account: recipient, status: Fabricate(:status, account: sender, visibility: :direct)) }
|
||||
|
||||
it 'sends email' do
|
||||
is_expected.to change(ActionMailer::Base.deliveries, :count).by(1)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with public messsages' do
|
||||
let(:activity) { Fabricate(:mention, account: recipient, status: Fabricate(:status, account: sender, visibility: :public)) }
|
||||
|
||||
it "doesn't send email" do
|
||||
is_expected.to_not change(ActionMailer::Base.deliveries, :count).from(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'if must_be_dm_to_send_email is false' do
|
||||
let(:enabled) { false }
|
||||
|
||||
describe 'with direct messsages' do
|
||||
let(:activity) { Fabricate(:mention, account: recipient, status: Fabricate(:status, account: sender, visibility: :direct)) }
|
||||
|
||||
it 'sends email' do
|
||||
is_expected.to change(ActionMailer::Base.deliveries, :count).by(1)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with public messsages' do
|
||||
let(:activity) { Fabricate(:mention, account: recipient, status: Fabricate(:status, account: sender, visibility: :public)) }
|
||||
|
||||
it 'sends email' do
|
||||
is_expected.to change(ActionMailer::Base.deliveries, :count).by(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue