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

Function entityTextFromObjects

lib/utils/entity-text.js:523–578  ·  view source on GitHub ↗
(
  objects: $ReadOnlyArray<EntityTextComponentAsObject>,
)

Source from the content-addressed store, hash-verified

521 return objs;
522}
523function entityTextFromObjects(
524 objects: $ReadOnlyArray<EntityTextComponentAsObject>,
525): EntityText {
526 const shadowUserMap = new Map<string, string>();
527 for (const obj of objects) {
528 if (obj.type === 'shadowUser' && obj.username !== obj.originalUsername) {
529 shadowUserMap.set(obj.originalUsername, obj.username);
530 }
531 }
532 return objects
533 .map(entity => {
534 if (entity.type === 'text') {
535 return entity.text;
536 } else if (entity.type === 'shadowUser') {
537 return null;
538 } else if (
539 entity.type === 'thread' &&
540 entity.display === 'uiName' &&
541 typeof entity.uiName !== 'string'
542 ) {
543 const uiName: UserEntity[] = [];
544 let changeOccurred = false;
545 for (const innerEntity of entity.uiName) {
546 if (typeof innerEntity === 'string' || innerEntity.type !== 'user') {
547 uiName.push(innerEntity);
548 continue;
549 }
550 const { username } = innerEntity;
551 if (!username) {
552 uiName.push(innerEntity);
553 continue;
554 }
555 const ensName = shadowUserMap.get(username);
556 if (!ensName) {
557 uiName.push(innerEntity);
558 continue;
559 }
560 changeOccurred = true;
561 uiName.push({
562 ...innerEntity,
563 username: ensName,
564 });
565 }
566 if (!changeOccurred) {
567 return entity;
568 }
569 return {
570 ...entity,
571 uiName,
572 };
573 } else {
574 return entity;
575 }
576 })
577 .filter(Boolean);
578}
579
580export type UseResolvedEntityTextOptions = {

Callers 2

useResolvedEntityTextFunction · 0.85
getEntityTextAsStringFunction · 0.85

Calls 3

pushMethod · 0.80
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected