fix: Fixed mixing of subscription events
This commit is contained in:
parent
71dd48d4f2
commit
fa021463cb
@ -75,6 +75,7 @@ const SlideShow = () => {
|
|||||||
const { currentSettings: settings } = useNav();
|
const { currentSettings: settings } = useNav();
|
||||||
const [state, setState] = useGlobalState();
|
const [state, setState] = useGlobalState();
|
||||||
const { autoLogin, setAutoLogin } = useAutoLogin();
|
const { autoLogin, setAutoLogin } = useAutoLogin();
|
||||||
|
const currentSubId = useRef("1");
|
||||||
|
|
||||||
const fetch = () => {
|
const fetch = () => {
|
||||||
if (!ndk) {
|
if (!ndk) {
|
||||||
@ -82,10 +83,17 @@ const SlideShow = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const postSubscription = ndk.subscribe(buildFilter(settings.tags, settings.npubs, settings.showReposts));
|
currentSubId.current = `${Math.floor(Math.random() * 10000000)}`
|
||||||
|
|
||||||
|
const postSubscription = ndk.subscribe(buildFilter(settings.tags, settings.npubs, settings.showReposts), {
|
||||||
|
subId: currentSubId.current
|
||||||
|
});
|
||||||
|
|
||||||
postSubscription.on('event', (event: NDKEvent) => {
|
postSubscription.on('event', (event: NDKEvent) => {
|
||||||
setPosts(oldPosts => {
|
setPosts(oldPosts => {
|
||||||
|
// Ignore event when the subscription's subId is not current any more.
|
||||||
|
if (postSubscription.subId !== currentSubId.current) return oldPosts;
|
||||||
|
|
||||||
//event.isReply = isReply(event);
|
//event.isReply = isReply(event);
|
||||||
|
|
||||||
if (event.kind === 1063) {
|
if (event.kind === 1063) {
|
||||||
|
Loading…
Reference in New Issue
Block a user