* Channel list drawer * Get channels by category * Fix and connect websocket * Fix Select first team using the team members * create loadMe and fix login actions to loads the teams * Add android back button handler for the channel drawer * Channel drawer styling and functionality * Mark channel as viewed and fixed reset unread counts * Unread above/below indicators * Improve performance replacing ScrollView with ListView * Fix unread indicators * Addressing review feedback
135 lines
3.5 KiB
JavaScript
135 lines
3.5 KiB
JavaScript
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
|
|
// See License.txt for license information.
|
|
|
|
import {ChannelTypes, UsersTypes} from 'service/constants';
|
|
import {combineReducers} from 'redux';
|
|
|
|
function currentId(state = '', action) {
|
|
switch (action.type) {
|
|
case ChannelTypes.SELECT_CHANNEL:
|
|
return action.data;
|
|
case UsersTypes.LOGOUT_SUCCESS:
|
|
return '';
|
|
default:
|
|
return state;
|
|
}
|
|
}
|
|
|
|
function channels(state = {}, action) {
|
|
const nextState = {...state};
|
|
|
|
switch (action.type) {
|
|
case ChannelTypes.RECEIVED_CHANNEL:
|
|
return {
|
|
...state,
|
|
[action.data.id]: action.data
|
|
};
|
|
|
|
case ChannelTypes.RECEIVED_CHANNELS:
|
|
case ChannelTypes.RECEIVED_MORE_CHANNELS: {
|
|
for (const channel of action.data) {
|
|
nextState[channel.id] = channel;
|
|
}
|
|
return nextState;
|
|
}
|
|
case ChannelTypes.RECEIVED_CHANNEL_DELETED:
|
|
Reflect.deleteProperty(nextState, action.data);
|
|
return nextState;
|
|
case ChannelTypes.RECEIVED_LAST_VIEWED: {
|
|
const channelId = action.data.channel_id;
|
|
const lastUpdatedAt = action.data.last_viewed_at;
|
|
return {
|
|
...state,
|
|
[channelId]: {
|
|
...state[channelId],
|
|
extra_update_at: lastUpdatedAt
|
|
}
|
|
};
|
|
}
|
|
case UsersTypes.LOGOUT_SUCCESS:
|
|
return {};
|
|
|
|
default:
|
|
return state;
|
|
}
|
|
}
|
|
|
|
function myMembers(state = {}, action) {
|
|
const nextState = {...state};
|
|
|
|
switch (action.type) {
|
|
case ChannelTypes.RECEIVED_MY_CHANNEL_MEMBER: {
|
|
const channelMember = action.data;
|
|
return {
|
|
...state,
|
|
[channelMember.channel_id]: channelMember
|
|
};
|
|
}
|
|
case ChannelTypes.RECEIVED_MY_CHANNEL_MEMBERS: {
|
|
for (const cm of action.data) {
|
|
nextState[cm.channel_id] = cm;
|
|
}
|
|
return nextState;
|
|
}
|
|
case ChannelTypes.RECEIVED_CHANNEL_PROPS: {
|
|
const member = {...state[action.data.channel_id]};
|
|
member.notify_props = action.data.notifyProps;
|
|
|
|
return {
|
|
...state,
|
|
[action.data.channel_id]: member
|
|
};
|
|
}
|
|
case ChannelTypes.RECEIVED_LAST_VIEWED: {
|
|
const member = {...state[action.data.channel_id]};
|
|
member.last_viewed_at = action.data.last_viewed_at;
|
|
member.msg_count = action.data.total_msg_count;
|
|
member.mention_count = 0;
|
|
|
|
return {
|
|
...state,
|
|
[action.data.channel_id]: member
|
|
};
|
|
}
|
|
case ChannelTypes.LEAVE_CHANNEL:
|
|
case ChannelTypes.RECEIVED_CHANNEL_DELETED:
|
|
Reflect.deleteProperty(nextState, action.data);
|
|
return nextState;
|
|
|
|
case UsersTypes.LOGOUT_SUCCESS:
|
|
return {};
|
|
default:
|
|
return state;
|
|
}
|
|
}
|
|
|
|
function stats(state = {}, action) {
|
|
switch (action.type) {
|
|
case ChannelTypes.RECEIVED_CHANNEL_STATS: {
|
|
const nextState = {...state};
|
|
const stat = action.data;
|
|
nextState[stat.channel_id] = stat;
|
|
|
|
return nextState;
|
|
}
|
|
case UsersTypes.LOGOUT_SUCCESS:
|
|
return {};
|
|
default:
|
|
return state;
|
|
}
|
|
}
|
|
|
|
export default combineReducers({
|
|
|
|
// the current selected channel
|
|
currentId,
|
|
|
|
// object where every key is the channel id and has and object with the channel detail
|
|
channels,
|
|
|
|
//object where every key is the channel id and has and object with the channel members detail
|
|
myMembers,
|
|
|
|
// object where every key is the team id and has an object with the team stats
|
|
stats
|
|
});
|