Fix data reload on socket reset

This commit is contained in:
Bojan Mojsilovic 2024-01-11 17:12:55 +01:00
parent e9f320698c
commit d849f984ab
7 changed files with 37 additions and 13 deletions

View File

@ -344,8 +344,11 @@ export const HomeProvider = (props: { children: ContextChildren }) => {
updateStore('scrollTop', () => top);
};
let currentFeed = '';
const selectFeed = (feed: PrimalFeed | undefined) => {
if (feed !== undefined && feed.hex !== undefined) {
if (feed?.hex !== undefined && feed.hex !== currentFeed) {
currentFeed = feed.hex;
updateStore('selectedFeed', reconcile({...feed}));
clearNotes();
fetchNotes(feed.hex , `${APP_ID}`, 0, feed.includeReplies);
@ -623,8 +626,11 @@ export const HomeProvider = (props: { children: ContextChildren }) => {
}
});
let keyIsDone = false;
createEffect(() => {
if (account?.isKeyLookupDone) {
if (account?.isKeyLookupDone && !keyIsDone && settings?.defaultFeed) {
keyIsDone = true;
selectFeed(settings?.defaultFeed);
}
});

View File

@ -564,10 +564,12 @@ export const MessagesProvider = (props: { children: ContextChildren }) => {
const orderedSenders = () => {
if (!store.senders) {
const senders = store.senders;
if (!senders) {
return [];
}
const senders = store.senders;
const counts = store.messageCountPerSender;
const ids = Object.keys(senders);
@ -797,8 +799,11 @@ export const MessagesProvider = (props: { children: ContextChildren }) => {
}
});
let isSecSet = false
createEffect(() => {
if (!account?.sec) {
if (!account?.sec && !isSecSet) {
isSecSet = true;
unsubscribeToMessagesStats(subidMsgCount);
updateStore('messageCount', () => 0);
updateStore('messageCountPerSender', reconcile({}));
@ -818,9 +823,12 @@ export const MessagesProvider = (props: { children: ContextChildren }) => {
updateStore('now', () => Math.floor((new Date()).getTime() / 1000));
};
let currentSender = '';
// When a sender is selected, get the first page of the conversation
createEffect(() => {
if (store.selectedSender) {
if (store.selectedSender && store.selectedSender !== currentSender) {
currentSender = store.selectedSender;
clearInterval(conversationRefreshInterval);
updateStore('encryptedMessages', () => []);

View File

@ -96,8 +96,6 @@ const Home: Component = () => {
}
setNewNotesCount(count);
});
onCleanup(()=> {

View File

@ -105,8 +105,11 @@ const Profile: Component = () => {
profile?.actions.clearZaps();
}
let keyIsDone = false
createEffect(() => {
if (account?.isKeyLookupDone) {
if (account?.isKeyLookupDone && !keyIsDone) {
keyIsDone = true;
setProfile(getHex());
}
});

View File

@ -32,6 +32,8 @@ const Thread: Component = () => {
let repliesHolder: HTMLDivElement | undefined;
let initialPostId = '';
const postId = () => {
if (params.postId.startsWith('note')) {
return params.postId;
@ -95,7 +97,12 @@ const Thread: Component = () => {
const isFetching = () => threadContext?.isFetching;
createEffect(() => {
threadContext?.actions.fetchNotes(postId());
const pid = postId();
if (pid !== initialPostId) {
threadContext?.actions.fetchNotes(pid);
initialPostId = pid;
}
});
let observer: IntersectionObserver | undefined;

View File

@ -13,9 +13,9 @@ const onOpen = () => {
const hook = (window as PrimalWindow).onPrimalCacheServerConnected;
hook && hook(cacheServer, socket());
socket().addEventListener('message', function(event) {
const hook = (window as PrimalWindow).onPrimalCacheServerMessageReceived;
hook && hook(cacheServer, event.data);
socket()?.addEventListener('message', function(event) {
const hook = (window as PrimalWindow).onPrimalCacheServerMessageReceived;
hook && hook(cacheServer, event.data);
});
}
}

View File

@ -277,6 +277,8 @@ export type FeedPage = {
postStats: NostrPostStats,
mentions?: Record<string, NostrNoteContent>,
noteActions: Record<string, NoteActions>,
since?: number,
until?: number,
};
export type TrendingNotesStore = {