Skip to content

Commit

Permalink
Temporary changes for staff release
Browse files Browse the repository at this point in the history
  • Loading branch information
atulsmadhugiri committed Jul 28, 2022
1 parent 8a1bb45 commit 95859fc
Showing 1 changed file with 42 additions and 8 deletions.
50 changes: 42 additions & 8 deletions native/redux/redux-setup.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @flow

import { isEqual } from 'lodash/lang';
import { AppState as NativeAppState, Platform, Alert } from 'react-native';
import ExitApp from 'react-native-exit-app';
import Orientation from 'react-native-orientation-locker';
Expand All @@ -20,6 +21,7 @@ import {
invalidSessionDowngrade,
invalidSessionRecovery,
} from 'lib/shared/account-utils';
import { isStaff } from 'lib/shared/user-utils';
import { defaultEnabledApps } from 'lib/types/enabled-apps';
import { defaultCalendarFilters } from 'lib/types/filter-types';
import type { Dispatch, BaseAction } from 'lib/types/redux-types';
Expand All @@ -32,7 +34,10 @@ import type { ThreadStoreOperation } from 'lib/types/thread-types';
import { updateTypes } from 'lib/types/update-types';
import { reduxLoggerMiddleware } from 'lib/utils/action-logger';
import { setNewSessionActionType } from 'lib/utils/action-utils';
import { convertMessageStoreOperationsToClientDBOperations } from 'lib/utils/message-ops-utils';
import {
convertMessageStoreOperationsToClientDBOperations,
translateClientDBMessageInfosToRawMessageInfos,
} from 'lib/utils/message-ops-utils';
import { convertThreadStoreOperationsToClientDBOperations } from 'lib/utils/thread-ops-utils';

import { defaultNavInfo } from '../navigation/default-state';
Expand Down Expand Up @@ -313,6 +318,42 @@ function reducer(state: AppState = defaultState, action: Action) {
const convertedMessageStoreOperations = convertMessageStoreOperationsToClientDBOperations(
messageStoreOperations,
);

if (convertedMessageStoreOperations.length > 0) {
global.CommCoreModule.processMessageStoreOperationsSync(
convertedMessageStoreOperations,
);
}

const crashReportsEnabled = state.reportStore.enabledReports.crashReports;
const viewerID = state.currentUserInfo?.id;

try {
const messages = global.CommCoreModule.getAllMessagesSync();
const rawMsgsFromSQLite = translateClientDBMessageInfosToRawMessageInfos(
messages,
);

const ignoreList = [
'@@INIT',
'persist/REHYDRATE',
'persist/PERSIST',
'SET_THREAD_STORE',
];
if (
!isEqual(rawMsgsFromSQLite, state.messageStore.messages) &&
!ignoreList.includes(action.type) &&
!action.type.includes('@@redux/INIT')
) {
Alert.alert(`${action.type}: NOT EQUAL`);
}
} catch (e) {
if ((__DEV__ || (viewerID && isStaff(viewerID))) && crashReportsEnabled) {
throw e;
}
console.log(e.message);
}

(async () => {
try {
const promises = [];
Expand All @@ -323,13 +364,6 @@ function reducer(state: AppState = defaultState, action: Action) {
),
);
}
if (convertedMessageStoreOperations.length > 0) {
promises.push(
global.CommCoreModule.processMessageStoreOperations(
convertedMessageStoreOperations,
),
);
}
await Promise.all(promises);
} catch {
dispatch({
Expand Down

0 comments on commit 95859fc

Please sign in to comment.