Add quote method to router
This commit is contained in:
+34
-13
@@ -144,15 +144,6 @@ export class Router {
|
|||||||
FromRelays = (relays: string[]) =>
|
FromRelays = (relays: string[]) =>
|
||||||
this.scenario([makeSelection(relays)])
|
this.scenario([makeSelection(relays)])
|
||||||
|
|
||||||
ForPubkey = (pubkey: string) =>
|
|
||||||
this.FromRelays(this.getRelaysForPubkey(pubkey, RelayMode.Read))
|
|
||||||
|
|
||||||
FromPubkey = (pubkey: string) =>
|
|
||||||
this.FromRelays(this.getRelaysForPubkey(pubkey, RelayMode.Write))
|
|
||||||
|
|
||||||
PubkeyInbox = (pubkey: string) =>
|
|
||||||
this.FromRelays(this.getRelaysForPubkey(pubkey, RelayMode.Inbox)).policy(addNoFallbacks)
|
|
||||||
|
|
||||||
ForUser = () =>
|
ForUser = () =>
|
||||||
this.FromRelays(this.getRelaysForUser(RelayMode.Read))
|
this.FromRelays(this.getRelaysForUser(RelayMode.Read))
|
||||||
|
|
||||||
@@ -162,6 +153,15 @@ export class Router {
|
|||||||
UserInbox = () =>
|
UserInbox = () =>
|
||||||
this.FromRelays(this.getRelaysForUser(RelayMode.Inbox)).policy(addNoFallbacks)
|
this.FromRelays(this.getRelaysForUser(RelayMode.Inbox)).policy(addNoFallbacks)
|
||||||
|
|
||||||
|
ForPubkey = (pubkey: string) =>
|
||||||
|
this.FromRelays(this.getRelaysForPubkey(pubkey, RelayMode.Read))
|
||||||
|
|
||||||
|
FromPubkey = (pubkey: string) =>
|
||||||
|
this.FromRelays(this.getRelaysForPubkey(pubkey, RelayMode.Write))
|
||||||
|
|
||||||
|
PubkeyInbox = (pubkey: string) =>
|
||||||
|
this.FromRelays(this.getRelaysForPubkey(pubkey, RelayMode.Inbox)).policy(addNoFallbacks)
|
||||||
|
|
||||||
ForPubkeys = (pubkeys: string[]) =>
|
ForPubkeys = (pubkeys: string[]) =>
|
||||||
this.merge(pubkeys.map(pubkey => this.ForPubkey(pubkey)))
|
this.merge(pubkeys.map(pubkey => this.ForPubkey(pubkey)))
|
||||||
|
|
||||||
@@ -174,9 +174,24 @@ export class Router {
|
|||||||
Event = (event: TrustedEvent) =>
|
Event = (event: TrustedEvent) =>
|
||||||
this.FromRelays(this.getRelaysForPubkey(event.pubkey, RelayMode.Write))
|
this.FromRelays(this.getRelaysForPubkey(event.pubkey, RelayMode.Write))
|
||||||
|
|
||||||
EventChildren = (event: TrustedEvent) =>
|
Replies = (event: TrustedEvent) =>
|
||||||
this.FromRelays(this.getRelaysForPubkey(event.pubkey, RelayMode.Read))
|
this.FromRelays(this.getRelaysForPubkey(event.pubkey, RelayMode.Read))
|
||||||
|
|
||||||
|
Quote = (event: TrustedEvent, value: string, relays = []) => {
|
||||||
|
const tag = event.tags.find(t => t[1] === value)
|
||||||
|
const scenarios: RouterScenario[] = []
|
||||||
|
|
||||||
|
if (tag?.[2] && isShareableRelayUrl(tag[2])) {
|
||||||
|
scenarios.push(this.FromRelays([tag[2]]))
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tag?.[3]?.length === 64) {
|
||||||
|
scenarios.push(this.FromPubkeys([tag[3]]))
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.merge(scenarios)
|
||||||
|
}
|
||||||
|
|
||||||
EventAncestors = (event: TrustedEvent, type: "mentions" | "replies" | "roots") => {
|
EventAncestors = (event: TrustedEvent, type: "mentions" | "replies" | "roots") => {
|
||||||
return this.scenario(
|
return this.scenario(
|
||||||
getAncestorTags(event.tags)[type].flatMap(
|
getAncestorTags(event.tags)[type].flatMap(
|
||||||
@@ -444,7 +459,10 @@ export const defaultFilterSelectionRules = [
|
|||||||
getFilterSelectionsForUser,
|
getFilterSelectionsForUser,
|
||||||
]
|
]
|
||||||
|
|
||||||
export function* getFilterSelections(filters: Filter[], rules: FilterSelectionRule[] = defaultFilterSelectionRules) {
|
export const getFilterSelections = (
|
||||||
|
filters: Filter[],
|
||||||
|
rules: FilterSelectionRule[] = defaultFilterSelectionRules
|
||||||
|
): RelaysAndFilters[] => {
|
||||||
const filtersById = new Map<string, Filter>()
|
const filtersById = new Map<string, Filter>()
|
||||||
const scenariosById = new Map<string, RouterScenario[]>()
|
const scenariosById = new Map<string, RouterScenario[]>()
|
||||||
|
|
||||||
@@ -457,10 +475,13 @@ export function* getFilterSelections(filters: Filter[], rules: FilterSelectionRu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const result = []
|
||||||
|
|
||||||
for (const [id, filter] of filtersById.entries()) {
|
for (const [id, filter] of filtersById.entries()) {
|
||||||
const scenario = ctx.app.router.merge(scenariosById.get(id) || [])
|
const scenario = ctx.app.router.merge(scenariosById.get(id) || [])
|
||||||
const result = {filters: [filter], relays: scenario.getUrls()} as RelaysAndFilters
|
|
||||||
|
|
||||||
yield result
|
result.push({filters: [filter], relays: scenario.getUrls()})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user