Add option to disable real-time updates in web UI (#9984)
Fix #9031 Fix #7913
This commit is contained in:
parent
4562c3cb7e
commit
9b1d3e4acb
20 changed files with 181 additions and 70 deletions
|
@ -6,6 +6,7 @@ import {
|
|||
NOTIFICATIONS_FILTER_SET,
|
||||
NOTIFICATIONS_CLEAR,
|
||||
NOTIFICATIONS_SCROLL_TOP,
|
||||
NOTIFICATIONS_LOAD_PENDING,
|
||||
} from '../actions/notifications';
|
||||
import {
|
||||
ACCOUNT_BLOCK_SUCCESS,
|
||||
|
@ -16,6 +17,7 @@ import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
|
|||
import compareId from '../compare_id';
|
||||
|
||||
const initialState = ImmutableMap({
|
||||
pendingItems: ImmutableList(),
|
||||
items: ImmutableList(),
|
||||
hasMore: true,
|
||||
top: false,
|
||||
|
@ -31,7 +33,11 @@ const notificationToMap = notification => ImmutableMap({
|
|||
status: notification.status ? notification.status.id : null,
|
||||
});
|
||||
|
||||
const normalizeNotification = (state, notification) => {
|
||||
const normalizeNotification = (state, notification, usePendingItems) => {
|
||||
if (usePendingItems) {
|
||||
return state.update('pendingItems', list => list.unshift(notificationToMap(notification)));
|
||||
}
|
||||
|
||||
const top = state.get('top');
|
||||
|
||||
if (!top) {
|
||||
|
@ -47,7 +53,7 @@ const normalizeNotification = (state, notification) => {
|
|||
});
|
||||
};
|
||||
|
||||
const expandNormalizedNotifications = (state, notifications, next) => {
|
||||
const expandNormalizedNotifications = (state, notifications, next, usePendingItems) => {
|
||||
let items = ImmutableList();
|
||||
|
||||
notifications.forEach((n, i) => {
|
||||
|
@ -56,7 +62,7 @@ const expandNormalizedNotifications = (state, notifications, next) => {
|
|||
|
||||
return state.withMutations(mutable => {
|
||||
if (!items.isEmpty()) {
|
||||
mutable.update('items', list => {
|
||||
mutable.update(usePendingItems ? 'pendingItems' : 'items', list => {
|
||||
const lastIndex = 1 + list.findLastIndex(
|
||||
item => item !== null && (compareId(item.get('id'), items.last().get('id')) > 0 || item.get('id') === items.last().get('id'))
|
||||
);
|
||||
|
@ -78,7 +84,8 @@ const expandNormalizedNotifications = (state, notifications, next) => {
|
|||
};
|
||||
|
||||
const filterNotifications = (state, relationship) => {
|
||||
return state.update('items', list => list.filterNot(item => item !== null && item.get('account') === relationship.id));
|
||||
const helper = list => list.filterNot(item => item !== null && item.get('account') === relationship.id);
|
||||
return state.update('items', helper).update('pendingItems', helper);
|
||||
};
|
||||
|
||||
const updateTop = (state, top) => {
|
||||
|
@ -90,34 +97,37 @@ const updateTop = (state, top) => {
|
|||
};
|
||||
|
||||
const deleteByStatus = (state, statusId) => {
|
||||
return state.update('items', list => list.filterNot(item => item !== null && item.get('status') === statusId));
|
||||
const helper = list => list.filterNot(item => item !== null && item.get('status') === statusId);
|
||||
return state.update('items', helper).update('pendingItems', helper);
|
||||
};
|
||||
|
||||
export default function notifications(state = initialState, action) {
|
||||
switch(action.type) {
|
||||
case NOTIFICATIONS_LOAD_PENDING:
|
||||
return state.update('items', list => state.get('pendingItems').concat(list.take(40))).set('pendingItems', ImmutableList()).set('unread', 0);
|
||||
case NOTIFICATIONS_EXPAND_REQUEST:
|
||||
return state.set('isLoading', true);
|
||||
case NOTIFICATIONS_EXPAND_FAIL:
|
||||
return state.set('isLoading', false);
|
||||
case NOTIFICATIONS_FILTER_SET:
|
||||
return state.set('items', ImmutableList()).set('hasMore', true);
|
||||
return state.set('items', ImmutableList()).set('pendingItems', ImmutableList()).set('hasMore', true);
|
||||
case NOTIFICATIONS_SCROLL_TOP:
|
||||
return updateTop(state, action.top);
|
||||
case NOTIFICATIONS_UPDATE:
|
||||
return normalizeNotification(state, action.notification);
|
||||
return normalizeNotification(state, action.notification, action.usePendingItems);
|
||||
case NOTIFICATIONS_EXPAND_SUCCESS:
|
||||
return expandNormalizedNotifications(state, action.notifications, action.next);
|
||||
return expandNormalizedNotifications(state, action.notifications, action.next, action.usePendingItems);
|
||||
case ACCOUNT_BLOCK_SUCCESS:
|
||||
return filterNotifications(state, action.relationship);
|
||||
case ACCOUNT_MUTE_SUCCESS:
|
||||
return action.relationship.muting_notifications ? filterNotifications(state, action.relationship) : state;
|
||||
case NOTIFICATIONS_CLEAR:
|
||||
return state.set('items', ImmutableList()).set('hasMore', false);
|
||||
return state.set('items', ImmutableList()).set('pendingItems', ImmutableList()).set('hasMore', false);
|
||||
case TIMELINE_DELETE:
|
||||
return deleteByStatus(state, action.id);
|
||||
case TIMELINE_DISCONNECT:
|
||||
return action.timeline === 'home' ?
|
||||
state.update('items', items => items.first() ? items.unshift(null) : items) :
|
||||
state.update(action.usePendingItems ? 'pendingItems' : 'items', items => items.first() ? items.unshift(null) : items) :
|
||||
state;
|
||||
default:
|
||||
return state;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue