From e90946ab114bf0c6ce82b28d0674568bad08ce3d Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Tue, 12 Sep 2023 01:27:27 +0800 Subject: [PATCH 01/12] added a check if the value was a number and return if it is --- src/libs/actions/OnyxUpdateManager.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libs/actions/OnyxUpdateManager.js b/src/libs/actions/OnyxUpdateManager.js index f0051b85f302..a26b5c334b1c 100644 --- a/src/libs/actions/OnyxUpdateManager.js +++ b/src/libs/actions/OnyxUpdateManager.js @@ -35,6 +35,11 @@ export default () => { return; } + if (_.isNumber(val)) { + Onyx.set(ONYXKEYS.ONYX_UPDATES_FROM_SERVER, null); + return; + } + const updateParams = val; const lastUpdateIDFromServer = val.lastUpdateID; const previousUpdateIDFromServer = val.previousUpdateID; From 0236648bb72d02b99bf13372a4bf62d89fac696e Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Tue, 12 Sep 2023 01:30:05 +0800 Subject: [PATCH 02/12] adding comment --- src/libs/actions/OnyxUpdateManager.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/OnyxUpdateManager.js b/src/libs/actions/OnyxUpdateManager.js index a26b5c334b1c..e3361f3925f7 100644 --- a/src/libs/actions/OnyxUpdateManager.js +++ b/src/libs/actions/OnyxUpdateManager.js @@ -34,7 +34,9 @@ export default () => { if (!val) { return; } - + + // Since we used the same key that used to store lastUpdateID, once we start watching this variable we need + // to confirm that the value is what we expect and not a number. if (_.isNumber(val)) { Onyx.set(ONYXKEYS.ONYX_UPDATES_FROM_SERVER, null); return; From 6187e713540e6d8f349a7ea05235558e44b2842a Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Tue, 12 Sep 2023 01:30:25 +0800 Subject: [PATCH 03/12] adding prettier --- src/libs/actions/OnyxUpdateManager.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/OnyxUpdateManager.js b/src/libs/actions/OnyxUpdateManager.js index e3361f3925f7..924f6ef5245e 100644 --- a/src/libs/actions/OnyxUpdateManager.js +++ b/src/libs/actions/OnyxUpdateManager.js @@ -34,8 +34,8 @@ export default () => { if (!val) { return; } - - // Since we used the same key that used to store lastUpdateID, once we start watching this variable we need + + // Since we used the same key that used to store lastUpdateID, once we start watching this variable we need // to confirm that the value is what we expect and not a number. if (_.isNumber(val)) { Onyx.set(ONYXKEYS.ONYX_UPDATES_FROM_SERVER, null); From 9be34e858ab8e0fba38dc25e885fad7eb2c3bbfe Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Tue, 12 Sep 2023 01:37:36 +0800 Subject: [PATCH 04/12] changing to is object instead --- src/libs/actions/OnyxUpdateManager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/OnyxUpdateManager.js b/src/libs/actions/OnyxUpdateManager.js index 924f6ef5245e..df5792aeef3f 100644 --- a/src/libs/actions/OnyxUpdateManager.js +++ b/src/libs/actions/OnyxUpdateManager.js @@ -37,7 +37,7 @@ export default () => { // Since we used the same key that used to store lastUpdateID, once we start watching this variable we need // to confirm that the value is what we expect and not a number. - if (_.isNumber(val)) { + if (!_.isObject(val)) { Onyx.set(ONYXKEYS.ONYX_UPDATES_FROM_SERVER, null); return; } From a98dc74d82573f710e30fbf9b1ec2df7789ddbb4 Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Tue, 12 Sep 2023 01:51:19 +0800 Subject: [PATCH 05/12] changing if to check format of the update --- src/libs/actions/OnyxUpdateManager.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/OnyxUpdateManager.js b/src/libs/actions/OnyxUpdateManager.js index df5792aeef3f..a3d7735e14c0 100644 --- a/src/libs/actions/OnyxUpdateManager.js +++ b/src/libs/actions/OnyxUpdateManager.js @@ -35,9 +35,14 @@ export default () => { return; } - // Since we used the same key that used to store lastUpdateID, once we start watching this variable we need - // to confirm that the value is what we expect and not a number. - if (!_.isObject(val)) { + // Since we used the same key that used to store another object, let's confirm that the current object is + // following the new format before we proceed. If it isn't, then let's clera the object in Onyx. + if ( + !_.isObject(val) || + !val.hasOwnProperty('type') || + !(val.type === CONST.ONYX_UPDATE_TYPES.HTTPS && val.hasOwnProperty('request') && val.hasOwnProperty('response')) || + !(val.type === CONST.ONYX_UPDATE_TYPES.PUSHER && !val.hasOwnProperty('updates')) + ) { Onyx.set(ONYXKEYS.ONYX_UPDATES_FROM_SERVER, null); return; } From 6425ff1b697be7ff34a37fca6bfeb4eb6c4c8bc5 Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Tue, 12 Sep 2023 01:55:34 +0800 Subject: [PATCH 06/12] import _ --- src/libs/actions/OnyxUpdateManager.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/actions/OnyxUpdateManager.js b/src/libs/actions/OnyxUpdateManager.js index a3d7735e14c0..a56941623c6f 100644 --- a/src/libs/actions/OnyxUpdateManager.js +++ b/src/libs/actions/OnyxUpdateManager.js @@ -1,4 +1,5 @@ import Onyx from 'react-native-onyx'; +import _ from 'underscore'; import ONYXKEYS from '../../ONYXKEYS'; import Log from '../Log'; import * as SequentialQueue from '../Network/SequentialQueue'; From 3c59fb43cc2310c76f0a22dba1d500747a0061f1 Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Tue, 12 Sep 2023 02:02:50 +0800 Subject: [PATCH 07/12] linter and addressing comments --- src/libs/actions/OnyxUpdateManager.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/OnyxUpdateManager.js b/src/libs/actions/OnyxUpdateManager.js index a56941623c6f..73f158785a18 100644 --- a/src/libs/actions/OnyxUpdateManager.js +++ b/src/libs/actions/OnyxUpdateManager.js @@ -5,6 +5,7 @@ import Log from '../Log'; import * as SequentialQueue from '../Network/SequentialQueue'; import * as App from './App'; import * as OnyxUpdates from './OnyxUpdates'; +import CONST from '../../CONST'; // This file is in charge of looking at the updateIDs coming from the server and comparing them to the last updateID that the client has. // If the client is behind the server, then we need to @@ -37,12 +38,13 @@ export default () => { } // Since we used the same key that used to store another object, let's confirm that the current object is - // following the new format before we proceed. If it isn't, then let's clera the object in Onyx. + // following the new format before we proceed. If it isn't, then let's clear the object in Onyx. if ( !_.isObject(val) || !val.hasOwnProperty('type') || - !(val.type === CONST.ONYX_UPDATE_TYPES.HTTPS && val.hasOwnProperty('request') && val.hasOwnProperty('response')) || - !(val.type === CONST.ONYX_UPDATE_TYPES.PUSHER && !val.hasOwnProperty('updates')) + + !(val.type === CONST.ONYX_UPDATE_TYPES.HTTPS && Object.prototype.hasOwnProperty.call(val, 'request') && Object.prototype.hasOwnProperty.call(val, 'response')) || + !(val.type === CONST.ONYX_UPDATE_TYPES.PUSHER && Object.prototype.hasOwnProperty.call(val, 'updates')) ) { Onyx.set(ONYXKEYS.ONYX_UPDATES_FROM_SERVER, null); return; From e4172fdd5cd55d58548f517d29d7dc7a9bbbf177 Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Tue, 12 Sep 2023 02:07:46 +0800 Subject: [PATCH 08/12] missing linter --- src/libs/actions/OnyxUpdateManager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/OnyxUpdateManager.js b/src/libs/actions/OnyxUpdateManager.js index 73f158785a18..7a37d1f3de41 100644 --- a/src/libs/actions/OnyxUpdateManager.js +++ b/src/libs/actions/OnyxUpdateManager.js @@ -41,7 +41,7 @@ export default () => { // following the new format before we proceed. If it isn't, then let's clear the object in Onyx. if ( !_.isObject(val) || - !val.hasOwnProperty('type') || + !Object.prototype.hasOwnProperty.call(val,'type') || !(val.type === CONST.ONYX_UPDATE_TYPES.HTTPS && Object.prototype.hasOwnProperty.call(val, 'request') && Object.prototype.hasOwnProperty.call(val, 'response')) || !(val.type === CONST.ONYX_UPDATE_TYPES.PUSHER && Object.prototype.hasOwnProperty.call(val, 'updates')) From 1810160f19877dcf98db5215c4784f13d3e6e95e Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Tue, 12 Sep 2023 02:13:30 +0800 Subject: [PATCH 09/12] prettier --- src/libs/actions/OnyxUpdateManager.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libs/actions/OnyxUpdateManager.js b/src/libs/actions/OnyxUpdateManager.js index 7a37d1f3de41..acc26884bc2f 100644 --- a/src/libs/actions/OnyxUpdateManager.js +++ b/src/libs/actions/OnyxUpdateManager.js @@ -41,8 +41,7 @@ export default () => { // following the new format before we proceed. If it isn't, then let's clear the object in Onyx. if ( !_.isObject(val) || - !Object.prototype.hasOwnProperty.call(val,'type') || - + !Object.prototype.hasOwnProperty.call(val, 'type') || !(val.type === CONST.ONYX_UPDATE_TYPES.HTTPS && Object.prototype.hasOwnProperty.call(val, 'request') && Object.prototype.hasOwnProperty.call(val, 'response')) || !(val.type === CONST.ONYX_UPDATE_TYPES.PUSHER && Object.prototype.hasOwnProperty.call(val, 'updates')) ) { From 89455eb68f6a1f929b61ad1ebb31ed9e0f80ff26 Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Wed, 13 Sep 2023 13:39:38 +0800 Subject: [PATCH 10/12] changing to underscore function --- src/libs/actions/OnyxUpdateManager.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/OnyxUpdateManager.js b/src/libs/actions/OnyxUpdateManager.js index acc26884bc2f..1c96a2d11d74 100644 --- a/src/libs/actions/OnyxUpdateManager.js +++ b/src/libs/actions/OnyxUpdateManager.js @@ -41,9 +41,9 @@ export default () => { // following the new format before we proceed. If it isn't, then let's clear the object in Onyx. if ( !_.isObject(val) || - !Object.prototype.hasOwnProperty.call(val, 'type') || - !(val.type === CONST.ONYX_UPDATE_TYPES.HTTPS && Object.prototype.hasOwnProperty.call(val, 'request') && Object.prototype.hasOwnProperty.call(val, 'response')) || - !(val.type === CONST.ONYX_UPDATE_TYPES.PUSHER && Object.prototype.hasOwnProperty.call(val, 'updates')) + !_.has(val, 'type') || + !(val.type === CONST.ONYX_UPDATE_TYPES.HTTPS && _.has(val, 'request') && _.has(val, 'response')) || + !(val.type === CONST.ONYX_UPDATE_TYPES.PUSHER && _.has(val, 'updates')) ) { Onyx.set(ONYXKEYS.ONYX_UPDATES_FROM_SERVER, null); return; From 941fbc919f37fc6f9e482c128c1ae78396889cd6 Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Fri, 15 Sep 2023 14:06:02 +0800 Subject: [PATCH 11/12] changing OR to AND --- src/libs/actions/OnyxUpdateManager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/OnyxUpdateManager.js b/src/libs/actions/OnyxUpdateManager.js index 1c96a2d11d74..209b095550cb 100644 --- a/src/libs/actions/OnyxUpdateManager.js +++ b/src/libs/actions/OnyxUpdateManager.js @@ -42,7 +42,7 @@ export default () => { if ( !_.isObject(val) || !_.has(val, 'type') || - !(val.type === CONST.ONYX_UPDATE_TYPES.HTTPS && _.has(val, 'request') && _.has(val, 'response')) || + !(val.type === CONST.ONYX_UPDATE_TYPES.HTTPS && _.has(val, 'request') && _.has(val, 'response')) && !(val.type === CONST.ONYX_UPDATE_TYPES.PUSHER && _.has(val, 'updates')) ) { Onyx.set(ONYXKEYS.ONYX_UPDATES_FROM_SERVER, null); From 5029f33f05b75d82253883a51853c4331742e836 Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Fri, 15 Sep 2023 14:15:16 +0800 Subject: [PATCH 12/12] fixing clause, adding OR and unpausing sequential queue --- src/libs/actions/OnyxUpdateManager.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/OnyxUpdateManager.js b/src/libs/actions/OnyxUpdateManager.js index 209b095550cb..e0f3f8fd4622 100644 --- a/src/libs/actions/OnyxUpdateManager.js +++ b/src/libs/actions/OnyxUpdateManager.js @@ -42,10 +42,11 @@ export default () => { if ( !_.isObject(val) || !_.has(val, 'type') || - !(val.type === CONST.ONYX_UPDATE_TYPES.HTTPS && _.has(val, 'request') && _.has(val, 'response')) && - !(val.type === CONST.ONYX_UPDATE_TYPES.PUSHER && _.has(val, 'updates')) + (!(val.type === CONST.ONYX_UPDATE_TYPES.HTTPS && _.has(val, 'request') && _.has(val, 'response')) && !(val.type === CONST.ONYX_UPDATE_TYPES.PUSHER && _.has(val, 'updates'))) ) { + console.debug('[OnyxUpdateManager] Invalid format found for updates, cleaning and unpausing the queue'); Onyx.set(ONYXKEYS.ONYX_UPDATES_FROM_SERVER, null); + SequentialQueue.unpause(); return; }