mattermost-mobile/app/reducers/views/team.js
enahum 3fdfe92800 Data cleanup (#1070)
* Add message retention middleware and config

* Data cleanup middleware
2017-10-30 11:23:19 -04:00

55 lines
1.3 KiB
JavaScript

// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import {combineReducers} from 'redux';
import {TeamTypes} from 'mattermost-redux/action_types';
import {ViewTypes} from 'app/constants';
function lastTeamId(state = '', action) {
switch (action.type) {
case TeamTypes.SELECT_TEAM:
return action.data;
default:
return state;
}
}
function lastChannelForTeam(state = {}, action) {
switch (action.type) {
case ViewTypes.SET_LAST_CHANNEL_FOR_TEAM: {
const team = state[action.teamId];
const channelIds = [];
if (!action.channelId) {
return state;
}
if (team) {
channelIds.push(...team);
const index = channelIds.indexOf(action.channelId);
if (index === -1) {
channelIds.unshift(action.channelId);
channelIds.slice(0, 5);
} else {
channelIds.splice(index, 1);
channelIds.unshift(action.channelId);
}
} else {
channelIds.push(action.channelId);
}
return {
...state,
[action.teamId]: channelIds
};
}
default:
return state;
}
}
export default combineReducers({
lastTeamId,
lastChannelForTeam
});