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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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