Add notification policies and notification requests in web UI (#29433)
This commit is contained in:
parent
19efa1b9f1
commit
c10bbf5fe3
35 changed files with 1278 additions and 252 deletions
|
@ -27,6 +27,8 @@ import media_attachments from './media_attachments';
|
|||
import meta from './meta';
|
||||
import { modalReducer } from './modal';
|
||||
import mutes from './mutes';
|
||||
import { notificationPolicyReducer } from './notification_policy';
|
||||
import { notificationRequestsReducer } from './notification_requests';
|
||||
import notifications from './notifications';
|
||||
import picture_in_picture from './picture_in_picture';
|
||||
import polls from './polls';
|
||||
|
@ -84,6 +86,8 @@ const reducers = {
|
|||
history,
|
||||
tags,
|
||||
followed_tags,
|
||||
notificationPolicy: notificationPolicyReducer,
|
||||
notificationRequests: notificationRequestsReducer,
|
||||
};
|
||||
|
||||
// We want the root state to be an ImmutableRecord, which is an object with a defined list of keys,
|
||||
|
|
12
app/javascript/mastodon/reducers/notification_policy.js
Normal file
12
app/javascript/mastodon/reducers/notification_policy.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
import { fromJS } from 'immutable';
|
||||
|
||||
import { NOTIFICATION_POLICY_FETCH_SUCCESS } from 'mastodon/actions/notifications';
|
||||
|
||||
export const notificationPolicyReducer = (state = null, action) => {
|
||||
switch(action.type) {
|
||||
case NOTIFICATION_POLICY_FETCH_SUCCESS:
|
||||
return fromJS(action.policy);
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
96
app/javascript/mastodon/reducers/notification_requests.js
Normal file
96
app/javascript/mastodon/reducers/notification_requests.js
Normal file
|
@ -0,0 +1,96 @@
|
|||
import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable';
|
||||
|
||||
import {
|
||||
NOTIFICATION_REQUESTS_EXPAND_REQUEST,
|
||||
NOTIFICATION_REQUESTS_EXPAND_SUCCESS,
|
||||
NOTIFICATION_REQUESTS_EXPAND_FAIL,
|
||||
NOTIFICATION_REQUESTS_FETCH_REQUEST,
|
||||
NOTIFICATION_REQUESTS_FETCH_SUCCESS,
|
||||
NOTIFICATION_REQUESTS_FETCH_FAIL,
|
||||
NOTIFICATION_REQUEST_FETCH_REQUEST,
|
||||
NOTIFICATION_REQUEST_FETCH_SUCCESS,
|
||||
NOTIFICATION_REQUEST_FETCH_FAIL,
|
||||
NOTIFICATION_REQUEST_ACCEPT_REQUEST,
|
||||
NOTIFICATION_REQUEST_DISMISS_REQUEST,
|
||||
NOTIFICATIONS_FOR_REQUEST_FETCH_REQUEST,
|
||||
NOTIFICATIONS_FOR_REQUEST_FETCH_SUCCESS,
|
||||
NOTIFICATIONS_FOR_REQUEST_FETCH_FAIL,
|
||||
NOTIFICATIONS_FOR_REQUEST_EXPAND_REQUEST,
|
||||
NOTIFICATIONS_FOR_REQUEST_EXPAND_SUCCESS,
|
||||
NOTIFICATIONS_FOR_REQUEST_EXPAND_FAIL,
|
||||
} from 'mastodon/actions/notifications';
|
||||
|
||||
import { notificationToMap } from './notifications';
|
||||
|
||||
const initialState = ImmutableMap({
|
||||
items: ImmutableList(),
|
||||
isLoading: false,
|
||||
next: null,
|
||||
current: ImmutableMap({
|
||||
isLoading: false,
|
||||
item: null,
|
||||
removed: false,
|
||||
notifications: ImmutableMap({
|
||||
items: ImmutableList(),
|
||||
isLoading: false,
|
||||
next: null,
|
||||
}),
|
||||
}),
|
||||
});
|
||||
|
||||
const normalizeRequest = request => fromJS({
|
||||
...request,
|
||||
account: request.account.id,
|
||||
});
|
||||
|
||||
const removeRequest = (state, id) => {
|
||||
if (state.getIn(['current', 'item', 'id']) === id) {
|
||||
state = state.setIn(['current', 'removed'], true);
|
||||
}
|
||||
|
||||
return state.update('items', list => list.filterNot(item => item.get('id') === id));
|
||||
};
|
||||
|
||||
export const notificationRequestsReducer = (state = initialState, action) => {
|
||||
switch(action.type) {
|
||||
case NOTIFICATION_REQUESTS_FETCH_SUCCESS:
|
||||
return state.withMutations(map => {
|
||||
map.update('items', list => ImmutableList(action.requests.map(normalizeRequest)).concat(list));
|
||||
map.set('isLoading', false);
|
||||
map.update('next', next => next ?? action.next);
|
||||
});
|
||||
case NOTIFICATION_REQUESTS_EXPAND_SUCCESS:
|
||||
return state.withMutations(map => {
|
||||
map.update('items', list => list.concat(ImmutableList(action.requests.map(normalizeRequest))));
|
||||
map.set('isLoading', false);
|
||||
map.set('next', action.next);
|
||||
});
|
||||
case NOTIFICATION_REQUESTS_EXPAND_REQUEST:
|
||||
case NOTIFICATION_REQUESTS_FETCH_REQUEST:
|
||||
return state.set('isLoading', true);
|
||||
case NOTIFICATION_REQUESTS_EXPAND_FAIL:
|
||||
case NOTIFICATION_REQUESTS_FETCH_FAIL:
|
||||
return state.set('isLoading', false);
|
||||
case NOTIFICATION_REQUEST_ACCEPT_REQUEST:
|
||||
case NOTIFICATION_REQUEST_DISMISS_REQUEST:
|
||||
return removeRequest(state, action.id);
|
||||
case NOTIFICATION_REQUEST_FETCH_REQUEST:
|
||||
return state.set('current', initialState.get('current').set('isLoading', true));
|
||||
case NOTIFICATION_REQUEST_FETCH_SUCCESS:
|
||||
return state.update('current', map => map.set('isLoading', false).set('item', normalizeRequest(action.request)));
|
||||
case NOTIFICATION_REQUEST_FETCH_FAIL:
|
||||
return state.update('current', map => map.set('isLoading', false));
|
||||
case NOTIFICATIONS_FOR_REQUEST_FETCH_REQUEST:
|
||||
case NOTIFICATIONS_FOR_REQUEST_EXPAND_REQUEST:
|
||||
return state.setIn(['current', 'notifications', 'isLoading'], true);
|
||||
case NOTIFICATIONS_FOR_REQUEST_FETCH_SUCCESS:
|
||||
return state.updateIn(['current', 'notifications'], map => map.set('isLoading', false).update('items', list => ImmutableList(action.notifications.map(notificationToMap)).concat(list)).update('next', next => next ?? action.next));
|
||||
case NOTIFICATIONS_FOR_REQUEST_EXPAND_SUCCESS:
|
||||
return state.updateIn(['current', 'notifications'], map => map.set('isLoading', false).update('items', list => list.concat(ImmutableList(action.notifications.map(notificationToMap)))).set('next', action.next));
|
||||
case NOTIFICATIONS_FOR_REQUEST_FETCH_FAIL:
|
||||
case NOTIFICATIONS_FOR_REQUEST_EXPAND_FAIL:
|
||||
return state.setIn(['current', 'notifications', 'isLoading'], false);
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
|
@ -48,7 +48,7 @@ const initialState = ImmutableMap({
|
|||
browserPermission: 'default',
|
||||
});
|
||||
|
||||
const notificationToMap = notification => ImmutableMap({
|
||||
export const notificationToMap = notification => ImmutableMap({
|
||||
id: notification.id,
|
||||
type: notification.type,
|
||||
account: notification.account.id,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue