(accumulators: ContactAccumulator[])
| 443 | } |
| 444 | |
| 445 | function 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 | |
| 481 | function toContactItem( |
| 482 | acc: ContactAccumulator, |
no test coverage detected