diff --git a/lib/selectors/user-selectors.js b/lib/selectors/user-selectors.js --- a/lib/selectors/user-selectors.js +++ b/lib/selectors/user-selectors.js @@ -3,11 +3,16 @@ import _memoize from 'lodash/memoize.js'; import { createSelector } from 'reselect'; +import { + getAvatarForUser, + getRandomDefaultEmojiAvatar, +} from '../shared/avatar-utils.js'; import SearchIndex from '../shared/search-index.js'; import { getSingleOtherUser, memberHasAdminPowers, } from '../shared/thread-utils.js'; +import type { ClientEmojiAvatar } from '../types/avatar-types'; import type { BaseAppState } from '../types/redux-types.js'; import { userRelationshipStatus } from '../types/relationship-types.js'; import { @@ -19,6 +24,7 @@ UserInfos, RelativeUserInfo, AccountUserInfo, + CurrentUserInfo, } from '../types/user-types.js'; // Used for specific message payloads that include an array of user IDs, ie. @@ -205,6 +211,19 @@ }, ); +const savedEmojiAvatarSelectorForCurrentUser: ( + state: BaseAppState<*>, +) => ClientEmojiAvatar = createSelector( + (state: BaseAppState<*>) => state.currentUserInfo && state.currentUserInfo, + (currentUser: ?CurrentUserInfo) => { + let userAvatar = getAvatarForUser(currentUser); + if (userAvatar.type !== 'emoji') { + userAvatar = getRandomDefaultEmojiAvatar(); + } + return userAvatar; + }, +); + export { userIDsToRelativeUserInfos, getRelativeMemberInfos, @@ -214,4 +233,5 @@ isLoggedIn, userStoreSearchIndex, usersWithPersonalThreadSelector, + savedEmojiAvatarSelectorForCurrentUser, };