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 @@ -73,13 +73,15 @@ import type { DispatchActionPromise } from '../utils/action-utils'; import type { GetENSNames } from '../utils/ens-helpers'; import { + ET, entityTextToRawString, getEntityTextAsString, + type UserEntity, } from '../utils/entity-text'; import { values } from '../utils/objects'; import { useSelector } from '../utils/redux-utils'; import { firstLine } from '../utils/string-utils'; -import { pluralize, trimText } from '../utils/text-utils'; +import { trimText } from '../utils/text-utils'; import { type ParserRules } from './markdown'; import { getMessageTitle } from './message-utils'; import { relationshipBlockedInEitherDirection } from './relationship-utils'; @@ -772,28 +774,18 @@ return newPermissions; } -function robotextName( - threadInfo: RawThreadInfo | ThreadInfo, - viewerID: ?string, - userInfos: UserInfos, -): string { - const threadUsernames = threadOtherMembers(threadInfo.members, viewerID) - .map(member => userInfos[member.id] && userInfos[member.id].username) - .filter(Boolean); - if (threadUsernames.length === 0) { - return 'just you'; - } - return pluralize(threadUsernames); -} - function threadUIName( - threadInfo: RawThreadInfo | ThreadInfo, + threadInfo: ThreadInfo, viewerID: ?string, userInfos: UserInfos, -): string { - return firstLine( - threadInfo.name || robotextName(threadInfo, viewerID, userInfos), +): string | $ReadOnlyArray { + if (threadInfo.name) { + return firstLine(threadInfo.name); + } + const threadMembers = threadInfo.members.filter( + memberInfo => memberInfo.role, ); + return threadMembers.map(member => ET.user({ userInfo: member })); } function threadInfoFromRawThreadInfo( @@ -805,7 +797,7 @@ id: rawThreadInfo.id, type: rawThreadInfo.type, name: rawThreadInfo.name, - uiName: threadUIName(rawThreadInfo, viewerID, userInfos), + uiName: '', description: rawThreadInfo.description, color: rawThreadInfo.color, creationTime: rawThreadInfo.creationTime, @@ -817,6 +809,10 @@ currentUser: getCurrentUser(rawThreadInfo, viewerID, userInfos), repliesCount: rawThreadInfo.repliesCount, }; + threadInfo = { + ...threadInfo, + uiName: threadUIName(threadInfo, viewerID, userInfos), + }; const { sourceMessageID } = rawThreadInfo; if (sourceMessageID) { threadInfo = { ...threadInfo, sourceMessageID }; @@ -1494,7 +1490,6 @@ threadFrozenDueToViewerBlock, rawThreadInfoFromServerThreadInfo, filterThreadEditDetailedPermissions, - robotextName, threadUIName, threadInfoFromRawThreadInfo, rawThreadInfoFromThreadInfo, diff --git a/lib/types/thread-types.js b/lib/types/thread-types.js --- a/lib/types/thread-types.js +++ b/lib/types/thread-types.js @@ -11,6 +11,7 @@ import type { ThreadSubscription } from './subscription-types'; import type { ServerUpdateInfo, ClientUpdateInfo } from './update-types'; import type { UserInfo, UserInfos } from './user-types'; +import type { UserEntity } from '../utils/entity-text'; export const threadTypes = Object.freeze({ //OPEN: 0, (DEPRECATED) @@ -207,7 +208,7 @@ +id: string, +type: ThreadType, +name: ?string, - +uiName: string, + +uiName: string | $ReadOnlyArray, +description: ?string, +color: string, // hex, without "#" or "0x" +creationTime: number, // millisecond timestamp diff --git a/lib/utils/entity-text.js b/lib/utils/entity-text.js --- a/lib/utils/entity-text.js +++ b/lib/utils/entity-text.js @@ -15,7 +15,7 @@ import { basePluralize } from '../utils/text-utils'; import type { GetENSNames } from './ens-helpers'; -type UserEntity = { +export type UserEntity = { +type: 'user', +id: string, +username?: ?string,