mattermost-mobile/app/mm-redux/selectors/entities/typing.ts
Miguel Alatzar 2d81b497cf [MM-23520] Port mattermost-redux (#4088)
* Remove mattermost-redux

* Move mm-redux files into app/redux

* Add @redux path to tsconfig.json

* Fix imports

* Install missing dependencies

* Fix tsc errors

* Fix i18n_utils test

* Fix more imports

* Remove redux websocket

* Fix tests

* Rename @redux

* Apply changes from mattermost-redux PR 1103

* Remove mattermost-redux mention in template

* Add missing imports

* Rename app/redux/ to app/mm-redux/

* Remove test file

* Fix fetching Sidebar GM profiles

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
2020-04-17 21:12:09 -07:00

48 lines
1.9 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {createSelector} from 'reselect';
import {getCurrentChannelId, getUsers} from '@mm-redux/selectors/entities/common';
import {getTeammateNameDisplaySetting} from '@mm-redux/selectors/entities/preferences';
import {displayUsername} from '@mm-redux/utils/user_utils';
import {Typing} from '@mm-redux/types/typing';
import {UserProfile} from '@mm-redux/types/users';
import {GlobalState} from '@mm-redux/types/store';
import {IDMappedObjects} from '@mm-redux/types/utilities';
const getUsersTypingImpl = (profiles: IDMappedObjects<UserProfile>, teammateNameDisplay: string, channelId: string, parentPostId: string, typing: Typing): Array<string> => {
const id = channelId + parentPostId;
if (typing[id]) {
const users = Object.keys(typing[id]);
if (users.length) {
return users.map((userId) => {
return displayUsername(profiles[userId], teammateNameDisplay);
});
}
}
return [];
};
export const makeGetUsersTypingByChannelAndPost = () => {
return (createSelector(getUsers, getTeammateNameDisplaySetting, (state: GlobalState, options: {
channelId: string;
postId: string;
}): string => options.channelId, (state: GlobalState, options: {
channelId: string;
postId: string;
}): string => options.postId, (state: GlobalState): Typing => state.entities.typing, getUsersTypingImpl) as (state: GlobalState, a: {
channelId: string;
postId: string;
}) => Array<string>);
};
export const getUsersTyping: (state: GlobalState) => Array<string> = createSelector(
getUsers,
getTeammateNameDisplaySetting,
getCurrentChannelId,
(state) => state.entities.posts.selectedPostId,
(state) => state.entities.typing,
getUsersTypingImpl,
);