diff --git a/lib/shared/thread-utils.js b/lib/shared/thread-utils.js --- a/lib/shared/thread-utils.js +++ b/lib/shared/thread-utils.js @@ -6,6 +6,7 @@ import _omitBy from 'lodash/fp/omitBy.js'; import * as React from 'react'; +import { getUserAvatarForThread } from './avatar-utils.js'; import { generatePendingThreadColor } from './color-utils.js'; import { type ParserRules } from './markdown.js'; import { extractUserMentionsFromText } from './mention-utils.js'; @@ -48,9 +49,9 @@ } from '../selectors/thread-selectors.js'; import { getLegacyRelativeMemberInfos, + getMinimallyEncodedRelativeMemberInfos, usersWithPersonalThreadSelector, } from '../selectors/user-selectors.js'; -import { getUserAvatarForThread } from '../shared/avatar-utils.js'; import type { CalendarQuery } from '../types/entry-types.js'; import { messageTypes } from '../types/message-types-enum.js'; import { @@ -890,26 +891,58 @@ } function threadInfoFromRawThreadInfo( - rawThreadInfo: LegacyRawThreadInfo, + rawThreadInfo: RawThreadInfo, viewerID: ?string, userInfos: UserInfos, ): MinimallyEncodedThreadInfo { - let threadInfo: LegacyThreadInfo = { - id: rawThreadInfo.id, - type: rawThreadInfo.type, - name: rawThreadInfo.name, - uiName: '', - description: rawThreadInfo.description, - color: rawThreadInfo.color, - creationTime: rawThreadInfo.creationTime, - parentThreadID: rawThreadInfo.parentThreadID, - containingThreadID: rawThreadInfo.containingThreadID, - community: rawThreadInfo.community, - members: getLegacyRelativeMemberInfos(rawThreadInfo, viewerID, userInfos), - roles: rawThreadInfo.roles, - currentUser: getCurrentUser(rawThreadInfo, viewerID, userInfos), - repliesCount: rawThreadInfo.repliesCount, - }; + let threadInfo: ThreadInfo; + // TODO (atul): Try to get rid of this ridiculous branching. + if (rawThreadInfo.minimallyEncoded) { + threadInfo = { + minimallyEncoded: true, + id: rawThreadInfo.id, + type: rawThreadInfo.type, + name: rawThreadInfo.name, + uiName: '', + description: rawThreadInfo.description, + color: rawThreadInfo.color, + creationTime: rawThreadInfo.creationTime, + parentThreadID: rawThreadInfo.parentThreadID, + containingThreadID: rawThreadInfo.containingThreadID, + community: rawThreadInfo.community, + members: getMinimallyEncodedRelativeMemberInfos( + rawThreadInfo, + viewerID, + userInfos, + ), + roles: rawThreadInfo.roles, + currentUser: getMinimallyEncodedCurrentUser( + rawThreadInfo, + viewerID, + userInfos, + ), + repliesCount: rawThreadInfo.repliesCount, + }; + } else { + threadInfo = { + id: rawThreadInfo.id, + type: rawThreadInfo.type, + name: rawThreadInfo.name, + uiName: '', + description: rawThreadInfo.description, + color: rawThreadInfo.color, + creationTime: rawThreadInfo.creationTime, + parentThreadID: rawThreadInfo.parentThreadID, + containingThreadID: rawThreadInfo.containingThreadID, + community: rawThreadInfo.community, + members: getLegacyRelativeMemberInfos(rawThreadInfo, viewerID, userInfos), + roles: rawThreadInfo.roles, + currentUser: getCurrentUser(rawThreadInfo, viewerID, userInfos), + repliesCount: rawThreadInfo.repliesCount, + }; + threadInfo = minimallyEncodeThreadInfo(threadInfo); + } + threadInfo = { ...threadInfo, uiName: threadUIName(threadInfo), @@ -934,7 +967,7 @@ if (pinnedCount) { threadInfo = { ...threadInfo, pinnedCount }; } - return minimallyEncodeThreadInfo(threadInfo); + return threadInfo; } function getCurrentUser(