mirror of
https://github.com/PrimalHQ/primal-web-app.git
synced 2024-09-29 00:10:50 +00:00
Call import_events on caching API on post to expedite note import
This commit is contained in:
parent
134bde9ab4
commit
6bb96d82d1
@ -52,23 +52,19 @@ const Layout: Component = () => {
|
||||
window.removeEventListener('resize', onResize);
|
||||
});
|
||||
|
||||
const onNewNotePosted = (note: SendNoteResult) => {
|
||||
const onNewNotePosted = (result: SendNoteResult) => {
|
||||
const path = location.pathname.split('/');
|
||||
|
||||
if (path[1] === 'home' && home) {
|
||||
// check for new notes on the home feed
|
||||
setTimeout(() => {
|
||||
home.actions.checkForNewNotes(home.selectedFeed?.hex)
|
||||
}, refreshFeedDelay);
|
||||
home.actions.checkForNewNotes(home.selectedFeed?.hex)
|
||||
return;
|
||||
}
|
||||
|
||||
if (['p', 'profile'].includes(path[1]) && profile) {
|
||||
const pubkey = params.npub;
|
||||
// check for new notes on the profile feed
|
||||
setTimeout(() => {
|
||||
profile.actions.checkForNewNotes(pubkey || account?.publicKey)
|
||||
}, refreshFeedDelay);
|
||||
profile.actions.checkForNewNotes(pubkey || account?.publicKey);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import { useAccountContext } from "../../../contexts/AccountContext";
|
||||
import { useSearchContext } from "../../../contexts/SearchContext";
|
||||
import { TranslatorProvider } from "../../../contexts/TranslatorContext";
|
||||
import { getEvents } from "../../../lib/feed";
|
||||
import { parseNote1, sanitize, sendNote, replaceLinkPreviews } from "../../../lib/notes";
|
||||
import { parseNote1, sanitize, sendNote, replaceLinkPreviews, importEvents } from "../../../lib/notes";
|
||||
import { getUserProfiles } from "../../../lib/profile";
|
||||
import { subscribeTo } from "../../../sockets";
|
||||
import { subscribeTo as uploadSub } from "../../../uploadSocket";
|
||||
@ -508,9 +508,24 @@ const EditBox: Component<{
|
||||
const { success, reasons, note } = await sendNote(messageToSend, account.relays, tags, account.relaySettings);
|
||||
|
||||
if (success) {
|
||||
toast?.sendSuccess(intl.formatMessage(tToast.publishNoteSuccess));
|
||||
props.onSuccess && props.onSuccess(note);
|
||||
closeEditor();
|
||||
|
||||
const importId = `import_note_${APP_ID}`;
|
||||
|
||||
const unsub = subscribeTo(importId, (type, _, response) => {
|
||||
console.log('IMPORTED: ', type, response)
|
||||
|
||||
if (type === 'EOSE') {
|
||||
if (note) {
|
||||
toast?.sendSuccess(intl.formatMessage(tToast.publishNoteSuccess));
|
||||
props.onSuccess && props.onSuccess({ success, reasons, note });
|
||||
closeEditor();
|
||||
}
|
||||
unsub();
|
||||
}
|
||||
});
|
||||
|
||||
note && importEvents([note], importId);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -123,6 +123,7 @@ export enum Kind {
|
||||
MediaInfo = 10_000_119,
|
||||
Upload = 10_000_120,
|
||||
Uploaded = 10_000_121,
|
||||
ImportResponse = 10_000_127,
|
||||
}
|
||||
|
||||
export const relayConnectingTimeout = 1000;
|
||||
|
@ -3,6 +3,7 @@ import { getLinkPreview } from "link-preview-js";
|
||||
import { Relay } from "nostr-tools";
|
||||
import { createStore } from "solid-js/store";
|
||||
import { Kind } from "../constants";
|
||||
import { sendMessage } from "../sockets";
|
||||
import { NostrRelays, NostrRelaySignedEvent, NostrWindow, PrimalNote, SendNoteResult } from "../types/primal";
|
||||
import { getMediaUrl } from "./media";
|
||||
|
||||
@ -220,6 +221,17 @@ export const parseNote1 = (content: string) => urlify(addlineBreaks(content));
|
||||
export const parseNote2 = (content: string) => urlify(addlineBreaks(content), true);
|
||||
export const parseNote3 = (content: string) => urlify(addlineBreaks(content), false, false, true);
|
||||
|
||||
|
||||
export const importEvents = (events: NostrRelaySignedEvent[], subid: string) => {
|
||||
|
||||
sendMessage(JSON.stringify([
|
||||
"REQ",
|
||||
subid,
|
||||
{cache: ["import_events", { events }]},
|
||||
]));
|
||||
};
|
||||
|
||||
|
||||
type ReplyTo = { e?: string, p?: string };
|
||||
type NostrEvent = { content: string, kind: number, tags: string[][], created_at: number };
|
||||
|
||||
|
@ -119,11 +119,8 @@ const Thread: Component = () => {
|
||||
pn && observer?.unobserve(pn);
|
||||
});
|
||||
|
||||
|
||||
const onNotePosted = (note: SendNoteResult) => {
|
||||
setTimeout(() => {
|
||||
threadContext?.actions.fetchNotes(postId());
|
||||
}, refreshFeedDelay);
|
||||
const onNotePosted = (result: SendNoteResult) => {
|
||||
threadContext?.actions.fetchNotes(postId());
|
||||
};
|
||||
|
||||
return (
|
||||
|
Loading…
Reference in New Issue
Block a user