bug: search page fix
This commit is contained in:
parent
12250c5e3d
commit
d573d075fe
@ -47,7 +47,7 @@ export const DefaultRelays = new Map<string, RelaySettings>([
|
|||||||
/**
|
/**
|
||||||
* Default search relays
|
* Default search relays
|
||||||
*/
|
*/
|
||||||
export const SearchRelays = new Map<string, RelaySettings>([["wss://relay.nostr.band", { read: true, write: false }]]);
|
export const SearchRelays = ["wss://relay.nostr.band"];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List of recommended follows for new users
|
* List of recommended follows for new users
|
||||||
|
@ -17,7 +17,10 @@ export default function useEventFeed(link: NostrLink) {
|
|||||||
f.kinds([unwrap(link.kind)]);
|
f.kinds([unwrap(link.kind)]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const f = b.withFilter().id(link.id, link.relays?.at(0));
|
const f = b.withFilter().ids([link.id]);
|
||||||
|
if (link.relays) {
|
||||||
|
link.relays.slice(0, 2).forEach(r => f.relay(r));
|
||||||
|
}
|
||||||
if (link.author) {
|
if (link.author) {
|
||||||
f.authors([link.author]);
|
f.authors([link.author]);
|
||||||
}
|
}
|
||||||
|
@ -22,9 +22,12 @@ export default function useThreadFeed(link: NostrLink) {
|
|||||||
leaveOpen: true,
|
leaveOpen: true,
|
||||||
});
|
});
|
||||||
if (trackingEvents.length > 0) {
|
if (trackingEvents.length > 0) {
|
||||||
const fTracking = sub.withFilter();
|
|
||||||
for (const te of trackingEvents) {
|
for (const te of trackingEvents) {
|
||||||
fTracking.id(te.id, te.relay);
|
const fTracking = sub.withFilter();
|
||||||
|
fTracking.ids([te.id]);
|
||||||
|
if (te.relay) {
|
||||||
|
fTracking.relay(te.relay);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (allEvents.length > 0) {
|
if (allEvents.length > 0) {
|
||||||
|
@ -6,6 +6,7 @@ import { unixNow, unwrap, tagFilterOfTextRepost } from "SnortUtils";
|
|||||||
import useTimelineWindow from "Hooks/useTimelineWindow";
|
import useTimelineWindow from "Hooks/useTimelineWindow";
|
||||||
import useLogin from "Hooks/useLogin";
|
import useLogin from "Hooks/useLogin";
|
||||||
import { System } from "index";
|
import { System } from "index";
|
||||||
|
import { SearchRelays } from "Const";
|
||||||
|
|
||||||
export interface TimelineFeedOptions {
|
export interface TimelineFeedOptions {
|
||||||
method: "TIME_RANGE" | "LIMIT_UNTIL";
|
method: "TIME_RANGE" | "LIMIT_UNTIL";
|
||||||
@ -64,10 +65,12 @@ export default function useTimelineFeed(subject: TimelineSubject, options: Timel
|
|||||||
}
|
}
|
||||||
case "profile_keyword": {
|
case "profile_keyword": {
|
||||||
f.search(subject.items[0] + " sort:popular");
|
f.search(subject.items[0] + " sort:popular");
|
||||||
|
SearchRelays.forEach(r => f.relay(r));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "post_keyword": {
|
case "post_keyword": {
|
||||||
f.search(subject.items[0]);
|
f.search(subject.items[0]);
|
||||||
|
SearchRelays.forEach(r => f.relay(r));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,7 @@ import Timeline from "Element/Timeline";
|
|||||||
import { Tab, TabElement } from "Element/Tabs";
|
import { Tab, TabElement } from "Element/Tabs";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { debounce } from "SnortUtils";
|
import { debounce } from "SnortUtils";
|
||||||
import { System, router } from "index";
|
import { router } from "index";
|
||||||
import { SearchRelays } from "Const";
|
|
||||||
import TrendingUsers from "Element/TrendingUsers";
|
import TrendingUsers from "Element/TrendingUsers";
|
||||||
|
|
||||||
import TrendingNotes from "Element/TrendingPosts";
|
import TrendingNotes from "Element/TrendingPosts";
|
||||||
@ -39,21 +38,6 @@ const SearchPage = () => {
|
|||||||
return debounce(500, () => setKeyword(search));
|
return debounce(500, () => setKeyword(search));
|
||||||
}, [search]);
|
}, [search]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const addedRelays: string[] = [];
|
|
||||||
for (const [k, v] of SearchRelays) {
|
|
||||||
if (!System.Sockets.some(v => v.address === k)) {
|
|
||||||
System.ConnectToRelay(k, v);
|
|
||||||
addedRelays.push(k);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return () => {
|
|
||||||
for (const r of addedRelays) {
|
|
||||||
System.DisconnectRelay(r);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
function tabContent() {
|
function tabContent() {
|
||||||
if (!keyword) {
|
if (!keyword) {
|
||||||
switch (tab.value) {
|
switch (tab.value) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import debug from "debug";
|
import debug from "debug";
|
||||||
import { v4 as uuid } from "uuid";
|
import { v4 as uuid } from "uuid";
|
||||||
import { appendDedupe, dedupe, unixNowMs } from "@snort/shared";
|
import { appendDedupe, sanitizeRelayUrl, unixNowMs } from "@snort/shared";
|
||||||
|
|
||||||
import { ReqFilter, u256, HexKey, EventKind } from ".";
|
import { ReqFilter, u256, HexKey, EventKind } from ".";
|
||||||
import { diffFilters } from "./RequestSplitter";
|
import { diffFilters } from "./RequestSplitter";
|
||||||
@ -24,9 +24,9 @@ export enum RequestStrategy {
|
|||||||
AuthorsRelays = 2,
|
AuthorsRelays = 2,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Relay hints are usually provided when using replies
|
* Use pre-determined relays for query
|
||||||
*/
|
*/
|
||||||
RelayHintedEventIds = 3,
|
ExplicitRelays = 3,
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -152,14 +152,21 @@ export class RequestBuilder {
|
|||||||
*/
|
*/
|
||||||
export class RequestFilterBuilder {
|
export class RequestFilterBuilder {
|
||||||
#filter: ReqFilter = {};
|
#filter: ReqFilter = {};
|
||||||
#relayHints = new Map<u256, Array<string>>();
|
#relays = new Set<string>();
|
||||||
|
|
||||||
get filter() {
|
get filter() {
|
||||||
return { ...this.#filter };
|
return { ...this.#filter };
|
||||||
}
|
}
|
||||||
|
|
||||||
get relayHints() {
|
/**
|
||||||
return new Map(this.#relayHints);
|
* Use a specific relay for this request filter
|
||||||
|
*/
|
||||||
|
relay(u: string) {
|
||||||
|
const uClean = sanitizeRelayUrl(u);
|
||||||
|
if (uClean) {
|
||||||
|
this.#relays.add(uClean);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
ids(ids: Array<u256>) {
|
ids(ids: Array<u256>) {
|
||||||
@ -167,13 +174,6 @@ export class RequestFilterBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
id(id: u256, relay?: string) {
|
|
||||||
if (relay) {
|
|
||||||
this.#relayHints.set(id, appendDedupe(this.#relayHints.get(id), [relay]));
|
|
||||||
}
|
|
||||||
return this.ids([id]);
|
|
||||||
}
|
|
||||||
|
|
||||||
authors(authors?: Array<HexKey>) {
|
authors(authors?: Array<HexKey>) {
|
||||||
if (!authors) return this;
|
if (!authors) return this;
|
||||||
this.#filter.authors = appendDedupe(this.#filter.authors, authors);
|
this.#filter.authors = appendDedupe(this.#filter.authors, authors);
|
||||||
@ -220,20 +220,13 @@ export class RequestFilterBuilder {
|
|||||||
* Build/expand this filter into a set of relay specific queries
|
* Build/expand this filter into a set of relay specific queries
|
||||||
*/
|
*/
|
||||||
build(relays: RelayCache, id: string): Array<BuiltRawReqFilter> {
|
build(relays: RelayCache, id: string): Array<BuiltRawReqFilter> {
|
||||||
// when querying for specific event ids with relay hints
|
// use the explicit relay list first
|
||||||
// take the first approach which is to split the filter by relay
|
if (this.#relays.size > 0) {
|
||||||
if (this.#filter.ids && this.#relayHints.size > 0) {
|
return [...this.#relays].map(r => {
|
||||||
const relays = dedupe([...this.#relayHints.values()].flat());
|
|
||||||
return relays.map(r => {
|
|
||||||
return {
|
return {
|
||||||
filters: [
|
filters: [this.#filter],
|
||||||
{
|
|
||||||
...this.#filter,
|
|
||||||
ids: [...this.#relayHints.entries()].filter(([, v]) => v.includes(r)).map(([k]) => k),
|
|
||||||
},
|
|
||||||
],
|
|
||||||
relay: r,
|
relay: r,
|
||||||
strategy: RequestStrategy.RelayHintedEventIds,
|
strategy: RequestStrategy.ExplicitRelays,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,14 @@ import { splitAllByWriteRelays } from "../src/GossipModel"
|
|||||||
describe("GossipModel", () => {
|
describe("GossipModel", () => {
|
||||||
it("should not output empty", () => {
|
it("should not output empty", () => {
|
||||||
const Relays = {
|
const Relays = {
|
||||||
get: (pk?: string) => {
|
getFromCache: (pk?: string) => {
|
||||||
return [];
|
if (pk) {
|
||||||
|
return {
|
||||||
|
pubkey: pk,
|
||||||
|
created_at: 0,
|
||||||
|
relays: []
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const a = [{
|
const a = [{
|
||||||
|
@ -2,22 +2,26 @@ import { RelayCache } from "../src/GossipModel";
|
|||||||
import { RequestBuilder, RequestStrategy } from "../src/RequestBuilder";
|
import { RequestBuilder, RequestStrategy } from "../src/RequestBuilder";
|
||||||
import { describe, expect } from "@jest/globals";
|
import { describe, expect } from "@jest/globals";
|
||||||
import { expandFilter } from "../src/RequestExpander";
|
import { expandFilter } from "../src/RequestExpander";
|
||||||
import { unixNowMs } from "../src/Utils";
|
|
||||||
import { bytesToHex } from "@noble/curves/abstract/utils";
|
import { bytesToHex } from "@noble/curves/abstract/utils";
|
||||||
|
import { unixNow, unixNowMs } from "@snort/shared";
|
||||||
|
|
||||||
const DummyCache = {
|
const DummyCache = {
|
||||||
get: (pk?: string) => {
|
getFromCache: (pk?: string) => {
|
||||||
if (!pk) return undefined;
|
if (!pk) return undefined;
|
||||||
|
|
||||||
return [
|
return {
|
||||||
{
|
pubkey: pk,
|
||||||
url: `wss://${pk}.com/`,
|
created_at: unixNow(),
|
||||||
settings: {
|
relays: [
|
||||||
read: true,
|
{
|
||||||
write: true,
|
url: `wss://${pk}.com/`,
|
||||||
|
settings: {
|
||||||
|
read: true,
|
||||||
|
write: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
]
|
||||||
];
|
};
|
||||||
},
|
},
|
||||||
} as RelayCache;
|
} as RelayCache;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user