From 2ab7e63e555bd60e18490d4441749721b8945626 Mon Sep 17 00:00:00 2001 From: Martti Malmi Date: Sat, 3 Feb 2024 14:55:18 +0200 Subject: [PATCH] common like counts in scoring --- packages/app/src/Db/getForYouFeed.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/app/src/Db/getForYouFeed.ts b/packages/app/src/Db/getForYouFeed.ts index 0b90b77a..489202a6 100644 --- a/packages/app/src/Db/getForYouFeed.ts +++ b/packages/app/src/Db/getForYouFeed.ts @@ -49,7 +49,7 @@ async function getMyReactedEventIds(pubkey: string) { } async function getOthersWhoReacted(myReactedEventIds: Set, myPubkey: string) { - const othersWhoReacted = new Set(); + const othersWhoReacted = new Map(); const otherReactions = await Relay.query([ "REQ", @@ -61,21 +61,21 @@ async function getOthersWhoReacted(myReactedEventIds: Set, myPubkey: str otherReactions.forEach(reaction => { if (reaction.pubkey !== myPubkey) { - othersWhoReacted.add(reaction.pubkey); + othersWhoReacted.set(reaction.pubkey, (othersWhoReacted.get(reaction.pubkey) || 0) + 1); } }); - return [...othersWhoReacted]; + return othersWhoReacted; } -async function getEventIdsReactedByOthers(othersWhoReacted: string[], myReactedEvents: Set, myPub: string) { +async function getEventIdsReactedByOthers(othersWhoReacted: Map, myReactedEvents: Set, myPub: string) { const eventIdsReactedByOthers = new Map(); const events = await Relay.query([ "REQ", "getEventIdsReactedByOthers", { - authors: othersWhoReacted, + authors: [...othersWhoReacted.keys()], kinds: [1, 6, 7, 9735], }, ]); @@ -87,7 +87,8 @@ async function getEventIdsReactedByOthers(othersWhoReacted: string[], myReactedE } event.tags.forEach(tag => { if (tag[0] === "e") { - eventIdsReactedByOthers.set(tag[1], (eventIdsReactedByOthers.get(tag[1]) || 0) + 1); + const score = Math.ceil(Math.sqrt(othersWhoReacted.get(event.pubkey) || 0)); + eventIdsReactedByOthers.set(tag[1], (eventIdsReactedByOthers.get(tag[1]) || 0) + score); } }); });