Add inbox relays scenario
This commit is contained in:
@@ -4,13 +4,13 @@ import {
|
|||||||
} from '@welshman/lib'
|
} from '@welshman/lib'
|
||||||
import {
|
import {
|
||||||
Tags, getFilterId, unionFilters, isShareableRelayUrl, isCommunityAddress, isGroupAddress, isContextAddress,
|
Tags, getFilterId, unionFilters, isShareableRelayUrl, isCommunityAddress, isGroupAddress, isContextAddress,
|
||||||
PROFILE, RELAYS, INBOX_RELAYS, FOLLOWS, LOCAL_RELAY_URL,
|
PROFILE, RELAYS, INBOX_RELAYS, FOLLOWS, LOCAL_RELAY_URL, WRAP,
|
||||||
} from '@welshman/util'
|
} from '@welshman/util'
|
||||||
import type {TrustedEvent, Filter} from '@welshman/util'
|
import type {TrustedEvent, Filter} from '@welshman/util'
|
||||||
import {ConnectionStatus} from '@welshman/net'
|
import {ConnectionStatus} from '@welshman/net'
|
||||||
import type {RelaysAndFilters} from '@welshman/net'
|
import type {RelaysAndFilters} from '@welshman/net'
|
||||||
import {pubkey} from './session'
|
import {pubkey} from './session'
|
||||||
import {relaySelectionsByPubkey, getReadRelayUrls, getWriteRelayUrls, getRelayUrls} from './relaySelections'
|
import {relaySelectionsByPubkey, inboxRelaySelectionsByPubkey, getReadRelayUrls, getWriteRelayUrls, getRelayUrls} from './relaySelections'
|
||||||
import {relays, relaysByUrl} from './relays'
|
import {relays, relaysByUrl} from './relays'
|
||||||
|
|
||||||
export const INDEXED_KINDS = [PROFILE, RELAYS, INBOX_RELAYS, FOLLOWS]
|
export const INDEXED_KINDS = [PROFILE, RELAYS, INBOX_RELAYS, FOLLOWS]
|
||||||
@@ -185,6 +185,8 @@ export class Router {
|
|||||||
|
|
||||||
WriteRelays = () => this.scenario(this.getUserSelections(RelayMode.Write))
|
WriteRelays = () => this.scenario(this.getUserSelections(RelayMode.Write))
|
||||||
|
|
||||||
|
InboxRelays = () => this.scenario(this.getUserSelections(RelayMode.Inbox)).policy(addNoFallbacks)
|
||||||
|
|
||||||
Messages = (pubkeys: string[]) =>
|
Messages = (pubkeys: string[]) =>
|
||||||
this.scenario([
|
this.scenario([
|
||||||
...this.getUserSelections(),
|
...this.getUserSelections(),
|
||||||
@@ -426,7 +428,7 @@ export const getRelayQuality = (url: string) => {
|
|||||||
|
|
||||||
export const getPubkeyRelays = (pubkey: string, mode?: string) => {
|
export const getPubkeyRelays = (pubkey: string, mode?: string) => {
|
||||||
const $relaySelections = relaySelectionsByPubkey.get()
|
const $relaySelections = relaySelectionsByPubkey.get()
|
||||||
const $inboxSelections = relaySelectionsByPubkey.get()
|
const $inboxSelections = inboxRelaySelectionsByPubkey.get()
|
||||||
|
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case RelayMode.Read: return getReadRelayUrls($relaySelections.get(pubkey))
|
case RelayMode.Read: return getReadRelayUrls($relaySelections.get(pubkey))
|
||||||
@@ -518,6 +520,17 @@ export const getFilterSelectionsForContext = (state: FilterSelectionRuleState) =
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const getFilterSelectionsForWraps = (state: FilterSelectionRuleState) => {
|
||||||
|
if (state.filter.kinds?.includes(WRAP) || !state.filter.authors) return false
|
||||||
|
|
||||||
|
const id = getFilterId({...state.filter, kinds: [WRAP]})
|
||||||
|
const scenario = ctx.app.router.InboxRelays().update(assoc('value', id))
|
||||||
|
|
||||||
|
state.selections.push(makeFilterSelection(id, state.filter, scenario))
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
export const getFilterSelectionsForIndexedKinds = (state: FilterSelectionRuleState) => {
|
export const getFilterSelectionsForIndexedKinds = (state: FilterSelectionRuleState) => {
|
||||||
const kinds = intersection(INDEXED_KINDS, state.filter.kinds || [])
|
const kinds = intersection(INDEXED_KINDS, state.filter.kinds || [])
|
||||||
|
|
||||||
@@ -558,6 +571,7 @@ export const defaultFilterSelectionRules = [
|
|||||||
getFilterSelectionsForLocalRelay,
|
getFilterSelectionsForLocalRelay,
|
||||||
getFilterSelectionsForSearch,
|
getFilterSelectionsForSearch,
|
||||||
getFilterSelectionsForContext,
|
getFilterSelectionsForContext,
|
||||||
|
getFilterSelectionsForWraps,
|
||||||
getFilterSelectionsForIndexedKinds,
|
getFilterSelectionsForIndexedKinds,
|
||||||
getFilterSelectionsForAuthors,
|
getFilterSelectionsForAuthors,
|
||||||
getFilterSelectionsForUser,
|
getFilterSelectionsForUser,
|
||||||
|
|||||||
@@ -18,36 +18,39 @@ export type AppSyncOpts = {
|
|||||||
filters: Filter[]
|
filters: Filter[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export const pull = async ({relays, filters}: AppSyncOpts) =>
|
export const pull = async ({relays, filters}: AppSyncOpts) => {
|
||||||
|
const events = repository.query(filters)
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
relays.map(async relay => {
|
relays.map(async relay => {
|
||||||
const events = repository.query(filters)
|
|
||||||
|
|
||||||
await hasNegentropy(relay)
|
await hasNegentropy(relay)
|
||||||
? basePull({filters, events, relays: [relay]})
|
? basePull({filters, events, relays: [relay]})
|
||||||
: pullWithoutNegentropy({filters, relays: [relay]})
|
: pullWithoutNegentropy({filters, relays: [relay]})
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const push = async ({relays, filters}: AppSyncOpts) => {
|
||||||
|
const events = repository.query(filters).filter(isSignedEvent)
|
||||||
|
|
||||||
export const push = async ({relays, filters}: AppSyncOpts) =>
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
relays.map(async relay => {
|
relays.map(async relay => {
|
||||||
const events = repository.query(filters).filter(isSignedEvent)
|
|
||||||
|
|
||||||
await hasNegentropy(relay)
|
await hasNegentropy(relay)
|
||||||
? basePush({filters, events, relays: [relay]})
|
? basePush({filters, events, relays: [relay]})
|
||||||
: pushWithoutNegentropy({events, relays: [relay]})
|
: pushWithoutNegentropy({events, relays: [relay]})
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const sync = async ({relays, filters}: AppSyncOpts) => {
|
||||||
|
const events = repository.query(filters).filter(isSignedEvent)
|
||||||
|
|
||||||
export const sync = async ({relays, filters}: AppSyncOpts) =>
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
relays.map(async relay => {
|
relays.map(async relay => {
|
||||||
const events = repository.query(filters).filter(isSignedEvent)
|
|
||||||
|
|
||||||
await hasNegentropy(relay)
|
await hasNegentropy(relay)
|
||||||
? baseSync({filters, events, relays: [relay]})
|
? baseSync({filters, events, relays: [relay]})
|
||||||
: syncWithoutNegentropy({filters, events, relays: [relay]})
|
: syncWithoutNegentropy({filters, events, relays: [relay]})
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user