Files
welshman/packages/app/src/feeds.ts
T
2025-05-05 15:38:48 -07:00

44 lines
1.2 KiB
TypeScript

import {Scope, FeedController, FeedControllerOptions, Feed} from "@welshman/feeds"
import {pubkey, signer} from "./session.js"
import {wotGraph, maxWot, getFollows, getNetwork, getFollowers} from "./wot.js"
export const getPubkeysForScope = (scope: string) => {
const $pubkey = pubkey.get()
if (!$pubkey) {
return []
}
switch (scope) {
case Scope.Self:
return [$pubkey]
case Scope.Follows:
return getFollows($pubkey)
case Scope.Network:
return getNetwork($pubkey)
case Scope.Followers:
return getFollowers($pubkey)
default:
return []
}
}
export const getPubkeysForWOTRange = (min: number, max: number) => {
const pubkeys = []
const thresholdMin = maxWot.get() * min
const thresholdMax = maxWot.get() * max
for (const [tpk, score] of wotGraph.get().entries()) {
if (score >= thresholdMin && score <= thresholdMax) {
pubkeys.push(tpk)
}
}
return pubkeys
}
type MakeFeedControllerOptions = Partial<Omit<FeedControllerOptions, "feed">> & {feed: Feed}
export const makeFeedController = (options: MakeFeedControllerOptions) =>
new FeedController({getPubkeysForScope, getPubkeysForWOTRange, signer: signer.get(), ...options})