Changeset View
Changeset View
Standalone View
Standalone View
native/data/sqlite-data-handler.js
Show All 15 Lines | |||||
import { getMessageForException } from 'lib/utils/errors.js'; | import { getMessageForException } from 'lib/utils/errors.js'; | ||||
import { convertClientDBThreadInfosToRawThreadInfos } from 'lib/utils/thread-ops-utils.js'; | import { convertClientDBThreadInfosToRawThreadInfos } from 'lib/utils/thread-ops-utils.js'; | ||||
import { filesystemMediaCache } from '../media/media-cache.js'; | import { filesystemMediaCache } from '../media/media-cache.js'; | ||||
import { commCoreModule } from '../native-modules.js'; | import { commCoreModule } from '../native-modules.js'; | ||||
import { setStoreLoadedActionType } from '../redux/action-types.js'; | import { setStoreLoadedActionType } from '../redux/action-types.js'; | ||||
import { useSelector } from '../redux/redux-utils.js'; | import { useSelector } from '../redux/redux-utils.js'; | ||||
import { StaffContext } from '../staff/staff-context.js'; | import { StaffContext } from '../staff/staff-context.js'; | ||||
import { useInitialNotificationsEncryptedMessage } from '../utils/crypto-utils.js'; | |||||
import { isTaskCancelledError } from '../utils/error-handling.js'; | import { isTaskCancelledError } from '../utils/error-handling.js'; | ||||
import { useStaffCanSee } from '../utils/staff-utils.js'; | import { useStaffCanSee } from '../utils/staff-utils.js'; | ||||
function SQLiteDataHandler(): React.Node { | function SQLiteDataHandler(): React.Node { | ||||
const storeLoaded = useSelector(state => state.storeLoaded); | const storeLoaded = useSelector(state => state.storeLoaded); | ||||
const dispatch = useDispatch(); | const dispatch = useDispatch(); | ||||
const rehydrateConcluded = useSelector( | const rehydrateConcluded = useSelector( | ||||
state => !!(state._persist && state._persist.rehydrated), | state => !!(state._persist && state._persist.rehydrated), | ||||
); | ); | ||||
const cookie = useSelector(state => state.cookie); | const cookie = useSelector(state => state.cookie); | ||||
const urlPrefix = useSelector(state => state.urlPrefix); | const urlPrefix = useSelector(state => state.urlPrefix); | ||||
const staffCanSee = useStaffCanSee(); | const staffCanSee = useStaffCanSee(); | ||||
const { staffUserHasBeenLoggedIn } = React.useContext(StaffContext); | const { staffUserHasBeenLoggedIn } = React.useContext(StaffContext); | ||||
const loggedIn = useSelector(isLoggedIn); | const loggedIn = useSelector(isLoggedIn); | ||||
const currentLoggedInUserID = useSelector(state => | const currentLoggedInUserID = useSelector(state => | ||||
state.currentUserInfo?.anonymous ? undefined : state.currentUserInfo?.id, | state.currentUserInfo?.anonymous ? undefined : state.currentUserInfo?.id, | ||||
); | ); | ||||
const mediaCacheContext = React.useContext(MediaCacheContext); | const mediaCacheContext = React.useContext(MediaCacheContext); | ||||
const getInitialNotificationsEncryptedMessage = | |||||
useInitialNotificationsEncryptedMessage(); | |||||
const callFetchNewCookieFromNativeCredentials = React.useCallback( | const callFetchNewCookieFromNativeCredentials = React.useCallback( | ||||
async (source: LogInActionSource) => { | async (source: LogInActionSource) => { | ||||
try { | try { | ||||
await fetchNewCookieFromNativeCredentials( | await fetchNewCookieFromNativeCredentials( | ||||
dispatch, | dispatch, | ||||
cookie, | cookie, | ||||
urlPrefix, | urlPrefix, | ||||
source, | source, | ||||
getInitialNotificationsEncryptedMessage, | |||||
); | ); | ||||
dispatch({ type: setStoreLoadedActionType }); | dispatch({ type: setStoreLoadedActionType }); | ||||
} catch (fetchCookieException) { | } catch (fetchCookieException) { | ||||
if (staffCanSee) { | if (staffCanSee) { | ||||
Alert.alert( | Alert.alert( | ||||
`Error fetching new cookie from native credentials: ${ | `Error fetching new cookie from native credentials: ${ | ||||
getMessageForException(fetchCookieException) ?? | getMessageForException(fetchCookieException) ?? | ||||
'{no exception message}' | '{no exception message}' | ||||
}. Please kill the app.`, | }. Please kill the app.`, | ||||
); | ); | ||||
} else { | } else { | ||||
commCoreModule.terminate(); | commCoreModule.terminate(); | ||||
} | } | ||||
} | } | ||||
}, | }, | ||||
[cookie, dispatch, staffCanSee, urlPrefix], | [ | ||||
cookie, | |||||
dispatch, | |||||
staffCanSee, | |||||
urlPrefix, | |||||
getInitialNotificationsEncryptedMessage, | |||||
], | |||||
); | ); | ||||
const callClearSensitiveData = React.useCallback( | const callClearSensitiveData = React.useCallback( | ||||
async (triggeredBy: string) => { | async (triggeredBy: string) => { | ||||
if (staffCanSee || staffUserHasBeenLoggedIn) { | if (staffCanSee || staffUserHasBeenLoggedIn) { | ||||
Alert.alert('Starting SQLite database deletion process'); | Alert.alert('Starting SQLite database deletion process'); | ||||
} | } | ||||
await commCoreModule.clearSensitiveData(); | await commCoreModule.clearSensitiveData(); | ||||
▲ Show 20 Lines • Show All 140 Lines • Show Last 20 Lines |