Page MenuHomePhabricator

D9030.id30767.diff
No OneTemporary

D9030.id30767.diff

diff --git a/keyserver/src/shared/state-sync/state-sync-spec.js b/keyserver/src/shared/state-sync/state-sync-spec.js
--- a/keyserver/src/shared/state-sync/state-sync-spec.js
+++ b/keyserver/src/shared/state-sync/state-sync-spec.js
@@ -11,5 +11,5 @@
calendarQuery: $ReadOnlyArray<CalendarQuery>,
ids?: $ReadOnlySet<string>,
) => Promise<Infos>,
- ...StateSyncSpec<Info>,
+ ...StateSyncSpec<Infos, Info>,
};
diff --git a/lib/selectors/socket-selectors.js b/lib/selectors/socket-selectors.js
--- a/lib/selectors/socket-selectors.js
+++ b/lib/selectors/socket-selectors.js
@@ -1,23 +1,18 @@
// @flow
import { createSelector } from 'reselect';
-import t from 'tcomb';
import {
updatesCurrentAsOfSelector,
currentAsOfSelector,
} from './keyserver-selectors.js';
import { currentCalendarQuery } from './nav-selectors.js';
-import {
- serverEntryInfo,
- serverEntryInfosObject,
- filterRawEntryInfosByCalendarQuery,
-} from '../shared/entry-utils.js';
+import { serverEntryInfo } from '../shared/entry-utils.js';
+import { stateSyncSpecs } from '../shared/state-sync/state-sync-specs.js';
import threadWatcher from '../shared/thread-watcher.js';
import type { SignedIdentityKeysBlob } from '../types/crypto-types.js';
import {
type RawEntryInfos,
- rawEntryInfoValidator,
type CalendarQuery,
} from '../types/entry-types.js';
import type { AppState } from '../types/redux-types.js';
@@ -29,21 +24,11 @@
} from '../types/request-types.js';
import type { SessionState } from '../types/session-types.js';
import type { OneTimeKeyGenerator } from '../types/socket-types.js';
-import {
- type RawThreadInfos,
- rawThreadInfoValidator,
-} from '../types/thread-types.js';
-import {
- type CurrentUserInfo,
- currentUserInfoValidator,
- type UserInfos,
- userInfosValidator,
-} from '../types/user-types.js';
+import { type RawThreadInfos } from '../types/thread-types.js';
+import { type CurrentUserInfo, type UserInfos } from '../types/user-types.js';
import { getConfig } from '../utils/config.js';
-import { convertClientIDsToServerIDs } from '../utils/conversion-utils.js';
import { minimumOneTimeKeysRequired } from '../utils/crypto-utils.js';
-import { values, hash } from '../utils/objects.js';
-import { tID, ashoatKeyserverID } from '../utils/validation-utils.js';
+import { hash } from '../utils/objects.js';
const queuedReports: (
state: AppState,
@@ -101,34 +86,29 @@
platformDetails: getConfig().platformDetails,
});
} else if (serverRequest.type === serverRequestTypes.CHECK_STATE) {
- const filteredEntryInfos = filterRawEntryInfosByCalendarQuery(
- serverEntryInfosObject(values(entryInfos)),
- calendarQuery(calendarActive),
- );
+ const query = calendarQuery(calendarActive);
- const convertedEntryInfos = convertClientIDsToServerIDs(
- ashoatKeyserverID,
- t.dict(tID, rawEntryInfoValidator),
- filteredEntryInfos,
- );
+ const convertedEntryInfos =
+ stateSyncSpecs.entries.convertClientToServerInfos(
+ entryInfos,
+ query,
+ );
- const convertedThreadInfos = convertClientIDsToServerIDs(
- ashoatKeyserverID,
- t.dict(tID, rawThreadInfoValidator),
- threadInfos,
- );
+ const convertedThreadInfos =
+ stateSyncSpecs.threads.convertClientToServerInfos(
+ threadInfos,
+ query,
+ );
- const convertedUserInfos = convertClientIDsToServerIDs(
- ashoatKeyserverID,
- userInfosValidator,
- userInfos,
- );
+ const convertedUserInfos =
+ stateSyncSpecs.users.convertClientToServerInfos(userInfos, query);
- const convertedCurrentUserInfo = convertClientIDsToServerIDs(
- ashoatKeyserverID,
- t.maybe(currentUserInfoValidator),
- currentUserInfo,
- );
+ const convertedCurrentUserInfo = currentUserInfo
+ ? stateSyncSpecs.currentUser.convertClientToServerInfos(
+ currentUserInfo,
+ query,
+ )
+ : currentUserInfo;
const hashResults = {};
for (const key in serverRequest.hashesToCheck) {
diff --git a/lib/shared/state-sync/current-user-state-sync-spec.js b/lib/shared/state-sync/current-user-state-sync-spec.js
--- a/lib/shared/state-sync/current-user-state-sync-spec.js
+++ b/lib/shared/state-sync/current-user-state-sync-spec.js
@@ -1,7 +1,23 @@
// @flow
import type { StateSyncSpec } from './state-sync-spec.js';
+import {
+ type CurrentUserInfo,
+ type OldCurrentUserInfo,
+ currentUserInfoValidator,
+} from '../../types/user-types.js';
+import { convertClientIDsToServerIDs } from '../../utils/conversion-utils.js';
+import { ashoatKeyserverID } from '../../utils/validation-utils.js';
-export const currentUserStateSyncSpec: StateSyncSpec<> = Object.freeze({
+export const currentUserStateSyncSpec: StateSyncSpec<
+ OldCurrentUserInfo | CurrentUserInfo,
+> = Object.freeze({
hashKey: 'currentUserInfo',
+ convertClientToServerInfos(info: OldCurrentUserInfo | CurrentUserInfo) {
+ return convertClientIDsToServerIDs(
+ ashoatKeyserverID,
+ currentUserInfoValidator,
+ info,
+ );
+ },
});
diff --git a/lib/shared/state-sync/entries-state-sync-spec.js b/lib/shared/state-sync/entries-state-sync-spec.js
--- a/lib/shared/state-sync/entries-state-sync-spec.js
+++ b/lib/shared/state-sync/entries-state-sync-spec.js
@@ -1,12 +1,43 @@
// @flow
+import t from 'tcomb';
+
import type { StateSyncSpec } from './state-sync-spec.js';
+import {
+ type CalendarQuery,
+ type RawEntryInfos,
+ rawEntryInfoValidator,
+} from '../../types/entry-types.js';
+import { convertClientIDsToServerIDs } from '../../utils/conversion-utils.js';
+import { values } from '../../utils/objects.js';
+import { ashoatKeyserverID, tID } from '../../utils/validation-utils.js';
+import {
+ filterRawEntryInfosByCalendarQuery,
+ serverEntryInfosObject,
+} from '../entry-utils.js';
+
+export const entriesStateSyncSpec: StateSyncSpec<RawEntryInfos> = Object.freeze(
+ {
+ hashKey: 'entryInfos',
+ innerHashSpec: {
+ hashKey: 'entryInfo',
+ deleteKey: 'deleteEntryIDs',
+ rawInfosKey: 'rawEntryInfos',
+ },
+ convertClientToServerInfos(
+ infos: RawEntryInfos,
+ calendarQuery: CalendarQuery,
+ ) {
+ const filteredEntryInfos = filterRawEntryInfosByCalendarQuery(
+ serverEntryInfosObject(values(infos)),
+ calendarQuery,
+ );
-export const entriesStateSyncSpec: StateSyncSpec<> = Object.freeze({
- hashKey: 'entryInfos',
- innerHashSpec: {
- hashKey: 'entryInfo',
- deleteKey: 'deleteEntryIDs',
- rawInfosKey: 'rawEntryInfos',
+ return convertClientIDsToServerIDs(
+ ashoatKeyserverID,
+ t.dict(tID, rawEntryInfoValidator),
+ filteredEntryInfos,
+ );
+ },
},
-});
+);
diff --git a/lib/shared/state-sync/state-sync-spec.js b/lib/shared/state-sync/state-sync-spec.js
--- a/lib/shared/state-sync/state-sync-spec.js
+++ b/lib/shared/state-sync/state-sync-spec.js
@@ -1,6 +1,8 @@
// @flow
-export type StateSyncSpec<Info = empty> = {
+import type { CalendarQuery } from '../../types/entry-types.js';
+
+export type StateSyncSpec<Infos, Info = empty> = {
+hashKey: string,
+innerHashSpec?: {
+hashKey: string,
@@ -8,4 +10,8 @@
+rawInfosKey: string,
+additionalDeleteCondition?: Info => boolean,
},
+ +convertClientToServerInfos: (
+ infos: Infos,
+ calendarQuery: CalendarQuery,
+ ) => Infos,
};
diff --git a/lib/shared/state-sync/threads-state-sync-spec.js b/lib/shared/state-sync/threads-state-sync-spec.js
--- a/lib/shared/state-sync/threads-state-sync-spec.js
+++ b/lib/shared/state-sync/threads-state-sync-spec.js
@@ -1,12 +1,28 @@
// @flow
+import t from 'tcomb';
+
import type { StateSyncSpec } from './state-sync-spec.js';
+import {
+ type RawThreadInfos,
+ rawThreadInfoValidator,
+} from '../../types/thread-types.js';
+import { convertClientIDsToServerIDs } from '../../utils/conversion-utils.js';
+import { ashoatKeyserverID, tID } from '../../utils/validation-utils.js';
-export const threadsStateSyncSpec: StateSyncSpec<> = Object.freeze({
- hashKey: 'threadInfos',
- innerHashSpec: {
- hashKey: 'threadInfo',
- deleteKey: 'deleteThreadIDs',
- rawInfosKey: 'rawThreadInfos',
- },
-});
+export const threadsStateSyncSpec: StateSyncSpec<RawThreadInfos> =
+ Object.freeze({
+ hashKey: 'threadInfos',
+ innerHashSpec: {
+ hashKey: 'threadInfo',
+ deleteKey: 'deleteThreadIDs',
+ rawInfosKey: 'rawThreadInfos',
+ },
+ convertClientToServerInfos(infos: RawThreadInfos) {
+ return convertClientIDsToServerIDs(
+ ashoatKeyserverID,
+ t.dict(tID, rawThreadInfoValidator),
+ infos,
+ );
+ },
+ });
diff --git a/lib/shared/state-sync/users-state-sync-spec.js b/lib/shared/state-sync/users-state-sync-spec.js
--- a/lib/shared/state-sync/users-state-sync-spec.js
+++ b/lib/shared/state-sync/users-state-sync-spec.js
@@ -1,16 +1,30 @@
// @flow
import type { StateSyncSpec } from './state-sync-spec.js';
-import type { UserInfo } from '../../types/user-types.js';
+import {
+ type UserInfo,
+ type UserInfos,
+ userInfosValidator,
+} from '../../types/user-types.js';
+import { convertClientIDsToServerIDs } from '../../utils/conversion-utils.js';
+import { ashoatKeyserverID } from '../../utils/validation-utils.js';
-export const usersStateSyncSpec: StateSyncSpec<UserInfo> = Object.freeze({
- hashKey: 'userInfos',
- innerHashSpec: {
- hashKey: 'userInfo',
- deleteKey: 'deleteUserInfoIDs',
- rawInfosKey: 'userInfos',
- additionalDeleteCondition(user: UserInfo) {
- return !user.username;
+export const usersStateSyncSpec: StateSyncSpec<UserInfos, UserInfo> =
+ Object.freeze({
+ hashKey: 'userInfos',
+ innerHashSpec: {
+ hashKey: 'userInfo',
+ deleteKey: 'deleteUserInfoIDs',
+ rawInfosKey: 'userInfos',
+ additionalDeleteCondition(user: UserInfo) {
+ return !user.username;
+ },
},
- },
-});
+ convertClientToServerInfos(infos: UserInfos) {
+ return convertClientIDsToServerIDs(
+ ashoatKeyserverID,
+ userInfosValidator,
+ infos,
+ );
+ },
+ });

File Metadata

Mime Type
text/plain
Expires
Sun, Sep 29, 12:19 PM (21 h, 45 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2196027
Default Alt Text
D9030.id30767.diff (10 KB)

Event Timeline