Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3356432
D11534.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D11534.diff
View Options
diff --git a/lib/shared/data-utils.js b/lib/shared/data-utils.js
new file mode 100644
--- /dev/null
+++ b/lib/shared/data-utils.js
@@ -0,0 +1,7 @@
+// @flow
+
+function shouldClearData(oldUserID: ?string, newUserID: ?string): boolean {
+ return !!oldUserID && oldUserID !== newUserID;
+}
+
+export { shouldClearData };
diff --git a/native/data/sqlite-data-handler.js b/native/data/sqlite-data-handler.js
--- a/native/data/sqlite-data-handler.js
+++ b/native/data/sqlite-data-handler.js
@@ -17,6 +17,7 @@
import { userStoreOpsHandlers } from 'lib/ops/user-store-ops.js';
import { isLoggedIn } from 'lib/selectors/user-selectors.js';
import { useInitialNotificationsEncryptedMessage } from 'lib/shared/crypto-utils.js';
+import { shouldClearData } from 'lib/shared/data-utils.js';
import {
recoveryActionSources,
type RecoveryActionSource,
@@ -139,10 +140,7 @@
const handleSensitiveData = React.useCallback(async () => {
try {
const databaseCurrentUserInfoID = await commCoreModule.getCurrentUserID();
- if (
- databaseCurrentUserInfoID &&
- databaseCurrentUserInfoID !== currentLoggedInUserID
- ) {
+ if (shouldClearData(databaseCurrentUserInfoID, currentLoggedInUserID)) {
await callClearSensitiveData('change in logged-in user credentials');
}
if (currentLoggedInUserID) {
diff --git a/native/redux/redux-setup.js b/native/redux/redux-setup.js
--- a/native/redux/redux-setup.js
+++ b/native/redux/redux-setup.js
@@ -21,6 +21,7 @@
import { reduceLoadingStatuses } from 'lib/reducers/loading-reducer.js';
import baseReducer from 'lib/reducers/master-reducer.js';
import { reduceCurrentUserInfo } from 'lib/reducers/user-reducer.js';
+import { shouldClearData } from 'lib/shared/data-utils.js';
import {
invalidSessionDowngrade,
invalidSessionRecovery,
@@ -279,11 +280,7 @@
state.currentUserInfo,
action,
);
- if (
- state.currentUserInfo &&
- !state.currentUserInfo?.anonymous &&
- newCurrentUserInfo?.id !== state.currentUserInfo?.id
- ) {
+ if (shouldClearData(state.currentUserInfo?.id, newCurrentUserInfo?.id)) {
state = resetUserSpecificState(
state,
defaultState,
diff --git a/web/redux/redux-setup.js b/web/redux/redux-setup.js
--- a/web/redux/redux-setup.js
+++ b/web/redux/redux-setup.js
@@ -24,6 +24,7 @@
import { reduceCurrentUserInfo } from 'lib/reducers/user-reducer.js';
import { mostRecentlyReadThreadSelector } from 'lib/selectors/thread-selectors.js';
import { isLoggedIn } from 'lib/selectors/user-selectors.js';
+import { shouldClearData } from 'lib/shared/data-utils.js';
import {
invalidSessionDowngrade,
identityInvalidSessionDowngrade,
@@ -353,11 +354,7 @@
state.currentUserInfo,
action,
);
- if (
- state.currentUserInfo &&
- !state.currentUserInfo?.anonymous &&
- newCurrentUserInfo?.id !== state.currentUserInfo?.id
- ) {
+ if (shouldClearData(state.currentUserInfo?.id, newCurrentUserInfo?.id)) {
state = resetUserSpecificState(
state,
defaultWebState,
diff --git a/web/shared-worker/sqlite-data-handler.js b/web/shared-worker/sqlite-data-handler.js
--- a/web/shared-worker/sqlite-data-handler.js
+++ b/web/shared-worker/sqlite-data-handler.js
@@ -2,6 +2,7 @@
import * as React from 'react';
+import { shouldClearData } from 'lib/shared/data-utils.js';
import { getMessageForException } from 'lib/utils/errors.js';
import { useDispatch } from 'lib/utils/redux-utils.js';
@@ -36,11 +37,10 @@
);
}
- if (currentDBUserID === currentLoggedInUserID && !errorGettingUserID) {
- return;
- }
-
- if (currentDBUserID || errorGettingUserID) {
+ if (
+ errorGettingUserID ||
+ shouldClearData(currentDBUserID, currentLoggedInUserID)
+ ) {
try {
await sharedWorker.init({ clearDatabase: true });
} catch (error) {
@@ -53,7 +53,8 @@
return;
}
}
- if (currentLoggedInUserID) {
+
+ if (currentLoggedInUserID && currentLoggedInUserID !== currentDBUserID) {
try {
await sharedWorker.schedule({
type: workerRequestMessageTypes.SET_CURRENT_USER_ID,
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 24, 6:49 PM (20 h, 35 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2577018
Default Alt Text
D11534.diff (4 KB)
Attached To
Mode
D11534: [web][native] Extract the common logic determining when to clear the data
Attached
Detach File
Event Timeline
Log In to Comment