( entity: ThreadEntity, params?: ?EntityTextToRawStringParams, )
| 281 | } |
| 282 | |
| 283 | function getNameForThreadEntity( |
| 284 | entity: ThreadEntity, |
| 285 | params?: ?EntityTextToRawStringParams, |
| 286 | ): string { |
| 287 | const { name: userGeneratedName, display } = entity; |
| 288 | if (entity.display === 'uiName') { |
| 289 | if (userGeneratedName) { |
| 290 | return userGeneratedName; |
| 291 | } |
| 292 | const { uiName } = entity; |
| 293 | if (typeof uiName === 'string') { |
| 294 | return uiName; |
| 295 | } |
| 296 | |
| 297 | let userEntities = uiName; |
| 298 | if (!params?.ignoreViewer) { |
| 299 | const viewerFilteredUserEntities = userEntities.filter( |
| 300 | innerEntity => !innerEntity.isViewer, |
| 301 | ); |
| 302 | if (viewerFilteredUserEntities.length > 0) { |
| 303 | userEntities = viewerFilteredUserEntities; |
| 304 | } else if (entity.ifJustViewer === 'viewer_username') { |
| 305 | // We pass ignoreViewer to entityTextToRawString in order |
| 306 | // to prevent it from rendering the viewer as "you" |
| 307 | params = { ...params, ignoreViewer: true }; |
| 308 | } else { |
| 309 | return 'just you'; |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | const pluralized = pluralizeEntityText( |
| 314 | userEntities.map(innerEntity => [innerEntity]), |
| 315 | ); |
| 316 | return entityTextToRawString(pluralized, params); |
| 317 | } |
| 318 | |
| 319 | invariant( |
| 320 | entity.display === 'shortName', |
| 321 | `getNameForThreadEntity can't handle thread entity display ${display}`, |
| 322 | ); |
| 323 | |
| 324 | let { name } = entity; |
| 325 | if (!name || entity.alwaysDisplayShortName) { |
| 326 | const threadType = entity.threadType ?? threadTypes.PERSONAL; |
| 327 | const { parentThreadID } = entity; |
| 328 | const noun = entity.subchannel |
| 329 | ? 'subchannel' |
| 330 | : threadNoun(threadType, parentThreadID); |
| 331 | if (entity.id === params?.threadID) { |
| 332 | const prefixThisThreadNounWith = |
| 333 | params?.prefixThisThreadNounWith === 'your' ? 'your' : 'this'; |
| 334 | name = `${prefixThisThreadNounWith} ${noun}`; |
| 335 | } else { |
| 336 | name = `a ${noun}`; |
| 337 | } |
| 338 | } |
| 339 | if (entity.possessive) { |
| 340 | name = makePossessive({ str: name }); |
no test coverage detected