Skip to content

Commit

Permalink
Add setting to notify mentions email only for dm
Browse files Browse the repository at this point in the history
  • Loading branch information
noellabo authored and atsu1125 committed Mar 13, 2023
1 parent 07dfad6 commit b1905a4
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/controllers/settings/preferences_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def user_settings_params
:setting_do_not_allow_follow,
:setting_auto_accept_followed,
notification_emails: %i(follow follow_request reblog favourite 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
end
6 changes: 5 additions & 1 deletion app/services/notify_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ def optional_non_following?
@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
Expand Down Expand Up @@ -192,7 +196,7 @@ def send_push_notifications!
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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,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
1 change: 1 addition & 0 deletions config/locales/simple_form.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ en:
featured_tag:
name: Hashtag
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
Expand Down
1 change: 1 addition & 0 deletions config/locales/simple_form.ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ ja:
featured_tag:
name: ハッシュタグ
interactions:
must_be_dm_to_send_email: ダイレクトメッセージ以外のメンションからの電子メール通知をブロックする
must_be_follower: フォロワー以外からの通知をブロック
must_be_following: フォローしていないユーザーからの通知をブロック
must_be_following_dm: フォローしていないユーザーからのダイレクトメッセージをブロック
Expand Down
1 change: 1 addition & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,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
Expand Down
49 changes: 49 additions & 0 deletions spec/services/notify_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,5 +174,54 @@
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

0 comments on commit b1905a4

Please sign in to comment.