From bceb70e805bbb4904f5cf457e3fe06c2e02da63c Mon Sep 17 00:00:00 2001 From: Zhiyuan Zheng Date: Thu, 28 Apr 2022 22:52:47 +0200 Subject: [PATCH] Bump to v4 Preparing for adding support to v3.5 and above --- package.json | 8 +- src/@types/mastodon.d.ts | 2 - src/store.ts | 2 +- src/utils/migrations/instances/migration.ts | 12 +++ src/utils/migrations/instances/v9.ts | 79 ++++++++++++++++++ src/utils/slices/instances/add.ts | 4 +- src/utils/slices/instancesSlice.ts | 92 +++------------------ yarn.lock | 8 +- 8 files changed, 111 insertions(+), 96 deletions(-) create mode 100644 src/utils/migrations/instances/v9.ts diff --git a/package.json b/package.json index a0ea509c..cc04d4c6 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { "name": "tooot", "versions": { - "native": "220328", - "major": 3, - "minor": 6, + "native": "220428", + "major": 4, + "minor": 0, "patch": 0, "expo": "44.0.0" }, @@ -62,7 +62,7 @@ "expo-updates": "0.11.6", "expo-video-thumbnails": "6.2.0", "expo-web-browser": "10.1.1", - "i18next": "21.6.14", + "i18next": "21.6.16", "li": "1.3.0", "lodash": "4.17.21", "react": "17.0.2", diff --git a/src/@types/mastodon.d.ts b/src/@types/mastodon.d.ts index de1742b7..6e7d2805 100644 --- a/src/@types/mastodon.d.ts +++ b/src/@types/mastodon.d.ts @@ -320,8 +320,6 @@ declare namespace Mastodon { max_expiration: number } } - // Custom - to be deprecated in v4 - max_toot_chars?: number } type Mention = { diff --git a/src/store.ts b/src/store.ts index 4df61af2..5e4e8afc 100644 --- a/src/store.ts +++ b/src/store.ts @@ -27,7 +27,7 @@ const instancesPersistConfig = { key: 'instances', prefix, storage: secureStorage, - version: 8, + version: 9, // @ts-ignore migrate: createMigrate(instancesMigration) } diff --git a/src/utils/migrations/instances/migration.ts b/src/utils/migrations/instances/migration.ts index f45abb0a..f7079c88 100644 --- a/src/utils/migrations/instances/migration.ts +++ b/src/utils/migrations/instances/migration.ts @@ -4,6 +4,7 @@ import { InstanceV5 } from './v5' import { InstanceV6 } from './v6' import { InstanceV7 } from './v7' import { InstanceV8 } from './v8' +import { InstanceV9 } from './v9' const instancesMigration = { 4: (state: InstanceV3): InstanceV4 => { @@ -87,6 +88,17 @@ const instancesMigration = { } }) } + }, + 9: (state: InstanceV8): { instances: InstanceV9[] } => { + return { + // @ts-ignore + instances: state.instances.map(instance => { + return { + ...instance, + version: '0' + } + }) + } } } diff --git a/src/utils/migrations/instances/v9.ts b/src/utils/migrations/instances/v9.ts new file mode 100644 index 00000000..2e2d47b5 --- /dev/null +++ b/src/utils/migrations/instances/v9.ts @@ -0,0 +1,79 @@ +import { ComposeStateDraft } from '@screens/Compose/utils/types' +import { QueryKeyTimeline } from '@utils/queryHooks/timeline' + +export type InstanceV9 = { + active: boolean + appData: { + clientId: string + clientSecret: string + } + url: string + token: string + uri: Mastodon.Instance['uri'] + urls: Mastodon.Instance['urls'] + account: { + id: Mastodon.Account['id'] + acct: Mastodon.Account['acct'] + avatarStatic: Mastodon.Account['avatar_static'] + preferences: Mastodon.Preferences + } + version: string + configuration?: Mastodon.Instance['configuration'] + filters: Mastodon.Filter[] + notifications_filter: { + follow: boolean + favourite: boolean + reblog: boolean + mention: boolean + poll: boolean + follow_request: boolean + } + push: { + global: { loading: boolean; value: boolean } + decode: { loading: boolean; value: boolean } + alerts: { + follow: { + loading: boolean + value: Mastodon.PushSubscription['alerts']['follow'] + } + favourite: { + loading: boolean + value: Mastodon.PushSubscription['alerts']['favourite'] + } + reblog: { + loading: boolean + value: Mastodon.PushSubscription['alerts']['reblog'] + } + mention: { + loading: boolean + value: Mastodon.PushSubscription['alerts']['mention'] + } + poll: { + loading: boolean + value: Mastodon.PushSubscription['alerts']['poll'] + } + } + keys: { + auth?: string + public?: string // legacy + private?: string // legacy + } + } + timelinesLookback?: { + [key: string]: { + queryKey: QueryKeyTimeline + ids: Mastodon.Status['id'][] + } + } + mePage: { + lists: { shown: boolean } + announcements: { shown: boolean; unread: number } + } + drafts: ComposeStateDraft[] + frequentEmojis: { + emoji: Pick + score: number + count: number + lastUsed: number + }[] +} diff --git a/src/utils/slices/instances/add.ts b/src/utils/slices/instances/add.ts index 470cfc13..5b5b95e0 100644 --- a/src/utils/slices/instances/add.ts +++ b/src/utils/slices/instances/add.ts @@ -74,9 +74,7 @@ const addInstance = createAsyncThunk( avatarStatic: avatar_static, preferences }, - ...(instance.max_toot_chars && { - max_toot_chars: instance.max_toot_chars - }), + version: instance.version, ...(instance.configuration && { configuration: instance.configuration }), diff --git a/src/utils/slices/instancesSlice.ts b/src/utils/slices/instancesSlice.ts index b6b553cb..1b5eb961 100644 --- a/src/utils/slices/instancesSlice.ts +++ b/src/utils/slices/instancesSlice.ts @@ -2,7 +2,7 @@ import analytics from '@components/analytics' import { createSlice, PayloadAction } from '@reduxjs/toolkit' import { RootState } from '@root/store' import { ComposeStateDraft } from '@screens/Compose/utils/types' -import { QueryKeyTimeline } from '@utils/queryHooks/timeline' +import { InstanceV9 } from '@utils/migrations/instances/v9' import addInstance from './instances/add' import { checkEmojis } from './instances/checkEmojis' import removeInstance from './instances/remove' @@ -13,82 +13,7 @@ import { updateInstancePush } from './instances/updatePush' import { updateInstancePushAlert } from './instances/updatePushAlert' import { updateInstancePushDecode } from './instances/updatePushDecode' -export type Instance = { - active: boolean - appData: { - clientId: string - clientSecret: string - } - url: string - token: string - uri: Mastodon.Instance['uri'] - urls: Mastodon.Instance['urls'] - account: { - id: Mastodon.Account['id'] - acct: Mastodon.Account['acct'] - avatarStatic: Mastodon.Account['avatar_static'] - preferences: Mastodon.Preferences - } - max_toot_chars?: number // To be deprecated in v4 - configuration?: Mastodon.Instance['configuration'] - filters: Mastodon.Filter[] - notifications_filter: { - follow: boolean - favourite: boolean - reblog: boolean - mention: boolean - poll: boolean - follow_request: boolean - } - push: { - global: { loading: boolean; value: boolean } - decode: { loading: boolean; value: boolean } - alerts: { - follow: { - loading: boolean - value: Mastodon.PushSubscription['alerts']['follow'] - } - favourite: { - loading: boolean - value: Mastodon.PushSubscription['alerts']['favourite'] - } - reblog: { - loading: boolean - value: Mastodon.PushSubscription['alerts']['reblog'] - } - mention: { - loading: boolean - value: Mastodon.PushSubscription['alerts']['mention'] - } - poll: { - loading: boolean - value: Mastodon.PushSubscription['alerts']['poll'] - } - } - keys: { - auth?: string - public?: string // legacy - private?: string // legacy - } - } - timelinesLookback?: { - [key: string]: { - queryKey: QueryKeyTimeline - ids: Mastodon.Status['id'][] - } - } - mePage: { - lists: { shown: boolean } - announcements: { shown: boolean; unread: number } - } - drafts: ComposeStateDraft[] - frequentEmojis: { - emoji: Pick - score: number - count: number - lastUsed: number - }[] -} +export type Instance = InstanceV9 export type InstancesState = { instances: Instance[] @@ -318,8 +243,7 @@ const instancesSlice = createSlice({ // Update Instance Configuration .addCase(updateConfiguration.fulfilled, (state, action) => { const activeIndex = findInstanceActive(state.instances) - state.instances[activeIndex].max_toot_chars = - action.payload.max_toot_chars + state.instances[activeIndex].version = action.payload.version state.instances[activeIndex].configuration = action.payload.configuration }) @@ -415,14 +339,18 @@ export const getInstanceUri = ({ instances: { instances } }: RootState) => export const getInstanceUrls = ({ instances: { instances } }: RootState) => instances[findInstanceActive(instances)]?.urls +export const getInstanceVersion = ({ instances: { instances } }: RootState) => + instances[findInstanceActive(instances)]?.version +export const getInstanceVersionInFloat = ({ + instances: { instances } +}: RootState) => parseFloat(instances[findInstanceActive(instances)]?.version) + /* Get Instance Configuration */ export const getInstanceConfigurationStatusMaxChars = ({ instances: { instances } }: RootState) => instances[findInstanceActive(instances)]?.configuration?.statuses - .max_characters || - instances[findInstanceActive(instances)]?.max_toot_chars || - 500 + .max_characters || 500 export const getInstanceConfigurationStatusMaxAttachments = ({ instances: { instances } diff --git a/yarn.lock b/yarn.lock index b9f6fc60..7ee519e3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4304,10 +4304,10 @@ https-proxy-agent@^5.0.0: agent-base "6" debug "4" -i18next@21.6.14: - version "21.6.14" - resolved "https://registry.yarnpkg.com/i18next/-/i18next-21.6.14.tgz#2bc199fba7f4da44b5952d7df0a3814a6e5c3943" - integrity sha512-XL6WyD+xlwQwbieXRlXhKWoLb/rkch50/rA+vl6untHnJ+aYnkQ0YDZciTWE78PPhOpbi2gR0LTJCJpiAhA+uQ== +i18next@21.6.16: + version "21.6.16" + resolved "https://registry.yarnpkg.com/i18next/-/i18next-21.6.16.tgz#8cff8c3ba2ffaf8438a8c83fe284083f15cf3941" + integrity sha512-xJlzrVxG9CyAGsbMP1aKuiNr1Ed2m36KiTB7hjGMG2Zo4idfw3p9THUEu+GjBwIgEZ7F11ZbCzJcfv4uyfKNuw== dependencies: "@babel/runtime" "^7.17.2"