Skip to content

Commit

Permalink
[lib] Enable new id schema
Browse files Browse the repository at this point in the history
Summary:
Bump state versions, and replace FUTURE_CODE_VERSION. Also remove the flag blocking the conversions, because after migrations had run, the code on the clients should run unconditionally, and the keyserver changes are version gated anyway, so this flag is not needed.

Depends on D8383, D8385

Test Plan: N/A

Reviewers: kamil, tomek

Reviewed By: kamil

Subscribers: ashoat

Differential Revision: https://phab.comm.dev/D8386
  • Loading branch information
MichalGniadek committed Jul 13, 2023
1 parent 55ab3e7 commit 98ea283
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 66 deletions.
21 changes: 9 additions & 12 deletions keyserver/src/utils/validation-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { TType } from 'tcomb';
import type { PolicyType } from 'lib/facts/policies.js';
import {
hasMinCodeVersion,
FUTURE_CODE_VERSION,
hasMinStateVersion,
} from 'lib/shared/version-utils.js';
import { type PlatformDetails } from 'lib/types/device-types.js';
import { ServerError } from 'lib/utils/errors.js';
Expand All @@ -15,7 +15,6 @@ import {
tPlatform,
tPlatformDetails,
assertWithValidator,
convertToNewIDSchema,
keyserverPrefixID,
convertClientIDsToServerIDs,
convertObject,
Expand All @@ -37,11 +36,10 @@ async function validateInput<T>(
const convertedInput = checkInputValidator(inputValidator, input);

if (
hasMinCodeVersion(viewer.platformDetails, {
native: FUTURE_CODE_VERSION,
web: FUTURE_CODE_VERSION,
}) &&
convertToNewIDSchema
hasMinStateVersion(viewer.platformDetails, {
native: 43,
web: 3,
})
) {
try {
return convertClientIDsToServerIDs(
Expand Down Expand Up @@ -72,12 +70,11 @@ function validateOutput<T>(
}

if (
(hasMinCodeVersion(platformDetails, {
native: FUTURE_CODE_VERSION,
web: FUTURE_CODE_VERSION,
hasMinStateVersion(platformDetails, {
native: 43,
web: 3,
}) ||
alwaysConvertSchema) &&
convertToNewIDSchema
alwaysConvertSchema
) {
return convertServerIDsToClientIDs(
keyserverPrefixID,
Expand Down
32 changes: 7 additions & 25 deletions lib/_generated/migration-utils.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
// @flow

import type { EntryStore } from '../types/entry-types.js';
import type { CalendarFilter } from '../types/filter-types.js';
import type { InviteLinksStore } from '../types/link-types.js';
import type { MessageStore, RawMessageInfo } from '../types/message-types.js';
import type { ConnectionInfo } from '../types/socket-types.js';
import type { RawThreadInfo } from '../types/thread-types.js';
import { entries } from '../utils/objects.js';

export function convertRawMessageInfoToNewIDSchema(
input: RawMessageInfo,
): RawMessageInfo {
export function convertRawMessageInfoToNewIDSchema(input: any): any {
return input.type === 0
? {
...input,
Expand Down Expand Up @@ -366,9 +358,7 @@ export function convertRawMessageInfoToNewIDSchema(
: input;
}
export function convertRawThreadInfoToNewIDSchema(
input: RawThreadInfo,
): RawThreadInfo {
export function convertRawThreadInfoToNewIDSchema(input: any): any {
return {
...input,
id: '256|' + input.id,
Expand Down Expand Up @@ -428,9 +418,7 @@ export function convertRawThreadInfoToNewIDSchema(
};
}
export function convertMessageStoreToNewIDSchema(
input: MessageStore,
): MessageStore {
export function convertMessageStoreToNewIDSchema(input: any): any {
return {
...input,
messages: Object.fromEntries(
Expand Down Expand Up @@ -832,7 +820,7 @@ export function convertMessageStoreToNewIDSchema(
};
}
export function convertEntryStoreToNewIDSchema(input: EntryStore): EntryStore {
export function convertEntryStoreToNewIDSchema(input: any): any {
return {
...input,
entryInfos: Object.fromEntries(
Expand All @@ -857,9 +845,7 @@ export function convertEntryStoreToNewIDSchema(input: EntryStore): EntryStore {
};
}
export function convertInviteLinksStoreToNewIDSchema(
input: InviteLinksStore,
): InviteLinksStore {
export function convertInviteLinksStoreToNewIDSchema(input: any): any {
return {
...input,
links: Object.fromEntries(
Expand All @@ -881,17 +867,13 @@ export function convertInviteLinksStoreToNewIDSchema(
};
}
export function convertCalendarFilterToNewIDSchema(
input: CalendarFilter,
): CalendarFilter {
export function convertCalendarFilterToNewIDSchema(input: any): any {
return input.type === 'threads'
? { ...input, threadIDs: input.threadIDs.map(elem => '256|' + elem) }
: input;
}

export function convertConnectionInfoToNewIDSchema(
input: ConnectionInfo,
): ConnectionInfo {
export function convertConnectionInfoToNewIDSchema(input: any): any {
return {
...input,
queuedActivityUpdates: input.queuedActivityUpdates.map(elem => ({
Expand Down
45 changes: 20 additions & 25 deletions lib/selectors/socket-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import {
tID,
convertClientIDsToServerIDs,
keyserverPrefixID,
convertToNewIDSchema,
} from '../utils/validation-utils.js';

const queuedReports: (
Expand Down Expand Up @@ -75,23 +74,21 @@ const getClientResponsesSelector: (
currentUserInfo: ?CurrentUserInfo,
calendarQuery: (calendarActive: boolean) => CalendarQuery,
) => {
if (convertToNewIDSchema) {
threadInfos = convertClientIDsToServerIDs(
keyserverPrefixID,
t.dict(tID, rawThreadInfoValidator),
threadInfos,
);
userInfos = convertClientIDsToServerIDs(
keyserverPrefixID,
userInfosValidator,
userInfos,
);
currentUserInfo = convertClientIDsToServerIDs(
keyserverPrefixID,
t.maybe(currentUserInfoValidator),
currentUserInfo,
);
}
threadInfos = convertClientIDsToServerIDs(
keyserverPrefixID,
t.dict(tID, rawThreadInfoValidator),
threadInfos,
);
userInfos = convertClientIDsToServerIDs(
keyserverPrefixID,
userInfosValidator,
userInfos,
);
currentUserInfo = convertClientIDsToServerIDs(
keyserverPrefixID,
t.maybe(currentUserInfoValidator),
currentUserInfo,
);

return async (
calendarActive: boolean,
Expand Down Expand Up @@ -124,13 +121,11 @@ const getClientResponsesSelector: (
calendarQuery(calendarActive),
);

if (convertToNewIDSchema) {
filteredEntryInfos = convertClientIDsToServerIDs(
keyserverPrefixID,
t.dict(tID, rawEntryInfoValidator),
filteredEntryInfos,
);
}
filteredEntryInfos = convertClientIDsToServerIDs(
keyserverPrefixID,
t.dict(tID, rawEntryInfoValidator),
filteredEntryInfos,
);

const hashResults = {};
for (const key in serverRequest.hashesToCheck) {
Expand Down
2 changes: 0 additions & 2 deletions lib/utils/validation-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ function assertWithValidator<T>(data: mixed, validator: TType<T>): T {
return (data: any);
}

const convertToNewIDSchema = false;
const keyserverPrefixID = '256';

function convertServerIDsToClientIDs<T>(
Expand Down Expand Up @@ -242,7 +241,6 @@ export {
tMediaMessageVideo,
tMediaMessageMedia,
assertWithValidator,
convertToNewIDSchema,
keyserverPrefixID,
convertClientIDsToServerIDs,
convertServerIDsToClientIDs,
Expand Down
2 changes: 1 addition & 1 deletion native/redux/persist.js
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ const persistConfig = {
'storeLoaded',
],
debug: __DEV__,
version: 42,
version: 43,
transforms: [messageStoreMessagesBlocklistTransform, reportStoreTransform],
migrate: (createAsyncMigrate(migrations, { debug: __DEV__ }): any),
timeout: ((__DEV__ ? 0 : undefined): number | void),
Expand Down
2 changes: 1 addition & 1 deletion web/redux/persist.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ const persistConfig: PersistConfig = {
{ debug: isDev },
migrateStorageToSQLite,
): any),
version: 2,
version: 3,
};

export { persistConfig };

0 comments on commit 98ea283

Please sign in to comment.