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 @@ -870,6 +870,10 @@ name: threadInfo.name, display: 'uiName', uiName: memberEntities, + ifJustViewer: + threadInfo.type === threadTypes.PRIVATE + ? 'viewer_username' + : 'just_you_string', }; } 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 @@ -34,6 +34,10 @@ // If uiName is EntityText, then at render time ThreadEntity will be // replaced with a pluralized list of uiName's UserEntities +uiName: $ReadOnlyArray | string, + // If name isn't set and uiName is an array with only the viewer, then + // just_you_string displays "just you" but viewer_username displays the + // viewer's ENS-resolved username. Defaults to just_you_string + +ifJustViewer?: 'just_you_string' | 'viewer_username', } | { +type: 'thread', @@ -233,18 +237,29 @@ if (typeof uiName === 'string') { return uiName; } + let userEntities = uiName; if (!params?.ignoreViewer) { - userEntities = userEntities.filter(innerEntity => !innerEntity.isViewer); - } - if (userEntities.length === 0) { - return 'just you'; + const viewerFilteredUserEntities = userEntities.filter( + innerEntity => !innerEntity.isViewer, + ); + if (viewerFilteredUserEntities.length > 0) { + userEntities = viewerFilteredUserEntities; + } else if (entity.ifJustViewer === 'viewer_username') { + // We pass ignoreViewer to entityTextToRawString in order + // to prevent it from rendering the viewer as "you" + params = { ...params, ignoreViewer: true }; + } else { + return 'just you'; + } } + const pluralized = pluralizeEntityText( userEntities.map(innerEntity => [innerEntity]), ); return entityTextToRawString(pluralized, params); } + invariant( entity.display === 'shortName', `getNameForThreadEntity can't handle thread entity display ${display}`,