Merge tag 'v2.6.0rc1' into instance_only_statuses
This commit is contained in:
96
app/javascript/mastodon/reducers/conversations.js
Normal file
96
app/javascript/mastodon/reducers/conversations.js
Normal file
@ -0,0 +1,96 @@
|
||||
import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
|
||||
import {
|
||||
CONVERSATIONS_MOUNT,
|
||||
CONVERSATIONS_UNMOUNT,
|
||||
CONVERSATIONS_FETCH_REQUEST,
|
||||
CONVERSATIONS_FETCH_SUCCESS,
|
||||
CONVERSATIONS_FETCH_FAIL,
|
||||
CONVERSATIONS_UPDATE,
|
||||
CONVERSATIONS_READ,
|
||||
} from '../actions/conversations';
|
||||
import compareId from '../compare_id';
|
||||
|
||||
const initialState = ImmutableMap({
|
||||
items: ImmutableList(),
|
||||
isLoading: false,
|
||||
hasMore: true,
|
||||
mounted: false,
|
||||
});
|
||||
|
||||
const conversationToMap = item => ImmutableMap({
|
||||
id: item.id,
|
||||
unread: item.unread,
|
||||
accounts: ImmutableList(item.accounts.map(a => a.id)),
|
||||
last_status: item.last_status.id,
|
||||
});
|
||||
|
||||
const updateConversation = (state, item) => state.update('items', list => {
|
||||
const index = list.findIndex(x => x.get('id') === item.id);
|
||||
const newItem = conversationToMap(item);
|
||||
|
||||
if (index === -1) {
|
||||
return list.unshift(newItem);
|
||||
} else {
|
||||
return list.set(index, newItem);
|
||||
}
|
||||
});
|
||||
|
||||
const expandNormalizedConversations = (state, conversations, next) => {
|
||||
let items = ImmutableList(conversations.map(conversationToMap));
|
||||
|
||||
return state.withMutations(mutable => {
|
||||
if (!items.isEmpty()) {
|
||||
mutable.update('items', list => {
|
||||
list = list.map(oldItem => {
|
||||
const newItemIndex = items.findIndex(x => x.get('id') === oldItem.get('id'));
|
||||
|
||||
if (newItemIndex === -1) {
|
||||
return oldItem;
|
||||
}
|
||||
|
||||
const newItem = items.get(newItemIndex);
|
||||
items = items.delete(newItemIndex);
|
||||
|
||||
return newItem;
|
||||
});
|
||||
|
||||
list = list.concat(items);
|
||||
|
||||
return list.sortBy(x => x.get('last_status'), (a, b) => compareId(a, b) * -1);
|
||||
});
|
||||
}
|
||||
|
||||
if (!next) {
|
||||
mutable.set('hasMore', false);
|
||||
}
|
||||
|
||||
mutable.set('isLoading', false);
|
||||
});
|
||||
};
|
||||
|
||||
export default function conversations(state = initialState, action) {
|
||||
switch (action.type) {
|
||||
case CONVERSATIONS_FETCH_REQUEST:
|
||||
return state.set('isLoading', true);
|
||||
case CONVERSATIONS_FETCH_FAIL:
|
||||
return state.set('isLoading', false);
|
||||
case CONVERSATIONS_FETCH_SUCCESS:
|
||||
return expandNormalizedConversations(state, action.conversations, action.next);
|
||||
case CONVERSATIONS_UPDATE:
|
||||
return updateConversation(state, action.conversation);
|
||||
case CONVERSATIONS_MOUNT:
|
||||
return state.update('mounted', count => count + 1);
|
||||
case CONVERSATIONS_UNMOUNT:
|
||||
return state.update('mounted', count => count - 1);
|
||||
case CONVERSATIONS_READ:
|
||||
return state.update('items', list => list.map(item => {
|
||||
if (item.get('id') === action.id) {
|
||||
return item.set('unread', false);
|
||||
}
|
||||
|
||||
return item;
|
||||
}));
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
@ -4,12 +4,12 @@ import {
|
||||
DROPDOWN_MENU_CLOSE,
|
||||
} from '../actions/dropdown_menu';
|
||||
|
||||
const initialState = Immutable.Map({ openId: null, placement: null });
|
||||
const initialState = Immutable.Map({ openId: null, placement: null, keyboard: false });
|
||||
|
||||
export default function dropdownMenu(state = initialState, action) {
|
||||
switch (action.type) {
|
||||
case DROPDOWN_MENU_OPEN:
|
||||
return state.merge({ openId: action.id, placement: action.placement });
|
||||
return state.merge({ openId: action.id, placement: action.placement, keyboard: action.keyboard });
|
||||
case DROPDOWN_MENU_CLOSE:
|
||||
return state.get('openId') === action.id ? state.set('openId', null) : state;
|
||||
default:
|
||||
|
@ -27,6 +27,7 @@ import custom_emojis from './custom_emojis';
|
||||
import lists from './lists';
|
||||
import listEditor from './list_editor';
|
||||
import filters from './filters';
|
||||
import conversations from './conversations';
|
||||
|
||||
const reducers = {
|
||||
dropdown_menu,
|
||||
@ -57,6 +58,7 @@ const reducers = {
|
||||
lists,
|
||||
listEditor,
|
||||
filters,
|
||||
conversations,
|
||||
};
|
||||
|
||||
export default combineReducers(reducers);
|
||||
|
@ -69,7 +69,7 @@ const expandNormalizedNotifications = (state, notifications, next) => {
|
||||
}
|
||||
|
||||
if (!next) {
|
||||
mutable.set('hasMore', true);
|
||||
mutable.set('hasMore', false);
|
||||
}
|
||||
|
||||
mutable.set('isLoading', false);
|
||||
|
Reference in New Issue
Block a user