refactor: outbox (inbox query) improvements
feat: sync account tool
This commit is contained in:
@ -65,6 +65,7 @@ export default function useLoginFeed() {
|
||||
EventKind.BookmarksList,
|
||||
EventKind.InterestsList,
|
||||
EventKind.PublicChatsList,
|
||||
EventKind.DirectMessage,
|
||||
]);
|
||||
if (CONFIG.features.subscriptions && !login.readonly) {
|
||||
b.withFilter().authors([pubKey]).kinds([EventKind.AppData]).tag("d", ["snort"]);
|
||||
|
@ -4,6 +4,7 @@ import { FormattedMessage, FormattedNumber } from "react-intl";
|
||||
|
||||
import { GiftsCache, Relay, RelayMetrics } from "@/Cache";
|
||||
import AsyncButton from "@/Components/Button/AsyncButton";
|
||||
import useLogin from "@/Hooks/useLogin";
|
||||
|
||||
export function CacheSettings() {
|
||||
return (
|
||||
@ -50,15 +51,24 @@ function CacheDetails<T>({ cache, name }: { cache: FeedCache<T>; name: ReactNode
|
||||
|
||||
function RelayCacheStats() {
|
||||
const [counts, setCounts] = useState<Record<string, number>>({});
|
||||
const [myEvents, setMyEvents] = useState<number>(0);
|
||||
const login = useLogin();
|
||||
|
||||
useEffect(() => {
|
||||
Relay.summary().then(setCounts);
|
||||
if (login.publicKey) {
|
||||
Relay.count(["REQ", "my", { authors: [login.publicKey] }]).then(setMyEvents);
|
||||
}
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="flex justify-between br p bg-superdark">
|
||||
<div className="flex flex-col g4 w-64">
|
||||
<FormattedMessage defaultMessage="Worker Relay" id="xSoIUU" />
|
||||
{myEvents && <p>
|
||||
<FormattedMessage defaultMessage="My events: {n}" id="lEnclp" values={{
|
||||
n: <FormattedNumber value={myEvents} />
|
||||
}} /></p>}
|
||||
<table className="text-secondary">
|
||||
<thead>
|
||||
<tr>
|
||||
@ -89,7 +99,7 @@ function RelayCacheStats() {
|
||||
</table>
|
||||
</div>
|
||||
<div className="flex flex-col gap-2">
|
||||
<AsyncButton onClick={() => {}}>
|
||||
<AsyncButton onClick={() => { }}>
|
||||
<FormattedMessage defaultMessage="Clear" id="/GCoTA" />
|
||||
</AsyncButton>
|
||||
<AsyncButton
|
||||
|
@ -6,6 +6,7 @@ import { SettingsMenuComponent } from "@/Pages/settings/Menu/SettingsMenuCompone
|
||||
import { SettingsMenuItems } from "../Menu/Menu";
|
||||
import { FollowsRelayHealth } from "./follows-relay-health";
|
||||
import { PruneFollowList } from "./prune-follows";
|
||||
import SyncAccountTool from "./sync-account";
|
||||
|
||||
const ToolMenuItems = [
|
||||
{
|
||||
@ -22,9 +23,21 @@ const ToolMenuItems = [
|
||||
iconBg: "bg-green-800",
|
||||
message: <FormattedMessage defaultMessage="Follows Relay Health" id="XQiFEl" />,
|
||||
path: "follows-relay-health",
|
||||
},
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
title: <FormattedMessage defaultMessage="Account Data" id="IIOul1" />,
|
||||
items: [
|
||||
{
|
||||
icon: "repost",
|
||||
iconBg: "bg-blue-800",
|
||||
message: <FormattedMessage defaultMessage="Sync Account" id="hMQmIw" />,
|
||||
path: "sync-account"
|
||||
}
|
||||
]
|
||||
}
|
||||
] as SettingsMenuItems;
|
||||
|
||||
export const ToolsPages = [
|
||||
@ -47,6 +60,10 @@ export const ToolsPages = [
|
||||
path: "follows-relay-health",
|
||||
element: <FollowsRelayHealth />,
|
||||
},
|
||||
{
|
||||
path: "sync-account",
|
||||
element: <SyncAccountTool />
|
||||
}
|
||||
] as Array<RouteObject>;
|
||||
|
||||
export function ToolsPage() {
|
||||
|
48
packages/app/src/Pages/settings/tools/sync-account.tsx
Normal file
48
packages/app/src/Pages/settings/tools/sync-account.tsx
Normal file
@ -0,0 +1,48 @@
|
||||
import { unwrap } from "@snort/shared";
|
||||
import { RangeSync, TaggedNostrEvent } from "@snort/system"
|
||||
import { SnortContext } from "@snort/system-react";
|
||||
import { useContext, useState } from "react";
|
||||
import { FormattedMessage, FormattedNumber } from "react-intl";
|
||||
|
||||
import AsyncButton from "@/Components/Button/AsyncButton";
|
||||
import useLogin from "@/Hooks/useLogin";
|
||||
import { SearchRelays } from "@/Utils/Const";
|
||||
|
||||
export default function SyncAccountTool() {
|
||||
const system = useContext(SnortContext);
|
||||
const login = useLogin();
|
||||
const [scan, setScan] = useState<number>();
|
||||
const [results, setResults] = useState<Array<TaggedNostrEvent>>([]);
|
||||
|
||||
async function start() {
|
||||
const relays = Object.entries(login.relays.item).filter(([, v]) => v.write).map(([k,]) => k);
|
||||
const sync = new RangeSync(system);
|
||||
sync.on("event", evs => {
|
||||
setResults(r => [...r, ...evs]);
|
||||
});
|
||||
sync.on("scan", t => setScan(t));
|
||||
await sync.sync({
|
||||
authors: [unwrap(login.publicKey)],
|
||||
relays: [...relays, ...Object.keys(CONFIG.defaultRelays), ...SearchRelays]
|
||||
})
|
||||
}
|
||||
return <>
|
||||
<p>
|
||||
<FormattedMessage defaultMessage="Sync all events for your profile into local cache" id="+QM0PJ" />
|
||||
</p>
|
||||
|
||||
{results.length > 0 && <h3>
|
||||
<FormattedMessage defaultMessage="Found {n} events" id="ufvXH1" values={{
|
||||
n: <FormattedNumber value={results.length} />
|
||||
}} />
|
||||
</h3>}
|
||||
{scan !== undefined && <h4>
|
||||
<FormattedMessage defaultMessage="Scanning {date}" id="OxPdQ0" values={{
|
||||
date: new Date(scan * 1000).toLocaleDateString()
|
||||
}} />
|
||||
</h4>}
|
||||
<AsyncButton onClick={start}>
|
||||
<FormattedMessage defaultMessage="Start" id="mOFG3K" />
|
||||
</AsyncButton>
|
||||
</>
|
||||
}
|
@ -32,10 +32,9 @@ export const SnortPubKey = "npub1sn0rtcjcf543gj4wsg7fa59s700d5ztys5ctj0g69g2x680
|
||||
* Default search relays
|
||||
*/
|
||||
export const SearchRelays = [
|
||||
"wss://relay.nostr.band",
|
||||
"wss://search.nos.today",
|
||||
"wss://relay.noswhere.com",
|
||||
"wss://saltivka.org",
|
||||
"wss://relay.nostr.band/",
|
||||
"wss://search.nos.today/",
|
||||
"wss://relay.noswhere.com/",
|
||||
];
|
||||
|
||||
export const DeveloperAccounts = [
|
||||
|
Reference in New Issue
Block a user