Skip to content

Commit 633d3de

Browse files
committed
Change account domain block to clear out notifications and follows
1 parent ab3126e commit 633d3de

7 files changed

Lines changed: 51 additions & 35 deletions

File tree

app/javascript/mastodon/actions/domain_blocks.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export function blockDomain(domain) {
2323
api(getState).post('/api/v1/domain_blocks', { domain }).then(() => {
2424
const at_domain = '@' + domain;
2525
const accounts = getState().get('accounts').filter(item => item.get('acct').endsWith(at_domain)).valueSeq().map(item => item.get('id'));
26+
2627
dispatch(blockDomainSuccess(domain, accounts));
2728
}).catch(err => {
2829
dispatch(blockDomainFail(domain, err));

app/javascript/mastodon/reducers/conversations.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88
CONVERSATIONS_UPDATE,
99
CONVERSATIONS_READ,
1010
} from '../actions/conversations';
11+
import { ACCOUNT_BLOCK_SUCCESS, ACCOUNT_MUTE_SUCCESS } from 'mastodon/actions/accounts';
12+
import { DOMAIN_BLOCK_SUCCESS } from 'mastodon/actions/domain_blocks';
1113
import compareId from '../compare_id';
1214

1315
const initialState = ImmutableMap({
@@ -74,6 +76,10 @@ const expandNormalizedConversations = (state, conversations, next, isLoadingRece
7476
});
7577
};
7678

79+
const filterConversations = (state, accountIds) => {
80+
return state.update('items', list => list.filterNot(item => item.get('accounts').some(accountId => accountIds.includes(accountId))));
81+
};
82+
7783
export default function conversations(state = initialState, action) {
7884
switch (action.type) {
7985
case CONVERSATIONS_FETCH_REQUEST:
@@ -96,6 +102,11 @@ export default function conversations(state = initialState, action) {
96102

97103
return item;
98104
}));
105+
case ACCOUNT_BLOCK_SUCCESS:
106+
case ACCOUNT_MUTE_SUCCESS:
107+
return filterConversations(state, [action.relationship.id]);
108+
case DOMAIN_BLOCK_SUCCESS:
109+
return filterConversations(state, action.accounts);
99110
default:
100111
return state;
101112
}

app/javascript/mastodon/reducers/notifications.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
ACCOUNT_BLOCK_SUCCESS,
1313
ACCOUNT_MUTE_SUCCESS,
1414
} from '../actions/accounts';
15+
import { DOMAIN_BLOCK_SUCCESS } from 'mastodon/actions/domain_blocks';
1516
import { TIMELINE_DELETE, TIMELINE_DISCONNECT } from '../actions/timelines';
1617
import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
1718
import compareId from '../compare_id';
@@ -83,8 +84,8 @@ const expandNormalizedNotifications = (state, notifications, next, usePendingIte
8384
});
8485
};
8586

