MCPcopy Create free account
hub / github.com/ChatLab/ChatLab / buildContactItems

Function buildContactItems

packages/node-runtime/src/services/contacts/compute.ts:445–479  ·  view source on GitHub ↗
(accumulators: ContactAccumulator[])

Source from the content-addressed store, hash-verified

443}
444
445function buildContactItems(accumulators: ContactAccumulator[]): ContactItem[] {
446 const friendInputs = accumulators
447 .filter((acc) => acc.isFriend)
448 .map((acc) => ({
449 acc,
450 privateMessageCount: acc.privateMessageCount,
451 activeMonths: [...acc.activePrivateMonths],
452 commonGroupCount: acc.commonGroupSessionIds.size,
453 }))
454 const nonFriendInputs = accumulators
455 .filter((acc) => !acc.isFriend)
456 .map((acc) => ({
457 acc,
458 coOccurrenceRawScore: acc.coOccurrenceRawScore,
459 commonGroupCount: acc.commonGroupSessionIds.size,
460 replyInteractionCount: acc.replyInteractionCount,
461 coOccurrenceCount: acc.coOccurrenceCount,
462 }))
463
464 const friendScores = computeFriendScores(friendInputs)
465 const nonFriendScores = computeNonFriendScores(nonFriendInputs)
466 const contacts: ContactItem[] = []
467
468 for (const input of friendInputs) {
469 const score = friendScores.get(input) ?? { score: 0, scoreBreakdown: {} }
470 contacts.push(toContactItem(input.acc, 'friend', score))
471 }
472
473 for (const input of nonFriendInputs) {
474 const score = nonFriendScores.get(input) ?? { score: 0, scoreBreakdown: {} }
475 contacts.push(toContactItem(input.acc, 'non_friend', score))
476 }
477
478 return contacts.sort((a, b) => b.score - a.score || a.displayName.localeCompare(b.displayName))
479}
480
481function toContactItem(
482 acc: ContactAccumulator,

Callers 1

computeContactsFunction · 0.85

Calls 4

computeFriendScoresFunction · 0.90
computeNonFriendScoresFunction · 0.90
toContactItemFunction · 0.85
getMethod · 0.65

Tested by

no test coverage detected