Page MenuHomePhabricator

D11534.diff
No OneTemporary

D11534.diff

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

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)

Event Timeline