MCPcopy Create free account
hub / github.com/CommE2E/comm / getNameForThreadEntity

Function getNameForThreadEntity

lib/utils/entity-text.js:283–343  ·  view source on GitHub ↗
(
  entity: ThreadEntity,
  params?: ?EntityTextToRawStringParams,
)

Source from the content-addressed store, hash-verified

281}
282
283function 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 });

Callers 3

entityTextToRawStringFunction · 0.85
entityTextToReactFunction · 0.85

Calls 4

threadNounFunction · 0.90
pluralizeEntityTextFunction · 0.85
entityTextToRawStringFunction · 0.85
makePossessiveFunction · 0.85

Tested by

no test coverage detected