mattermost-mobile/service/selectors/entities/users.js
Chris Duarte ea3b2cabd4 Channel members fix (#209)
* Channel members fix

* Review feedback
2017-02-01 09:28:01 -05:00

72 lines
1.8 KiB
JavaScript

// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import {createSelector} from 'reselect';
import {getCurrentChannelId} from './channels';
import {getMyPreferences} from './preferences';
export function getCurrentUserId(state) {
return state.entities.users.currentId;
}
export function getProfilesInChannel(state) {
return state.entities.users.profilesInChannel;
}
export function getUserStatuses(state) {
return state.entities.users.statuses;
}
export function getUser(state, id) {
return state.entities.users.profiles[id];
}
export function getUsers(state) {
return state.entities.users.profiles;
}
export const getCurrentUser = createSelector(
getUsers,
getCurrentUserId,
(profiles, currentUserId) => {
return profiles[currentUserId];
}
);
export const getProfileSetInCurrentChannel = createSelector(
getCurrentChannelId,
getProfilesInChannel,
(currentChannel, channelProfiles) => {
return channelProfiles[currentChannel];
}
);
export const getProfilesInCurrentChannel = createSelector(
getUsers,
getUserStatuses,
getProfileSetInCurrentChannel,
getMyPreferences,
(profiles, statuses, currentChannelProfileSet) => {
const currentProfiles = [];
if (typeof currentChannelProfileSet === 'undefined') {
return currentProfiles;
}
currentChannelProfileSet.forEach((p) => {
currentProfiles.push({
...profiles[p],
status: statuses[p]
});
});
const sortedCurrentProfiles = currentProfiles.sort((a, b) => {
const nameA = a.username;
const nameB = b.username;
return nameA.localeCompare(nameB);
});
return sortedCurrentProfiles;
}
);