Skip to content

Commit

Permalink
[native] read users from SQLite on app start
Browse files Browse the repository at this point in the history
Summary:
Get data from DB and populate store.

Only native, web is in progress and those changes shouldn't affect anything.

Depends on D9913

Test Plan: Test if contents are the same

Reviewers: tomek

Reviewed By: tomek

Subscribers: ashoat

Differential Revision: https://phab.comm.dev/D9914
  • Loading branch information
xsanm committed Nov 20, 2023
1 parent e529864 commit 11d86ef
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/reducers/message-reducer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ describe('SET_MESSAGE_STORE_MESSAGES', () => {
messageStoreThreads: clientDBThreads,
messages: clientDBMessages,
reports: [],
users: {},
},
},
{
Expand Down
14 changes: 14 additions & 0 deletions lib/reducers/user-reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import _isEqual from 'lodash/fp/isEqual.js';
import _keyBy from 'lodash/fp/keyBy.js';

import { setClientDBStoreActionType } from '../actions/client-db-store-actions.js';
import { siweAuthActionTypes } from '../actions/siwe-actions.js';
import {
joinThreadActionTypes,
Expand Down Expand Up @@ -393,6 +394,19 @@ function reduceUserInfos(
}
: state;
return [newState, [], userStoreOps];
} else if (action.type === setClientDBStoreActionType) {
if (!action.payload.users) {
return [state, [], []];
}
// Once the functionality is confirmed to work correctly,
// we will proceed with returning the users from the payload.
assertUserStoresAreEqual(
action.payload.users ?? {},
state.userInfos,
action.type,
onStateDifference,
);
return [state, [], []];
}

return [state, [], []];
Expand Down
3 changes: 2 additions & 1 deletion lib/types/redux-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ import type {
RoleDeletionPayload,
} from './thread-types.js';
import type { ClientUpdatesResultWithUserInfos } from './update-types.js';
import type { CurrentUserInfo, UserStore } from './user-types.js';
import type { CurrentUserInfo, UserInfos, UserStore } from './user-types.js';
import type { SetDeviceTokenActionPayload } from '../actions/device-actions.js';
import type { Shape } from '../types/core.js';
import type { NotifPermissionAlertInfo } from '../utils/push-alerts.js';
Expand Down Expand Up @@ -659,6 +659,7 @@ export type BaseAction =
+threadStore: ?ThreadStore,
+messageStoreThreads: ?$ReadOnlyArray<ClientDBThreadMessageInfo>,
+reports: ?$ReadOnlyArray<ClientReportCreationRequest>,
+users: ?UserInfos,
},
}
| {
Expand Down
13 changes: 11 additions & 2 deletions native/data/sqlite-data-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { setClientDBStoreActionType } from 'lib/actions/client-db-store-actions.
import { MediaCacheContext } from 'lib/components/media-cache-provider.react.js';
import { reportStoreOpsHandlers } from 'lib/ops/report-store-ops.js';
import { threadStoreOpsHandlers } from 'lib/ops/thread-store-ops.js';
import { userStoreOpsHandlers } from 'lib/ops/user-store-ops.js';
import {
cookieSelector,
urlPrefixSelector,
Expand Down Expand Up @@ -168,12 +169,19 @@ function SQLiteDataHandler(): React.Node {
mediaCacheContext?.evictCache(),
]);
try {
const { threads, messages, drafts, messageStoreThreads, reports } =
await commCoreModule.getClientDBStore();
const {
threads,
messages,
drafts,
messageStoreThreads,
reports,
users,
} = await commCoreModule.getClientDBStore();
const threadInfosFromDB =
threadStoreOpsHandlers.translateClientDBData(threads);
const reportsFromDb =
reportStoreOpsHandlers.translateClientDBData(reports);
const usersFromDb = userStoreOpsHandlers.translateClientDBData(users);

dispatch({
type: setClientDBStoreActionType,
Expand All @@ -184,6 +192,7 @@ function SQLiteDataHandler(): React.Node {
currentUserID: currentLoggedInUserID,
messageStoreThreads,
reports: reportsFromDb,
users: usersFromDb,
},
});
} catch (setStoreException) {
Expand Down

0 comments on commit 11d86ef

Please sign in to comment.