Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/**
* Manage push notification subscriptions on sign-in/sign-out.
*/
Onyx.connect({

Check warning on line 20 in src/libs/Notification/PushNotification/subscribeToPushNotifications.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.NVP_PRIVATE_PUSH_NOTIFICATION_ID,
callback: (notificationID) => {
if (notificationID) {
Expand All @@ -41,7 +41,7 @@
});

let isSingleNewDotEntry: boolean | undefined;
Onyx.connect({

Check warning on line 44 in src/libs/Notification/PushNotification/subscribeToPushNotifications.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.HYBRID_APP,
callback: (value) => {
if (!value) {
Expand All @@ -52,7 +52,7 @@
});

function applyOnyxData({reportID, onyxData, lastUpdateID, previousUpdateID, hasPendingOnyxUpdates = false}: PushNotificationData): Promise<void> {
Log.info(`[PushNotification] Applying onyx data in the ${Visibility.isVisible() ? 'foreground' : 'background'}`, false, {reportID});
Log.info(`[PushNotification] Applying onyx data in the ${Visibility.isVisible() ? 'foreground' : 'background'}`, false, {reportID, lastUpdateID});

const logMissingOnyxDataInfo = (isDataMissing: boolean): boolean => {
if (isDataMissing) {
Expand Down Expand Up @@ -151,7 +151,7 @@

function getLastUpdateIDAppliedToClient(): Promise<number> {
return new Promise((resolve) => {
Onyx.connect({

Check warning on line 154 in src/libs/Notification/PushNotification/subscribeToPushNotifications.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT,
callback: (value) => resolve(value ?? CONST.DEFAULT_NUMBER_ID),
});
Expand Down
26 changes: 13 additions & 13 deletions src/libs/actions/OnyxUpdates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// This key needs to be separate from ONYXKEYS.ONYX_UPDATES_FROM_SERVER so that it can be updated without triggering the callback when the server IDs are updated. If that
// callback were triggered it would lead to duplicate processing of server updates.
let lastUpdateIDAppliedToClient: number | undefined = 0;
Onyx.connect({

Check warning on line 18 in src/libs/actions/OnyxUpdates.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT,
callback: (val) => (lastUpdateIDAppliedToClient = val),
});
Expand All @@ -26,9 +26,9 @@

let airshipEventsPromise = Promise.resolve();

function applyHTTPSOnyxUpdates(request: Request, response: Response) {
function applyHTTPSOnyxUpdates(request: Request, response: Response, lastUpdateID: number) {
Performance.markStart(CONST.TIMING.APPLY_HTTPS_UPDATES);
console.debug('[OnyxUpdateManager] Applying https update');
Log.info('[OnyxUpdateManager] Applying https update', false, {lastUpdateID});
// For most requests we can immediately update Onyx. For write requests we queue the updates and apply them after the sequential queue has flushed to prevent a replay effect in
// the UI. See https://github.com/Expensify/App/issues/12775 for more info.
const updateHandler: (updates: OnyxUpdate[]) => Promise<unknown> = request?.data?.apiRequestType === CONST.API_REQUEST_TYPE.WRITE ? queueOnyxUpdates : Onyx.update;
Expand Down Expand Up @@ -64,40 +64,40 @@
})
.then(() => {
Performance.markEnd(CONST.TIMING.APPLY_HTTPS_UPDATES);
console.debug('[OnyxUpdateManager] Done applying HTTPS update');
Log.info('[OnyxUpdateManager] Done applying HTTPS update', false, {lastUpdateID});
return Promise.resolve(response);
});
}

function applyPusherOnyxUpdates(updates: OnyxUpdateEvent[]) {
function applyPusherOnyxUpdates(updates: OnyxUpdateEvent[], lastUpdateID: number) {
Performance.markStart(CONST.TIMING.APPLY_PUSHER_UPDATES);

pusherEventsPromise = pusherEventsPromise.then(() => {
console.debug('[OnyxUpdateManager] Applying pusher update');
Log.info('[OnyxUpdateManager] Applying pusher update', false, {lastUpdateID});
});

pusherEventsPromise = updates
.reduce((promise, update) => promise.then(() => PusherUtils.triggerMultiEventHandler(update.eventType, update.data)), pusherEventsPromise)
.then(() => {
Performance.markEnd(CONST.TIMING.APPLY_PUSHER_UPDATES);
console.debug('[OnyxUpdateManager] Done applying Pusher update');
Log.info('[OnyxUpdateManager] Done applying Pusher update', false, {lastUpdateID});
});

return pusherEventsPromise;
}

function applyAirshipOnyxUpdates(updates: OnyxUpdateEvent[]) {
function applyAirshipOnyxUpdates(updates: OnyxUpdateEvent[], lastUpdateID: number) {
Performance.markStart(CONST.TIMING.APPLY_AIRSHIP_UPDATES);

airshipEventsPromise = airshipEventsPromise.then(() => {
console.debug('[OnyxUpdateManager] Applying Airship updates');
Log.info('[OnyxUpdateManager] Applying Airship updates', false, {lastUpdateID});
});

airshipEventsPromise = updates
.reduce((promise, update) => promise.then(() => Onyx.update(update.data)), airshipEventsPromise)
.then(() => {
Performance.markEnd(CONST.TIMING.APPLY_AIRSHIP_UPDATES);
console.debug('[OnyxUpdateManager] Done applying Airship updates');
Log.info('[OnyxUpdateManager] Done applying Airship updates', false, {lastUpdateID});
});

return airshipEventsPromise;
Expand Down Expand Up @@ -136,7 +136,7 @@

// We use a spread here instead of delete because we don't want to change the response for other middlewares
const {onyxData, ...responseWithoutOnyxData} = response;
return applyHTTPSOnyxUpdates(request, responseWithoutOnyxData);
return applyHTTPSOnyxUpdates(request, responseWithoutOnyxData, Number(lastUpdateID));
}

return Promise.resolve();
Expand All @@ -145,13 +145,13 @@
Onyx.merge(ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT, Number(lastUpdateID));
}
if (type === CONST.ONYX_UPDATE_TYPES.HTTPS && request && response) {
return applyHTTPSOnyxUpdates(request, response);
return applyHTTPSOnyxUpdates(request, response, Number(lastUpdateID));
}
if (type === CONST.ONYX_UPDATE_TYPES.PUSHER && updates) {
return applyPusherOnyxUpdates(updates);
return applyPusherOnyxUpdates(updates, Number(lastUpdateID));
}
if (type === CONST.ONYX_UPDATE_TYPES.AIRSHIP && updates) {
return applyAirshipOnyxUpdates(updates);
return applyAirshipOnyxUpdates(updates, Number(lastUpdateID));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/__mocks__/OnyxUpdates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
};

let lastUpdateIDAppliedToClient: number | undefined = 0;
Onyx.connect({

Check warning on line 16 in src/libs/actions/__mocks__/OnyxUpdates.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT,
callback: (val) => (lastUpdateIDAppliedToClient = val),
});
Expand All @@ -24,7 +24,7 @@
}

if (request && response) {
return applyHTTPSOnyxUpdates(request, response).then(() => undefined);
return applyHTTPSOnyxUpdates(request, response, Number(lastUpdateID)).then(() => undefined);
}

return Promise.resolve();
Expand Down
Loading