mattermost-mobile/service/selectors/entities/users.js
Harrison Healey c28d64c8da #96/#112/PLT-5370/PLT-5372 Styling posts and channel view (#213)
* Updated post rendering in center channel to include dates, display names, themeing, profile pictures, and threads

* Added status to ProfilePicture component

* Changed MemberListRow to use a ProfilePicture

* Removed unused prop

* Fixed incorrect copyright year on new file

* Removed unnecessary ref
2017-02-02 13:53:42 -03:00

70 lines
1.7 KiB
JavaScript

// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import {createSelector} from 'reselect';
import {getCurrentChannelId} from './channels';
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,
getProfileSetInCurrentChannel,
(profiles, currentChannelProfileSet) => {
const currentProfiles = [];
if (typeof currentChannelProfileSet === 'undefined') {
return currentProfiles;
}
currentChannelProfileSet.forEach((p) => {
currentProfiles.push(profiles[p]);
});
const sortedCurrentProfiles = currentProfiles.sort((a, b) => {
const nameA = a.username;
const nameB = b.username;
return nameA.localeCompare(nameB);
});
return sortedCurrentProfiles;
}
);
export function getStatusForUserId(state, userId) {
return getUserStatuses(state)[userId];
}