Page MenuHomePhabricator

D8927.id.diff
No OneTemporary

D8927.id.diff

diff --git a/keyserver/src/shared/state-sync/current-user-state-sync-spec.js b/keyserver/src/shared/state-sync/current-user-state-sync-spec.js
new file mode 100644
--- /dev/null
+++ b/keyserver/src/shared/state-sync/current-user-state-sync-spec.js
@@ -0,0 +1,18 @@
+// @flow
+
+import type {
+ CurrentUserInfo,
+ OldCurrentUserInfo,
+} from 'lib/types/user-types.js';
+
+import type { StateSyncSpec } from './state-sync-spec.js';
+import { fetchCurrentUserInfo } from '../../fetchers/user-fetchers.js';
+import type { Viewer } from '../../session/viewer.js';
+
+export const currentUserStateSyncSpec: StateSyncSpec<
+ OldCurrentUserInfo | CurrentUserInfo,
+> = Object.freeze({
+ fetchAll(viewer: Viewer) {
+ return fetchCurrentUserInfo(viewer);
+ },
+});
diff --git a/keyserver/src/shared/state-sync/entries-state-sync-spec.js b/keyserver/src/shared/state-sync/entries-state-sync-spec.js
new file mode 100644
--- /dev/null
+++ b/keyserver/src/shared/state-sync/entries-state-sync-spec.js
@@ -0,0 +1,17 @@
+// @flow
+
+import { serverEntryInfosObject } from 'lib/shared/entry-utils.js';
+import type { CalendarQuery, RawEntryInfos } from 'lib/types/entry-types.js';
+
+import type { StateSyncSpec } from './state-sync-spec.js';
+import { fetchEntryInfos } from '../../fetchers/entry-fetchers.js';
+import type { Viewer } from '../../session/viewer.js';
+
+export const entriesStateSyncSpec: StateSyncSpec<RawEntryInfos> = Object.freeze(
+ {
+ async fetchAll(viewer: Viewer, query: $ReadOnlyArray<CalendarQuery>) {
+ const entriesResult = await fetchEntryInfos(viewer, query);
+ return serverEntryInfosObject(entriesResult.rawEntryInfos);
+ },
+ },
+);
diff --git a/keyserver/src/shared/state-sync/state-sync-spec.js b/keyserver/src/shared/state-sync/state-sync-spec.js
new file mode 100644
--- /dev/null
+++ b/keyserver/src/shared/state-sync/state-sync-spec.js
@@ -0,0 +1,12 @@
+// @flow
+
+import type { CalendarQuery } from 'lib/types/entry-types.js';
+
+import type { Viewer } from '../../session/viewer.js';
+
+export type StateSyncSpec<Infos> = {
+ +fetchAll: (
+ viewer: Viewer,
+ calendarQuery: $ReadOnlyArray<CalendarQuery>,
+ ) => Promise<Infos>,
+};
diff --git a/keyserver/src/shared/state-sync/state-sync-specs.js b/keyserver/src/shared/state-sync/state-sync-specs.js
new file mode 100644
--- /dev/null
+++ b/keyserver/src/shared/state-sync/state-sync-specs.js
@@ -0,0 +1,16 @@
+// @flow
+
+import { currentUserStateSyncSpec } from './current-user-state-sync-spec.js';
+import { entriesStateSyncSpec } from './entries-state-sync-spec.js';
+import type { StateSyncSpec } from './state-sync-spec.js';
+import { threadsStateSyncSpec } from './threads-state-sync-spec.js';
+import { usersStateSyncSpec } from './users-state-sync-spec.js';
+
+export const serverStateSyncSpecs: {
+ +[string]: StateSyncSpec<*>,
+} = Object.freeze({
+ threads: threadsStateSyncSpec,
+ entries: entriesStateSyncSpec,
+ currentUser: currentUserStateSyncSpec,
+ users: usersStateSyncSpec,
+});
diff --git a/keyserver/src/shared/state-sync/threads-state-sync-spec.js b/keyserver/src/shared/state-sync/threads-state-sync-spec.js
new file mode 100644
--- /dev/null
+++ b/keyserver/src/shared/state-sync/threads-state-sync-spec.js
@@ -0,0 +1,15 @@
+// @flow
+
+import type { StateSyncSpec } from './state-sync-spec.js';
+import {
+ fetchThreadInfos,
+ type FetchThreadInfosResult,
+} from '../../fetchers/thread-fetchers.js';
+import type { Viewer } from '../../session/viewer.js';
+
+export const threadsStateSyncSpec: StateSyncSpec<FetchThreadInfosResult> =
+ Object.freeze({
+ fetchAll(viewer: Viewer) {
+ return fetchThreadInfos(viewer);
+ },
+ });
diff --git a/keyserver/src/shared/state-sync/users-state-sync-spec.js b/keyserver/src/shared/state-sync/users-state-sync-spec.js
new file mode 100644
--- /dev/null
+++ b/keyserver/src/shared/state-sync/users-state-sync-spec.js
@@ -0,0 +1,13 @@
+// @flow
+
+import type { UserInfos } from 'lib/types/user-types.js';
+
+import type { StateSyncSpec } from './state-sync-spec.js';
+import { fetchKnownUserInfos } from '../../fetchers/user-fetchers.js';
+import type { Viewer } from '../../session/viewer.js';
+
+export const usersStateSyncSpec: StateSyncSpec<UserInfos> = Object.freeze({
+ fetchAll(viewer: Viewer) {
+ return fetchKnownUserInfos(viewer);
+ },
+});
diff --git a/keyserver/src/socket/session-utils.js b/keyserver/src/socket/session-utils.js
--- a/keyserver/src/socket/session-utils.js
+++ b/keyserver/src/socket/session-utils.js
@@ -4,10 +4,7 @@
import t from 'tcomb';
import type { TUnion } from 'tcomb';
-import {
- serverEntryInfo,
- serverEntryInfosObject,
-} from 'lib/shared/entry-utils.js';
+import { serverEntryInfo } from 'lib/shared/entry-utils.js';
import type { UpdateActivityResult } from 'lib/types/activity-types.js';
import type { IdentityKeysBlob } from 'lib/types/crypto-types.js';
import { isDeviceType } from 'lib/types/device-types.js';
@@ -65,6 +62,7 @@
setCookieSignedIdentityKeysBlob,
} from '../session/cookies.js';
import type { Viewer } from '../session/viewer.js';
+import { serverStateSyncSpecs } from '../shared/state-sync/state-sync-specs.js';
import { activityUpdater } from '../updaters/activity-updaters.js';
import { compareNewCalendarQuery } from '../updaters/entry-updaters.js';
import type { SessionUpdate } from '../updaters/session-updaters.js';
@@ -392,21 +390,20 @@
status: StateCheckStatus,
calendarQuery: CalendarQuery,
): Promise<StateCheckResult> {
+ const query = [calendarQuery];
if (status.status === 'state_validated') {
return { sessionUpdate: { lastValidated: Date.now() } };
} else if (status.status === 'state_check') {
const promises = {
- threadsResult: fetchThreadInfos(viewer),
- entriesResult: fetchEntryInfos(viewer, [calendarQuery]),
- currentUserInfo: fetchCurrentUserInfo(viewer),
- userInfosResult: fetchKnownUserInfos(viewer),
+ threadsResult: serverStateSyncSpecs.threads.fetchAll(viewer, query),
+ entriesResult: serverStateSyncSpecs.entries.fetchAll(viewer, query),
+ currentUserInfo: serverStateSyncSpecs.currentUser.fetchAll(viewer, query),
+ userInfosResult: serverStateSyncSpecs.users.fetchAll(viewer, query),
};
const fetchedData = await promiseAll(promises);
const hashesToCheck = {
threadInfos: hash(fetchedData.threadsResult.threadInfos),
- entryInfos: hash(
- serverEntryInfosObject(fetchedData.entriesResult.rawEntryInfos),
- ),
+ entryInfos: hash(fetchedData.entriesResult),
currentUserInfo: hash(fetchedData.currentUserInfo),
userInfos: hash(fetchedData.userInfosResult),
};
diff --git a/lib/shared/entry-utils.js b/lib/shared/entry-utils.js
--- a/lib/shared/entry-utils.js
+++ b/lib/shared/entry-utils.js
@@ -12,6 +12,7 @@
RawEntryInfo,
EntryInfo,
CalendarQuery,
+ RawEntryInfos,
} from '../types/entry-types.js';
import { calendarThreadFilterTypes } from '../types/filter-types.js';
import type { UserInfos } from '../types/user-types.js';
@@ -224,9 +225,9 @@
return { ...rest }; // we only do this for Flow
}
-function serverEntryInfosObject(array: $ReadOnlyArray<RawEntryInfo>): {
- +[id: string]: RawEntryInfo,
-} {
+function serverEntryInfosObject(
+ array: $ReadOnlyArray<RawEntryInfo>,
+): RawEntryInfos {
const obj = {};
for (const rawEntryInfo of array) {
const entryInfo = serverEntryInfo(rawEntryInfo);

File Metadata

Mime Type
text/plain
Expires
Mon, Dec 23, 10:44 PM (18 h, 34 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2695851
Default Alt Text
D8927.id.diff (7 KB)

Event Timeline