86-
const filterNotifications = (state, relationship) => {
87-
const helper = list => list.filterNot(item => item !== null && item.get('account') === relationship.id);
87+
const filterNotifications = (state, accountIds) => {
88+
const helper = list => list.filterNot(item => item !== null && accountIds.includes(item.get('account')));
8889
return state.update('items', helper).update('pendingItems', helper);
8990
};
9091

@@ -118,9 +119,11 @@ export default function notifications(state = initialState, action) {
118119
case NOTIFICATIONS_EXPAND_SUCCESS:
119120
return expandNormalizedNotifications(state, action.notifications, action.next, action.usePendingItems);
120121
case ACCOUNT_BLOCK_SUCCESS:
121-
return filterNotifications(state, action.relationship);
122+
return filterNotifications(state, [action.relationship.id]);
122123
case ACCOUNT_MUTE_SUCCESS:
123-
return action.relationship.muting_notifications ? filterNotifications(state, action.relationship) : state;
124+
return action.relationship.muting_notifications ? filterNotifications(state, [action.relationship.id]) : state;
125+
case DOMAIN_BLOCK_SUCCESS:
126+
return filterNotifications(state, action.accounts);
124127
case NOTIFICATIONS_CLEAR:
125128
return state.set('items', ImmutableList()).set('pendingItems', ImmutableList()).set('hasMore', false);
126129
case TIMELINE_DELETE:

app/javascript/mastodon/reducers/suggestions.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import {
44
SUGGESTIONS_FETCH_FAIL,
55
SUGGESTIONS_DISMISS,
66
} from '../actions/suggestions';
7+
import { ACCOUNT_BLOCK_SUCCESS, ACCOUNT_MUTE_SUCCESS } from 'mastodon/actions/accounts';
8+
import { DOMAIN_BLOCK_SUCCESS } from 'mastodon/actions/domain_blocks';
79
import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable';
810

911
const initialState = ImmutableMap({
@@ -24,6 +26,11 @@ export default function suggestionsReducer(state = initialState, action) {
2426
return state.set('isLoading', false);
2527
case SUGGESTIONS_DISMISS:
2628
return state.update('items', list => list.filterNot(id => id === action.id));
29+
case ACCOUNT_BLOCK_SUCCESS:
30+
case ACCOUNT_MUTE_SUCCESS:
31+
return state.update('items', list => list.filterNot(id => id === action.relationship.id));
32+
case DOMAIN_BLOCK_SUCCESS:
33+
return state.update('items', list => list.filterNot(id => action.accounts.includes(id)));
2734
default:
2835
return state;
2936
}

app/services/after_block_domain_from_account_service.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,24 @@ def call(account, domain)
1010
@account = account
1111
@domain = domain
1212

13+
clear_notifications!
14+
remove_follows!
1315
reject_existing_followers!
1416
reject_pending_follow_requests!
1517
end
1618

1719
private
1820

21+
def remove_follows!
22+
@account.active_relationships.where(account: Account.where(domain: @domain)).includes(:target_account).reorder(nil).find_each do |follow|
23+
UnfollowService.new.call(@account, follow.target_account)
24+
end
25+
end
26+
27+
def clear_notifications!
28+
Notification.where(account: @account).where(from_account: Account.where(domain: @domain)).in_batches.delete_all
29+
end
30+
1931
def reject_existing_followers!
2032
@account.passive_relationships.where(account: Account.where(domain: @domain)).includes(:account).reorder(nil).find_each do |follow|
2133
reject_follow!(follow)

app/services/after_block_service.rb

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,25 @@
22

33
class AfterBlockService < BaseService
44
def call(account, target_account)
5-
clear_home_feed(account, target_account)
6-
clear_notifications(account, target_account)
7-
clear_conversations(account, target_account)
5+
@account = account
6+
@target_account = target_account
7+
8+
clear_home_feed!
9+
clear_notifications!
10+
clear_conversations!
811
end
912

1013
private
1114

12-
def clear_home_feed(account, target_account)
13-
FeedManager.instance.clear_from_timeline(account, target_account)
15+
def clear_home_feed!
16+
FeedManager.instance.clear_from_timeline(@account, @target_account)
1417
end
1518

16-
def clear_conversations(account, target_account)
17-
AccountConversation.where(account: account)
18-
.where('? = ANY(participant_account_ids)', target_account.id)
19-
.in_batches
20-
.destroy_all
19+
def clear_conversations!
20+
AccountConversation.where(account: @account).where('? = ANY(participant_account_ids)', @target_account.id).in_batches.destroy_all
2121
end
2222

23-
def clear_notifications(account, target_account)
24-
Notification.where(account: account)
25-
.joins(:follow)
26-
.where(activity_type: 'Follow', follows: { account_id: target_account.id })
27-
.delete_all
28-
29-
Notification.where(account: account)
30-
.joins(mention: :status)
31-
.where(activity_type: 'Mention', statuses: { account_id: target_account.id })
32-
.delete_all
33-
34-
Notification.where(account: account)
35-
.joins(:favourite)
36-
.where(activity_type: 'Favourite', favourites: { account_id: target_account.id })
37-
.delete_all
38-
39-
Notification.where(account: account)
40-
.joins(:status)
41-
.where(activity_type: 'Status', statuses: { account_id: target_account.id })
42-
.delete_all
23+
def clear_notifications!
24+
Notification.where(account: @account).where(from_account: @target_account).in_batches.delete_all
4325
end
4426
end

app/services/follow_service.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def call(source_account, target_account, reblogs: nil)
1313
target_account = ResolveAccountService.new.call(target_account, skip_webfinger: true)
1414

1515
raise ActiveRecord::RecordNotFound if target_account.nil? || target_account.id == source_account.id || target_account.suspended?
16-
raise Mastodon::NotPermittedError if target_account.blocking?(source_account) || source_account.blocking?(target_account) || target_account.moved? || (!target_account.local? && target_account.ostatus?)
16+
raise Mastodon::NotPermittedError if target_account.blocking?(source_account) || source_account.blocking?(target_account) || target_account.moved? || (!target_account.local? && target_account.ostatus?) || source_account.domain_blocking?(target_account.domain)
1717

1818
if source_account.following?(target_account)
1919
# We're already following this account, but we'll call follow! again to

0 commit comments

Comments
 (0)