hold unread status and notificatoin count until first sync complete
This commit is contained in:
parent
d8cb89ca57
commit
86e6e539a6
4 changed files with 38 additions and 7 deletions
|
|
@ -3,7 +3,7 @@ import { useCallback, useEffect } from 'react';
|
|||
import { UnreadNotificationCounts } from 'neurone/lib/api/types';
|
||||
import { useRoomsNotificationPreferencesContext } from '../../hooks/useRoomsNotificationPreferences';
|
||||
import { ClientContext } from '../../../client/context';
|
||||
import { useObservableValue } from '../../hooks/useObservableValue';
|
||||
import { useObservableValue, useObservableValueListener } from '../../hooks/useObservableValue';
|
||||
|
||||
export type Notifications = UnreadNotificationCounts & {
|
||||
threads: Map<string, UnreadNotificationCounts>;
|
||||
|
|
@ -54,6 +54,15 @@ export const useBindRoomToNotificationsAtom = (
|
|||
}, [notifications, threadNotifications, setNotificationAtom, roomsNotificationPreferences]);
|
||||
|
||||
useEffect(() => {
|
||||
processNotifications();
|
||||
}, [processNotifications]);
|
||||
if (!ct.firstSync) {
|
||||
processNotifications();
|
||||
}
|
||||
}, [ct.firstSync, processNotifications]);
|
||||
|
||||
useObservableValueListener(
|
||||
ct.firstSync,
|
||||
useCallback(() => {
|
||||
processNotifications();
|
||||
}, [processNotifications])
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { atom, useSetAtom } from 'jotai';
|
||||
import { useEffect } from 'react';
|
||||
import { useCallback, useEffect } from 'react';
|
||||
import { ThreadId } from '../../../types/matrix/room';
|
||||
import { useObservableValue } from '../../hooks/useObservableValue';
|
||||
import { useObservableValue, useObservableValueListener } from '../../hooks/useObservableValue';
|
||||
import { getReadReceiptId } from '../../../client/storage/collections';
|
||||
import { ClientContext } from '../../../client/context';
|
||||
|
||||
|
|
@ -12,7 +12,7 @@ export const useBindUnreadRoomsAtom = (ct: ClientContext, unreadRooms: typeof un
|
|||
const roomToLatestEvent = useObservableValue(ct.roomToLatestEvent);
|
||||
const userReadReceipts = useObservableValue(ct.userReadReceipt);
|
||||
|
||||
useEffect(() => {
|
||||
const proccessUnread = useCallback(() => {
|
||||
const unreads = new Set<string>();
|
||||
|
||||
Array.from(roomToLatestEvent.entries()).forEach(([roomId, event]) => {
|
||||
|
|
@ -27,4 +27,17 @@ export const useBindUnreadRoomsAtom = (ct: ClientContext, unreadRooms: typeof un
|
|||
|
||||
setUnreadRooms(unreads);
|
||||
}, [ct, setUnreadRooms, userReadReceipts, roomToLatestEvent]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!ct.firstSync) {
|
||||
proccessUnread();
|
||||
}
|
||||
}, [ct.firstSync, proccessUnread]);
|
||||
|
||||
useObservableValueListener(
|
||||
ct.firstSync,
|
||||
useCallback(() => {
|
||||
proccessUnread();
|
||||
}, [proccessUnread])
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -137,6 +137,7 @@ export type ClientContext = {
|
|||
megolmBackup: MegolmBackup;
|
||||
|
||||
sync: SyncContext;
|
||||
firstSync: ObservableValue<boolean>;
|
||||
requestAuthJSON: MatrixRequest;
|
||||
getTxnId: GetTxnId;
|
||||
logout: () => Promise<void>;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { MatrixRequest } from 'neurone/lib/matrix-request';
|
||||
import { Disposer } from 'neurone/lib/utils/disposable';
|
||||
import { ObservableValue } from 'neurone/lib/utils/observable';
|
||||
import { removeSession, Session } from './sessions';
|
||||
import {
|
||||
ClientContext,
|
||||
|
|
@ -42,6 +43,7 @@ import { initializeCrypto } from './crypto';
|
|||
import { MegolmBackup } from './MegolmBackup';
|
||||
import { clearUserLocalStorage } from './localStorage';
|
||||
import { CallSessions } from './call';
|
||||
import { randomStr } from '../app/utils/common';
|
||||
|
||||
export type InitializeClientResult = {
|
||||
ct: ClientContext;
|
||||
|
|
@ -49,6 +51,7 @@ export type InitializeClientResult = {
|
|||
};
|
||||
export const initializeClient = async (session: Session): Promise<InitializeClientResult> => {
|
||||
const disposer = new Disposer();
|
||||
const publisherKey = randomStr();
|
||||
|
||||
const { storage, deleteStorage, disconnectStorage } = await createStorage(session);
|
||||
|
||||
|
|
@ -105,6 +108,7 @@ export const initializeClient = async (session: Session): Promise<InitializeClie
|
|||
sync,
|
||||
() => syncTokenObservable.read
|
||||
);
|
||||
const firstSync = new ObservableValue(true, publisherKey);
|
||||
|
||||
const decryption = new DecryptionManager(machine);
|
||||
|
||||
|
|
@ -169,6 +173,7 @@ export const initializeClient = async (session: Session): Promise<InitializeClie
|
|||
observable: syncObservable,
|
||||
controller: syncController,
|
||||
},
|
||||
firstSync,
|
||||
requestAuthJSON,
|
||||
getTxnId,
|
||||
logout: () => logoutManager.logout(),
|
||||
|
|
@ -178,7 +183,10 @@ export const initializeClient = async (session: Session): Promise<InitializeClie
|
|||
const machineManager = new MachineManager(ct);
|
||||
|
||||
const syncResponseManager = new SyncResponseManager(ct, syncTokenObservable, {
|
||||
onWriteComplete,
|
||||
onWriteComplete: () => {
|
||||
if (firstSync.read) firstSync.publish(publisherKey, false);
|
||||
onWriteComplete();
|
||||
},
|
||||
onSyncToken,
|
||||
onVerificationRequest,
|
||||
onToDeviceEvents,
|
||||
|
|
|
|||
Loading…
Reference in a new issue