Keep notification when muting_notifications is true (#7311)
* Keep notification when muting_notifications is true * Retrun mute object * Fix testshrike
parent
d0cdd5cf94
commit
71a7cea73f
|
@ -105,7 +105,7 @@ export default function notifications(state = initialState, action) {
|
||||||
return expandNormalizedNotifications(state, action.notifications, action.next);
|
return expandNormalizedNotifications(state, action.notifications, action.next);
|
||||||
case ACCOUNT_BLOCK_SUCCESS:
|
case ACCOUNT_BLOCK_SUCCESS:
|
||||||
case ACCOUNT_MUTE_SUCCESS:
|
case ACCOUNT_MUTE_SUCCESS:
|
||||||
return filterNotifications(state, action.relationship);
|
return action.relationship.muting_notifications ? filterNotifications(state, action.relationship) : state;
|
||||||
case NOTIFICATIONS_CLEAR:
|
case NOTIFICATIONS_CLEAR:
|
||||||
return state.set('items', ImmutableList()).set('hasMore', false);
|
return state.set('items', ImmutableList()).set('hasMore', false);
|
||||||
case TIMELINE_DELETE:
|
case TIMELINE_DELETE:
|
||||||
|
|
|
@ -93,6 +93,7 @@ module AccountInteractions
|
||||||
if mute.hide_notifications? != notifications
|
if mute.hide_notifications? != notifications
|
||||||
mute.update!(hide_notifications: notifications)
|
mute.update!(hide_notifications: notifications)
|
||||||
end
|
end
|
||||||
|
mute
|
||||||
end
|
end
|
||||||
|
|
||||||
def mute_conversation!(conversation)
|
def mute_conversation!(conversation)
|
||||||
|
|
|
@ -3,9 +3,13 @@
|
||||||
class MuteService < BaseService
|
class MuteService < BaseService
|
||||||
def call(account, target_account, notifications: nil)
|
def call(account, target_account, notifications: nil)
|
||||||
return if account.id == target_account.id
|
return if account.id == target_account.id
|
||||||
FeedManager.instance.clear_from_timeline(account, target_account)
|
|
||||||
mute = account.mute!(target_account, notifications: notifications)
|
mute = account.mute!(target_account, notifications: notifications)
|
||||||
BlockWorker.perform_async(account.id, target_account.id)
|
if mute.hide_notifications?
|
||||||
|
BlockWorker.perform_async(account.id, target_account.id)
|
||||||
|
else
|
||||||
|
FeedManager.instance.clear_from_timeline(account, target_account)
|
||||||
|
end
|
||||||
mute
|
mute
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -108,13 +108,15 @@ describe AccountInteractions do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#mute!' do
|
describe '#mute!' do
|
||||||
|
subject { account.mute!(target_account, notifications: arg_notifications) }
|
||||||
|
|
||||||
context 'Mute does not exist yet' do
|
context 'Mute does not exist yet' do
|
||||||
context 'arg :notifications is nil' do
|
context 'arg :notifications is nil' do
|
||||||
let(:arg_notifications) { nil }
|
let(:arg_notifications) { nil }
|
||||||
|
|
||||||
it 'creates Mute, and returns nil' do
|
it 'creates Mute, and returns Mute' do
|
||||||
expect do
|
expect do
|
||||||
expect(account.mute!(target_account, notifications: arg_notifications)).to be nil
|
expect(subject).to be_kind_of Mute
|
||||||
end.to change { account.mute_relationships.count }.by 1
|
end.to change { account.mute_relationships.count }.by 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -122,9 +124,9 @@ describe AccountInteractions do
|
||||||
context 'arg :notifications is false' do
|
context 'arg :notifications is false' do
|
||||||
let(:arg_notifications) { false }
|
let(:arg_notifications) { false }
|
||||||
|
|
||||||
it 'creates Mute, and returns nil' do
|
it 'creates Mute, and returns Mute' do
|
||||||
expect do
|
expect do
|
||||||
expect(account.mute!(target_account, notifications: arg_notifications)).to be nil
|
expect(subject).to be_kind_of Mute
|
||||||
end.to change { account.mute_relationships.count }.by 1
|
end.to change { account.mute_relationships.count }.by 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -132,9 +134,9 @@ describe AccountInteractions do
|
||||||
context 'arg :notifications is true' do
|
context 'arg :notifications is true' do
|
||||||
let(:arg_notifications) { true }
|
let(:arg_notifications) { true }
|
||||||
|
|
||||||
it 'creates Mute, and returns nil' do
|
it 'creates Mute, and returns Mute' do
|
||||||
expect do
|
expect do
|
||||||
expect(account.mute!(target_account, notifications: arg_notifications)).to be nil
|
expect(subject).to be_kind_of Mute
|
||||||
end.to change { account.mute_relationships.count }.by 1
|
end.to change { account.mute_relationships.count }.by 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -158,36 +160,30 @@ describe AccountInteractions do
|
||||||
context 'arg :notifications is nil' do
|
context 'arg :notifications is nil' do
|
||||||
let(:arg_notifications) { nil }
|
let(:arg_notifications) { nil }
|
||||||
|
|
||||||
it 'returns nil without updating mute.hide_notifications' do
|
it 'returns Mute without updating mute.hide_notifications' do
|
||||||
expect do
|
expect do
|
||||||
expect(account.mute!(target_account, notifications: arg_notifications)).to be nil
|
expect(subject).to be_kind_of Mute
|
||||||
mute = account.mute_relationships.find_by(target_account: target_account)
|
end.not_to change { mute.reload.hide_notifications? }.from(true)
|
||||||
expect(mute.hide_notifications?).to be true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'arg :notifications is false' do
|
context 'arg :notifications is false' do
|
||||||
let(:arg_notifications) { false }
|
let(:arg_notifications) { false }
|
||||||
|
|
||||||
it 'returns true, and updates mute.hide_notifications false' do
|
it 'returns Mute, and updates mute.hide_notifications false' do
|
||||||
expect do
|
expect do
|
||||||
expect(account.mute!(target_account, notifications: arg_notifications)).to be true
|
expect(subject).to be_kind_of Mute
|
||||||
mute = account.mute_relationships.find_by(target_account: target_account)
|
end.to change { mute.reload.hide_notifications? }.from(true).to(false)
|
||||||
expect(mute.hide_notifications?).to be false
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'arg :notifications is true' do
|
context 'arg :notifications is true' do
|
||||||
let(:arg_notifications) { true }
|
let(:arg_notifications) { true }
|
||||||
|
|
||||||
it 'returns nil without updating mute.hide_notifications' do
|
it 'returns Mute without updating mute.hide_notifications' do
|
||||||
expect do
|
expect do
|
||||||
expect(account.mute!(target_account, notifications: arg_notifications)).to be nil
|
expect(subject).to be_kind_of Mute
|
||||||
mute = account.mute_relationships.find_by(target_account: target_account)
|
end.not_to change { mute.reload.hide_notifications? }.from(true)
|
||||||
expect(mute.hide_notifications?).to be true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -198,36 +194,30 @@ describe AccountInteractions do
|
||||||
context 'arg :notifications is nil' do
|
context 'arg :notifications is nil' do
|
||||||
let(:arg_notifications) { nil }
|
let(:arg_notifications) { nil }
|
||||||
|
|
||||||
it 'returns true, and updates mute.hide_notifications true' do
|
it 'returns Mute, and updates mute.hide_notifications true' do
|
||||||
expect do
|
expect do
|
||||||
expect(account.mute!(target_account, notifications: arg_notifications)).to be true
|
expect(subject).to be_kind_of Mute
|
||||||
mute = account.mute_relationships.find_by(target_account: target_account)
|
end.to change { mute.reload.hide_notifications? }.from(false).to(true)
|
||||||
expect(mute.hide_notifications?).to be true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'arg :notifications is false' do
|
context 'arg :notifications is false' do
|
||||||
let(:arg_notifications) { false }
|
let(:arg_notifications) { false }
|
||||||
|
|
||||||
it 'returns nil without updating mute.hide_notifications' do
|
it 'returns Mute without updating mute.hide_notifications' do
|
||||||
expect do
|
expect do
|
||||||
expect(account.mute!(target_account, notifications: arg_notifications)).to be nil
|
expect(subject).to be_kind_of Mute
|
||||||
mute = account.mute_relationships.find_by(target_account: target_account)
|
end.not_to change { mute.reload.hide_notifications? }.from(false)
|
||||||
expect(mute.hide_notifications?).to be false
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'arg :notifications is true' do
|
context 'arg :notifications is true' do
|
||||||
let(:arg_notifications) { true }
|
let(:arg_notifications) { true }
|
||||||
|
|
||||||
it 'returns true, and updates mute.hide_notifications true' do
|
it 'returns Mute, and updates mute.hide_notifications true' do
|
||||||
expect do
|
expect do
|
||||||
expect(account.mute!(target_account, notifications: arg_notifications)).to be true
|
expect(subject).to be_kind_of Mute
|
||||||
mute = account.mute_relationships.find_by(target_account: target_account)
|
end.to change { mute.reload.hide_notifications? }.from(false).to(true)
|
||||||
expect(mute.hide_notifications?).to be true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue