( objects: $ReadOnlyArray<EntityTextComponentAsObject>, )
| 521 | return objs; |
| 522 | } |
| 523 | function 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 | |
| 580 | export type UseResolvedEntityTextOptions = { |
no test coverage detected