Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run migrations and refresh app state if relevant #7620

Merged
merged 28 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f49b260
Initial testing for refreshing Expenisfy app
Feb 8, 2022
cb3d47e
Add UserFixAccount command
Feb 16, 2022
a8c31bd
Merge branch 'main' of github.com:Expensify/App into amal-migration-app
Feb 17, 2022
905275d
Make UserFixAccount match other User_ functions
Feb 21, 2022
fbb3024
Require authToken for User_FixAccount
Feb 21, 2022
7aeaaa1
Merge branch 'main' of github.com:Expensify/App into amal-migration-app
Feb 21, 2022
c6bf430
Merge branch 'main' of github.com:Expensify/App into amal-migration-app
May 2, 2022
cffa9c0
Move loading of initialization data to Session
May 2, 2022
7491c3a
Remove unused imports
May 2, 2022
d60c3e3
Add JSDoc
May 2, 2022
e11e68e
Create fixAccountAndReload
May 2, 2022
286d06c
Check for migrations and reload after initial app loadup
May 2, 2022
b901321
Use early return
May 3, 2022
c9c52e7
Remove extra parantheses typo
May 3, 2022
7035a12
Move up in ordering
May 4, 2022
3c1d5c8
Rename and clean up comments
May 5, 2022
1eb5989
Merge branch 'main' of github.com:Expensify/App into amal-migration-app
May 5, 2022
6b258de
Reintroduce required inputs
May 5, 2022
34b2d12
Remove redundant functions and move reloading data functionality to a…
May 5, 2022
5eca072
Merge branch 'main' of github.com:Expensify/App into amal-migration-app
May 5, 2022
20cd05f
remove unused code
May 5, 2022
afa2de3
Use log instead of console.debug
May 5, 2022
6212538
Better comment
May 5, 2022
c34b37d
remove trailiing space
May 5, 2022
af85157
Merge branch 'main' of github.com:Expensify/App into amal-migration-app
May 6, 2022
7426e68
Clearer comments
May 6, 2022
8217889
Fix spelling
May 6, 2022
c353f45
Merge branch 'main' of github.com:Expensify/App into amal-migration-app
May 10, 2022
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
11 changes: 11 additions & 0 deletions src/libs/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,16 @@ function User_UploadAvatar(parameters) {
return Network.post(commandName, parameters);
}

/**
* Runs command that will fix malformed data in a users account and also run migrations.
*
* @returns {Promise}
*/
function User_FixAccount() {
const commandName = 'User_FixAccount';
return Network.post(commandName);
}

/**
* @param {Object} parameters
* @param {Number} parameters.accountID
Expand Down Expand Up @@ -969,6 +979,7 @@ export {
User_ReopenAccount,
User_SecondaryLogin_Send,
User_UploadAvatar,
User_FixAccount,
CreateIOUTransaction,
CreateIOUSplit,
ValidateEmail,
Expand Down
2 changes: 2 additions & 0 deletions src/libs/Navigation/AppNavigator/AuthScreens.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ class AuthScreens extends React.Component {
UnreadIndicatorUpdater.listenForReportChanges();
App.getAppData(false);

App.fixAccountAndReloadData();
marcaaron marked this conversation as resolved.
Show resolved Hide resolved

// Load policies, maybe creating a new policy first.
Linking.getInitialURL()
.then((url) => {
Expand Down
16 changes: 16 additions & 0 deletions src/libs/actions/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,21 @@ function getAppData(shouldSyncPolicyList = true) {
]);
}

/**
* Run FixAccount to check if we need to fix anything for the user or run migrations. Reinitialize the data if anything changed
* because some migrations might create new chat reports or their change data.
*/
function fixAccountAndReloadData() {
API.User_FixAccount()
.then((response) => {
if (!response.changed) {
return;
}
Log.info('FixAccount found updates for this user, so data will be reinitialized', true, response);
getAppData(false);
TomatoToaster marked this conversation as resolved.
Show resolved Hide resolved
});
}

// When the app reconnects from being offline, fetch all initialization data
NetworkConnection.onReconnect(getAppData);

Expand All @@ -125,4 +140,5 @@ export {
setSidebarLoaded,
getLocale,
getAppData,
fixAccountAndReloadData,
};