diff --git a/lib/shared/notif-utils.js b/lib/shared/notif-utils.js --- a/lib/shared/notif-utils.js +++ b/lib/shared/notif-utils.js @@ -20,9 +20,8 @@ import { ET, getEntityTextAsString, - pluralizeEntityText, type EntityText, - type UserEntity, + type ThreadEntity, } from '../utils/entity-text.js'; import { promiseAll } from '../utils/promises.js'; import { trimText } from '../utils/text-utils.js'; @@ -98,7 +97,7 @@ +threadType: ThreadType, +parentThreadInfo: ThreadInfo, +childThreadName: ?string, - +childThreadUIName: string | $ReadOnlyArray, + +childThreadUIName: string | ThreadEntity, }; function notifTextsForSubthreadCreation( input: NotifTextsForSubthreadCreationInput, @@ -181,15 +180,10 @@ ); return notifString; }; - const unresolvedTitle = unresolvedNotifTexts.title; - const pluralizedTitle = - typeof unresolvedTitle === 'string' - ? unresolvedTitle - : pluralizeEntityText(unresolvedTitle.map(entity => [entity])); let promises = { merged: resolveToString(unresolvedNotifTexts.merged), body: resolveToString(unresolvedNotifTexts.body), - title: resolveToString(pluralizedTitle), + title: resolveToString(ET`${unresolvedNotifTexts.title}`), }; if (unresolvedNotifTexts.prefix) { promises = { 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 @@ -83,7 +83,7 @@ ET, entityTextToRawString, getEntityTextAsString, - type UserEntity, + type ThreadEntity, } from '../utils/entity-text.js'; import { values } from '../utils/objects.js'; import { useSelector } from '../utils/redux-utils.js'; @@ -777,16 +777,23 @@ return newPermissions; } -function threadUIName( - threadInfo: ThreadInfo, -): string | $ReadOnlyArray { +function threadUIName(threadInfo: ThreadInfo): string | ThreadEntity { if (threadInfo.name) { return firstLine(threadInfo.name); } const threadMembers = threadInfo.members.filter( memberInfo => memberInfo.role, ); - return threadMembers.map(member => ET.user({ userInfo: member })); + const memberEntities = threadMembers.map(member => + ET.user({ userInfo: member }), + ); + return { + type: 'thread', + id: threadInfo.id, + name: threadInfo.name, + display: 'uiName', + uiName: memberEntities, + }; } function threadInfoFromRawThreadInfo( diff --git a/lib/types/notif-types.js b/lib/types/notif-types.js --- a/lib/types/notif-types.js +++ b/lib/types/notif-types.js @@ -1,11 +1,11 @@ // @flow -import type { EntityText, UserEntity } from '../utils/entity-text.js'; +import type { EntityText, ThreadEntity } from '../utils/entity-text.js'; export type NotifTexts = { +merged: string | EntityText, +body: string | EntityText, - +title: string | $ReadOnlyArray, + +title: string | ThreadEntity, +prefix?: string | EntityText, }; 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,7 +11,7 @@ import type { ThreadSubscription } from './subscription-types.js'; import type { ServerUpdateInfo, ClientUpdateInfo } from './update-types.js'; import type { UserInfo, UserInfos } from './user-types.js'; -import type { UserEntity } from '../utils/entity-text.js'; +import type { ThreadEntity } from '../utils/entity-text.js'; export const threadTypes = Object.freeze({ //OPEN: 0, (DEPRECATED) @@ -208,7 +208,7 @@ +id: string, +type: ThreadType, +name: ?string, - +uiName: string | $ReadOnlyArray, + +uiName: string | ThreadEntity, +description: ?string, +color: string, // hex, without "#" or "0x" +creationTime: number, // millisecond timestamp diff --git a/lib/utils/entity-helpers.js b/lib/utils/entity-helpers.js --- a/lib/utils/entity-helpers.js +++ b/lib/utils/entity-helpers.js @@ -15,10 +15,7 @@ threadInfos: $ReadOnlyArray, ): $ReadOnlyArray { const entityText = React.useMemo( - () => - threadInfos.map(threadInfo => - ET.thread({ display: 'uiName', threadInfo }), - ), + () => threadInfos.map(threadInfo => threadInfo.uiName), [threadInfos], ); const withENSNames = useENSNamesForEntityText(entityText); 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 @@ } from '../types/thread-types.js'; import { basePluralize } from '../utils/text-utils.js'; -export type UserEntity = { +type UserEntity = { +type: 'user', +id: string, +username?: ?string, @@ -24,7 +24,7 @@ }; // Comments explain how thread name will appear from user4's perspective -type ThreadEntity = +export type ThreadEntity = | { +type: 'thread', +id: string, @@ -119,6 +119,9 @@ entityTextFunction.thread = (input: EntityTextThreadInput) => { if (input.display === 'uiName') { const { threadInfo } = input; + if (typeof threadInfo.uiName !== 'string') { + return threadInfo.uiName; + } return { type: 'thread', id: threadInfo.id,