Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3347760
D9329.id31546.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
12 KB
Referenced Files
None
Subscribers
None
D9329.id31546.diff
View Options
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
@@ -13,5 +13,5 @@
) => Promise<FullSocketSyncPayload>,
+getServerInfosHash: (infos: Infos) => number,
+getServerInfoHash: (info: Info) => number,
- ...StateSyncSpec<Infos, Info>,
+ ...StateSyncSpec<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
@@ -39,12 +39,12 @@
);
const boundStateSyncSpecsSelector: AppState => {
- specsPerHashKey: { +[string]: BoundStateSyncSpec<mixed, mixed> },
- specPerInnerHashKey: { +[string]: BoundStateSyncSpec<mixed, mixed> },
+ specsPerHashKey: { +[string]: BoundStateSyncSpec<mixed> },
+ specPerInnerHashKey: { +[string]: BoundStateSyncSpec<mixed> },
} =
// $FlowFixMe - createSelector only handles finite number of subselectors
createSelector(stateSyncSpecSelectors, (...specs) => {
- const boundSpecs = (specs: BoundStateSyncSpec<mixed, mixed>[]);
+ const boundSpecs = (specs: BoundStateSyncSpec<mixed>[]);
const specsPerHashKey = Object.fromEntries(
boundSpecs.map(spec => [spec.hashKey, spec]),
);
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
@@ -4,33 +4,19 @@
import type { StateSyncSpec } from './state-sync-spec.js';
import type { AppState } from '../../types/redux-types';
-import {
- type CurrentUserInfo,
- currentUserInfoValidator,
-} from '../../types/user-types.js';
-import { convertClientIDsToServerIDs } from '../../utils/conversion-utils.js';
+import { type CurrentUserInfo } from '../../types/user-types.js';
import { hash } from '../../utils/objects.js';
-import { ashoatKeyserverID } from '../../utils/validation-utils.js';
-export const currentUserStateSyncSpec: StateSyncSpec<
- CurrentUserInfo,
- CurrentUserInfo,
-> = Object.freeze({
- hashKey: 'currentUserInfo',
- convertClientToServerInfos(info: CurrentUserInfo) {
- return convertClientIDsToServerIDs(
- ashoatKeyserverID,
- currentUserInfoValidator,
- info,
- );
- },
- selector: createSelector(
- (state: AppState) => state.currentUserInfo,
- currentUserInfo => ({
- ...currentUserStateSyncSpec,
- getInfoHash: () => hash(currentUserInfo),
- getAllInfosHash: () => hash(currentUserInfo),
- getIDs: () => [],
- }),
- ),
-});
+export const currentUserStateSyncSpec: StateSyncSpec<CurrentUserInfo> =
+ Object.freeze({
+ hashKey: 'currentUserInfo',
+ selector: createSelector(
+ (state: AppState) => state.currentUserInfo,
+ currentUserInfo => ({
+ ...currentUserStateSyncSpec,
+ getInfoHash: () => hash(currentUserInfo),
+ getAllInfosHash: () => hash(currentUserInfo),
+ getIDs: () => [],
+ }),
+ ),
+ });
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,58 +1,39 @@
// @flow
import { createSelector } from 'reselect';
-import t from 'tcomb';
import type { StateSyncSpec } from './state-sync-spec.js';
import {
type CalendarQuery,
type RawEntryInfos,
- rawEntryInfoValidator,
type RawEntryInfo,
} from '../../types/entry-types.js';
import type { AppState } from '../../types/redux-types.js';
-import { convertClientIDsToServerIDs } from '../../utils/conversion-utils.js';
import { values, combineUnorderedHashes, hash } from '../../utils/objects.js';
-import { ashoatKeyserverID, tID } from '../../utils/validation-utils.js';
+import { ashoatKeyserverID } from '../../utils/validation-utils.js';
import {
filterRawEntryInfosByCalendarQuery,
serverEntryInfosObject,
} from '../entry-utils.js';
-export const entriesStateSyncSpec: StateSyncSpec<RawEntryInfos, RawEntryInfo> =
- Object.freeze({
- hashKey: 'entryInfos',
- innerHashSpec: {
- hashKey: 'entryInfo',
- deleteKey: 'deleteEntryIDs',
- rawInfosKey: 'rawEntryInfos',
- },
- convertClientToServerInfos(
- infos: RawEntryInfos,
- calendarQuery: CalendarQuery,
- ) {
- const filteredEntryInfos = filterRawEntryInfosByCalendarQuery(
- serverEntryInfosObject(values(infos)),
- calendarQuery,
- );
-
- return convertClientIDsToServerIDs(
- ashoatKeyserverID,
- t.dict(tID, rawEntryInfoValidator),
- filteredEntryInfos,
- );
- },
- selector: createSelector(
- (state: AppState) => state.entryStore.entryInfos,
- entryInfos => ({
- ...entriesStateSyncSpec,
- getInfoHash: id => hash(entryInfos[`${ashoatKeyserverID}|${id}`]),
- getAllInfosHash: calendarQuery =>
- getEntryInfosHash(entryInfos, calendarQuery),
- getIDs: calendarQuery => getEntryIDs(entryInfos, calendarQuery),
- }),
- ),
- });
+export const entriesStateSyncSpec: StateSyncSpec<RawEntryInfo> = Object.freeze({
+ hashKey: 'entryInfos',
+ innerHashSpec: {
+ hashKey: 'entryInfo',
+ deleteKey: 'deleteEntryIDs',
+ rawInfosKey: 'rawEntryInfos',
+ },
+ selector: createSelector(
+ (state: AppState) => state.entryStore.entryInfos,
+ entryInfos => ({
+ ...entriesStateSyncSpec,
+ getInfoHash: id => hash(entryInfos[`${ashoatKeyserverID}|${id}`]),
+ getAllInfosHash: calendarQuery =>
+ getEntryInfosHash(entryInfos, calendarQuery),
+ getIDs: calendarQuery => getEntryIDs(entryInfos, calendarQuery),
+ }),
+ ),
+});
function getEntryInfosHash(
entryInfos: RawEntryInfos,
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
@@ -3,7 +3,7 @@
import type { CalendarQuery } from '../../types/entry-types.js';
import type { AppState } from '../../types/redux-types.js';
-export type StateSyncSpec<Infos, Info> = {
+export type StateSyncSpec<Info> = {
+hashKey: string,
+innerHashSpec?: {
+hashKey: string,
@@ -11,21 +11,17 @@
+rawInfosKey: string,
+additionalDeleteCondition?: Info => boolean,
},
- +convertClientToServerInfos: (
- infos: Infos,
- calendarQuery: CalendarQuery,
- ) => Infos,
- +selector: (state: AppState) => BoundStateSyncSpec<Infos, Info>,
+ +selector: (state: AppState) => BoundStateSyncSpec<Info>,
};
// All ids specified here (getInfoHash and getIDs) are server ids.
// E.g. in the case of threadStore or entryStore the keyserver prefix
// needs to be handled additionaly
-export type BoundStateSyncSpec<Infos, Info> = {
+export type BoundStateSyncSpec<Info> = {
// If these function depend on background hashing that is still not complete
// they should return null, to indicate that the hashes aren't available yet
+getInfoHash: (id: string) => ?number,
+getAllInfosHash: (query: CalendarQuery) => ?number,
+getIDs: (query: CalendarQuery) => ?Array<string>,
- ...StateSyncSpec<Infos, Info>,
+ ...StateSyncSpec<Info>,
};
diff --git a/lib/shared/state-sync/state-sync-specs.js b/lib/shared/state-sync/state-sync-specs.js
--- a/lib/shared/state-sync/state-sync-specs.js
+++ b/lib/shared/state-sync/state-sync-specs.js
@@ -14,5 +14,5 @@
});
(stateSyncSpecs: {
- +[string]: StateSyncSpec<any, any>,
+ +[string]: StateSyncSpec<any>,
});
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,48 +1,34 @@
// @flow
import { createSelector } from 'reselect';
-import t from 'tcomb';
import type { StateSyncSpec } from './state-sync-spec.js';
import type { AppState } from '../../types/redux-types.js';
-import {
- type RawThreadInfos,
- type RawThreadInfo,
- rawThreadInfoValidator,
-} from '../../types/thread-types.js';
-import { convertClientIDsToServerIDs } from '../../utils/conversion-utils.js';
+import { type RawThreadInfo } from '../../types/thread-types.js';
import { combineUnorderedHashes, values } from '../../utils/objects.js';
-import { ashoatKeyserverID, tID } from '../../utils/validation-utils.js';
+import { ashoatKeyserverID } from '../../utils/validation-utils.js';
-export const threadsStateSyncSpec: StateSyncSpec<
- RawThreadInfos,
- RawThreadInfo,
-> = Object.freeze({
- hashKey: 'threadInfos',
- innerHashSpec: {
- hashKey: 'threadInfo',
- deleteKey: 'deleteThreadIDs',
- rawInfosKey: 'rawThreadInfos',
+export const threadsStateSyncSpec: StateSyncSpec<RawThreadInfo> = Object.freeze(
+ {
+ hashKey: 'threadInfos',
+ innerHashSpec: {
+ hashKey: 'threadInfo',
+ deleteKey: 'deleteThreadIDs',
+ rawInfosKey: 'rawThreadInfos',
+ },
+ selector: createSelector(
+ (state: AppState) => state.integrityStore.threadHashes,
+ (state: AppState) => state.integrityStore.threadHashingComplete,
+ (threadHashes, threadHashingComplete) => ({
+ ...threadsStateSyncSpec,
+ getInfoHash: id => threadHashes[`${ashoatKeyserverID}|${id}`],
+ getAllInfosHash: threadHashingComplete
+ ? () => combineUnorderedHashes(values(threadHashes))
+ : () => null,
+ getIDs: threadHashingComplete
+ ? () => Object.keys(threadHashes).map(id => id.split('|')[1])
+ : () => null,
+ }),
+ ),
},
- convertClientToServerInfos(infos: RawThreadInfos) {
- return convertClientIDsToServerIDs(
- ashoatKeyserverID,
- t.dict(tID, rawThreadInfoValidator),
- infos,
- );
- },
- selector: createSelector(
- (state: AppState) => state.integrityStore.threadHashes,
- (state: AppState) => state.integrityStore.threadHashingComplete,
- (threadHashes, threadHashingComplete) => ({
- ...threadsStateSyncSpec,
- getInfoHash: id => threadHashes[`${ashoatKeyserverID}|${id}`],
- getAllInfosHash: threadHashingComplete
- ? () => combineUnorderedHashes(values(threadHashes))
- : () => null,
- getIDs: threadHashingComplete
- ? () => Object.keys(threadHashes).map(id => id.split('|')[1])
- : () => null,
- }),
- ),
-});
+);
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
@@ -4,41 +4,27 @@
import type { StateSyncSpec } from './state-sync-spec.js';
import type { AppState } from '../../types/redux-types';
-import {
- type UserInfo,
- type UserInfos,
- userInfosValidator,
-} from '../../types/user-types.js';
-import { convertClientIDsToServerIDs } from '../../utils/conversion-utils.js';
+import { type UserInfo } from '../../types/user-types.js';
import { combineUnorderedHashes, hash } from '../../utils/objects.js';
-import { ashoatKeyserverID } from '../../utils/validation-utils.js';
-export const usersStateSyncSpec: StateSyncSpec<UserInfos, UserInfo> =
- Object.freeze({
- hashKey: 'userInfos',
- innerHashSpec: {
- hashKey: 'userInfo',
- deleteKey: 'deleteUserInfoIDs',
- rawInfosKey: 'userInfos',
- additionalDeleteCondition(user: UserInfo) {
- return !user.username;
- },
+export const usersStateSyncSpec: StateSyncSpec<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,
- );
- },
- selector: createSelector(
- (state: AppState) => state.userStore.userInfos,
- userInfos => ({
- ...usersStateSyncSpec,
- getInfoHash: id => hash(userInfos[id]),
- getAllInfosHash: () =>
- combineUnorderedHashes(Object.values(userInfos).map(hash)),
- getIDs: () => Object.keys(userInfos),
- }),
- ),
- });
+ },
+ selector: createSelector(
+ (state: AppState) => state.userStore.userInfos,
+ userInfos => ({
+ ...usersStateSyncSpec,
+ getInfoHash: id => hash(userInfos[id]),
+ getAllInfosHash: () =>
+ combineUnorderedHashes(Object.values(userInfos).map(hash)),
+ getIDs: () => Object.keys(userInfos),
+ }),
+ ),
+});
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 23, 1:12 PM (19 h, 16 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2570761
Default Alt Text
D9329.id31546.diff (12 KB)
Attached To
Mode
D9329: [lib] Remove convertClientToServerInfos from spec
Attached
Detach File
Event Timeline
Log In to Comment