Browse Source

refactor: perfonNetworkBuilder.ts - foreach to map

master
limina1 8 months ago
parent
commit
7e0e24066f
  1. 43
      src/lib/navigator/EventNetwork/utils/personNetworkBuilder.ts

43
src/lib/navigator/EventNetwork/utils/personNetworkBuilder.ts

@ -225,31 +225,36 @@ export function createPersonLinks(
const nodeMap = new Map(nodes.map((n) => [n.id, n])); const nodeMap = new Map(nodes.map((n) => [n.id, n]));
const links: PersonLink = personAnchors.map((anchor) => { const links: PersonLink[] = personAnchors.flatMap((anchor) => {
if (!anchor.connectedNodes || !anchor.pubkey) return; if (!anchor.connectedNodes || !anchor.pubkey) {
return [];
}
const connection = personMap.get(anchor.pubkey); const connection = personMap.get(anchor.pubkey);
if (!connection) return; if (!connection) {
return [];
}
return ...anchor.connectedNodes.map((nodeId) => { return anchor.connectedNodes.map((nodeId) => {
const node = nodeMap.get(nodeId); const node = nodeMap.get(nodeId);
if (node) { if (!node) {
// Determine connection type return undefined;
let connectionType: "signed-by" | "referenced" | undefined; }
if (connection.signedByEventIds.has(nodeId)) {
connectionType = "signed-by";
} else if (connection.referencedInEventIds.has(nodeId)) {
connectionType = "referenced";
}
return { let connectionType: 'signed-by' | 'referenced' | undefined;
source: anchor, if (connection.signedByEventIds.has(nodeId)) {
target: node, connectionType = 'signed-by';
isSequential: false, } else if (connection.referencedInEventIds.has(nodeId)) {
connectionType, connectionType = 'referenced';
};
} }
});
return {
source: anchor,
target: node,
isSequential: false,
connectionType,
};
}).filter(Boolean); // Remove undefineds
}); });
debug("Created person links", { linkCount: links.length }); debug("Created person links", { linkCount: links.length });

Loading…
Cancel
Save