[Glitch] Change account domain block to clear out notifications and follows
Port 93a6ab5a32
to glitch-soc
Signed-off-by: Thibaut Girka <thib@sitedethib.com>
lolsob-rspec
parent
6c7a3268c9
commit
16b5fe3ac3
|
@ -23,6 +23,7 @@ export function blockDomain(domain) {
|
||||||
api(getState).post('/api/v1/domain_blocks', { domain }).then(() => {
|
api(getState).post('/api/v1/domain_blocks', { domain }).then(() => {
|
||||||
const at_domain = '@' + domain;
|
const at_domain = '@' + domain;
|
||||||
const accounts = getState().get('accounts').filter(item => item.get('acct').endsWith(at_domain)).valueSeq().map(item => item.get('id'));
|
const accounts = getState().get('accounts').filter(item => item.get('acct').endsWith(at_domain)).valueSeq().map(item => item.get('id'));
|
||||||
|
|
||||||
dispatch(blockDomainSuccess(domain, accounts));
|
dispatch(blockDomainSuccess(domain, accounts));
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
dispatch(blockDomainFail(domain, err));
|
dispatch(blockDomainFail(domain, err));
|
||||||
|
|
|
@ -8,6 +8,8 @@ import {
|
||||||
CONVERSATIONS_UPDATE,
|
CONVERSATIONS_UPDATE,
|
||||||
CONVERSATIONS_READ,
|
CONVERSATIONS_READ,
|
||||||
} from '../actions/conversations';
|
} from '../actions/conversations';
|
||||||
|
import { ACCOUNT_BLOCK_SUCCESS, ACCOUNT_MUTE_SUCCESS } from 'flavours/glitch/actions/accounts';
|
||||||
|
import { DOMAIN_BLOCK_SUCCESS } from 'flavours/glitch/actions/domain_blocks';
|
||||||
import compareId from 'flavours/glitch/util/compare_id';
|
import compareId from 'flavours/glitch/util/compare_id';
|
||||||
|
|
||||||
const initialState = ImmutableMap({
|
const initialState = ImmutableMap({
|
||||||
|
@ -74,6 +76,10 @@ const expandNormalizedConversations = (state, conversations, next, isLoadingRece
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const filterConversations = (state, accountIds) => {
|
||||||
|
return state.update('items', list => list.filterNot(item => item.get('accounts').some(accountId => accountIds.includes(accountId))));
|
||||||
|
};
|
||||||
|
|
||||||
export default function conversations(state = initialState, action) {
|
export default function conversations(state = initialState, action) {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case CONVERSATIONS_FETCH_REQUEST:
|
case CONVERSATIONS_FETCH_REQUEST:
|
||||||
|
@ -96,6 +102,11 @@ export default function conversations(state = initialState, action) {
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
}));
|
}));
|
||||||
|
case ACCOUNT_BLOCK_SUCCESS:
|
||||||
|
case ACCOUNT_MUTE_SUCCESS:
|
||||||
|
return filterConversations(state, [action.relationship.id]);
|
||||||
|
case DOMAIN_BLOCK_SUCCESS:
|
||||||
|
return filterConversations(state, action.accounts);
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ import {
|
||||||
ACCOUNT_BLOCK_SUCCESS,
|
ACCOUNT_BLOCK_SUCCESS,
|
||||||
ACCOUNT_MUTE_SUCCESS,
|
ACCOUNT_MUTE_SUCCESS,
|
||||||
} from 'flavours/glitch/actions/accounts';
|
} from 'flavours/glitch/actions/accounts';
|
||||||
|
import { DOMAIN_BLOCK_SUCCESS } from 'flavours/glitch/actions/domain_blocks';
|
||||||
import { TIMELINE_DELETE, TIMELINE_DISCONNECT } from 'flavours/glitch/actions/timelines';
|
import { TIMELINE_DELETE, TIMELINE_DISCONNECT } from 'flavours/glitch/actions/timelines';
|
||||||
import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
|
import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
|
||||||
import compareId from 'flavours/glitch/util/compare_id';
|
import compareId from 'flavours/glitch/util/compare_id';
|
||||||
|
@ -110,8 +111,8 @@ const expandNormalizedNotifications = (state, notifications, next, usePendingIte
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const filterNotifications = (state, relationship) => {
|
const filterNotifications = (state, accountIds) => {
|
||||||
const helper = list => list.filterNot(item => item !== null && item.get('account') === relationship.id);
|
const helper = list => list.filterNot(item => item !== null && accountIds.includes(item.get('account')));
|
||||||
return state.update('items', helper).update('pendingItems', helper);
|
return state.update('items', helper).update('pendingItems', helper);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -217,9 +218,11 @@ export default function notifications(state = initialState, action) {
|
||||||
case NOTIFICATIONS_EXPAND_SUCCESS:
|
case NOTIFICATIONS_EXPAND_SUCCESS:
|
||||||
return expandNormalizedNotifications(state, action.notifications, action.next, action.usePendingItems);
|
return expandNormalizedNotifications(state, action.notifications, action.next, action.usePendingItems);
|
||||||
case ACCOUNT_BLOCK_SUCCESS:
|
case ACCOUNT_BLOCK_SUCCESS:
|
||||||
return filterNotifications(state, action.relationship);
|
return filterNotifications(state, [action.relationship.id]);
|
||||||
case ACCOUNT_MUTE_SUCCESS:
|
case ACCOUNT_MUTE_SUCCESS:
|
||||||
return action.relationship.muting_notifications ? filterNotifications(state, action.relationship) : state;
|
return action.relationship.muting_notifications ? filterNotifications(state, [action.relationship.id]) : state;
|
||||||
|
case DOMAIN_BLOCK_SUCCESS:
|
||||||
|
return filterNotifications(state, action.accounts);
|
||||||
case NOTIFICATIONS_CLEAR:
|
case NOTIFICATIONS_CLEAR:
|
||||||
return state.set('items', ImmutableList()).set('pendingItems', ImmutableList()).set('hasMore', false);
|
return state.set('items', ImmutableList()).set('pendingItems', ImmutableList()).set('hasMore', false);
|
||||||
case TIMELINE_DELETE:
|
case TIMELINE_DELETE:
|
||||||
|
|
|
@ -4,6 +4,8 @@ import {
|
||||||
SUGGESTIONS_FETCH_FAIL,
|
SUGGESTIONS_FETCH_FAIL,
|
||||||
SUGGESTIONS_DISMISS,
|
SUGGESTIONS_DISMISS,
|
||||||
} from '../actions/suggestions';
|
} from '../actions/suggestions';
|
||||||
|
import { ACCOUNT_BLOCK_SUCCESS, ACCOUNT_MUTE_SUCCESS } from 'mastodon/actions/accounts';
|
||||||
|
import { DOMAIN_BLOCK_SUCCESS } from 'mastodon/actions/domain_blocks';
|
||||||
import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable';
|
import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable';
|
||||||
|
|
||||||
const initialState = ImmutableMap({
|
const initialState = ImmutableMap({
|
||||||
|
@ -24,6 +26,11 @@ export default function suggestionsReducer(state = initialState, action) {
|
||||||
return state.set('isLoading', false);
|
return state.set('isLoading', false);
|
||||||
case SUGGESTIONS_DISMISS:
|
case SUGGESTIONS_DISMISS:
|
||||||
return state.update('items', list => list.filterNot(id => id === action.id));
|
return state.update('items', list => list.filterNot(id => id === action.id));
|
||||||
|
case ACCOUNT_BLOCK_SUCCESS:
|
||||||
|
case ACCOUNT_MUTE_SUCCESS:
|
||||||
|
return state.update('items', list => list.filterNot(id => id === action.relationship.id));
|
||||||
|
case DOMAIN_BLOCK_SUCCESS:
|
||||||
|
return state.update('items', list => list.filterNot(id => action.accounts.includes(id)));
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue