MCPcopy Create free account
hub / github.com/CommE2E/comm / SQLiteDataHandler

Function SQLiteDataHandler

native/data/sqlite-data-handler.js:48–211  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

46}
47
48function SQLiteDataHandler(): React.Node {
49 const initialStateLoaded = useSelector(state => state.initialStateLoaded);
50
51 const dispatch = useDispatch();
52
53 const rehydrateConcluded = useSelector(
54 state => !!(state._persist && state._persist.rehydrated),
55 );
56 const staffCanSee = useStaffCanSee();
57 const loggedIn = useSelector(isLoggedIn);
58 const currentLoggedInUserID = useSelector(state =>
59 state.currentUserInfo?.anonymous ? undefined : state.currentUserInfo?.id,
60 );
61 const mediaCacheContext = React.useContext(MediaCacheContext);
62
63 const showCorruptionAlert = React.useCallback(() => {
64 const { showAlert } = getConfig();
65 showAlert(
66 'Corrupted data',
67 'Comm failed to load your local data. Please log in again.',
68 );
69 }, []);
70
71 const callClearSensitiveData = React.useCallback(
72 async (triggeredBy: string) => {
73 await clearSensitiveData();
74 const { showAlert, isStaffRelease } = getConfig();
75 if (isStaffRelease) {
76 showAlert('SQLite database deletion', `triggered by ${triggeredBy}`);
77 }
78 console.log(`SQLite database deletion was triggered by ${triggeredBy}`);
79 },
80 [],
81 );
82
83 const handleSensitiveData = React.useCallback(async () => {
84 try {
85 let sqliteStampedUserID,
86 errorGettingStampedUserID = false;
87 try {
88 sqliteStampedUserID = await commCoreModule.getSQLiteStampedUserID();
89 } catch (error) {
90 errorGettingStampedUserID = true;
91 console.log(
92 `Error getting SQLite stamped user ID: ${
93 getMessageForException(error) ?? 'unknown'
94 }`,
95 );
96 }
97 if (
98 errorGettingStampedUserID ||
99 shouldClearData(sqliteStampedUserID, currentLoggedInUserID)
100 ) {
101 await callClearSensitiveData('change in logged-in user credentials');
102 }
103 if (
104 currentLoggedInUserID &&
105 currentLoggedInUserID !== sqliteStampedUserID

Callers

nothing calls this directly

Calls 14

useSelectorFunction · 0.90
useDispatchFunction · 0.90
useStaffCanSeeFunction · 0.90
getConfigFunction · 0.90
getMessageForExceptionFunction · 0.90
shouldClearDataFunction · 0.90
isTaskCancelledErrorFunction · 0.90
clearSensitiveDataFunction · 0.70
logMethod · 0.45
stampSQLiteDBUserIDMethod · 0.45
terminateMethod · 0.45

Tested by

no test coverage detected