From caa02446c74113e47af4c31baad33706304ba991 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90?= Date: Tue, 10 Jan 2023 14:10:20 +0800 Subject: [PATCH] refactor: upgrade masto --- components/status/StatusCard.vue | 6 ++--- components/status/StatusContent.vue | 4 +--- composables/paginator.ts | 10 ++++----- composables/users.ts | 2 +- package.json | 2 +- pnpm-lock.yaml | 35 ++++++++++++++++++++--------- 6 files changed, 34 insertions(+), 25 deletions(-) diff --git a/components/status/StatusCard.vue b/components/status/StatusCard.vue index 3831e8d0..9875e3ff 100644 --- a/components/status/StatusCard.vue +++ b/components/status/StatusCard.vue @@ -67,11 +67,9 @@ const timeago = useTimeAgo(() => status.createdAt, timeAgoOptions) // Content Filter logic const filterResult = $computed(() => status.filtered?.length ? status.filtered[0] : null) -const filter = $computed(() => filterResult?.filter as mastodon.v2.Filter) +const filter = $computed(() => filterResult?.filter) -// a bit of a hack due to Filter being different in v1 and v2 -// clean up when masto.js supports explicit versions: https://github.com/neet/masto.js/issues/722 -const filterPhrase = $computed(() => filter?.phrase || (filter as any)?.title) +const filterPhrase = $computed(() => filter?.title) const isFiltered = $computed(() => filterPhrase && (props.context ? filter?.context.includes(props.context) : false)) const isSelfReply = $computed(() => status.inReplyToAccountId === status.account.id) diff --git a/components/status/StatusContent.vue b/components/status/StatusContent.vue index 50120c03..b2851bd8 100644 --- a/components/status/StatusContent.vue +++ b/components/status/StatusContent.vue @@ -13,9 +13,7 @@ const isDetails = $computed(() => context === 'details') const filterResult = $computed(() => status.filtered?.length ? status.filtered[0] : null) const filter = $computed(() => filterResult?.filter) -// a bit of a hack due to Filter being different in v1 and v2 -// clean up when masto.js supports explicit versions: https://github.com/neet/masto.js/issues/722 -const filterPhrase = $computed(() => filter?.phrase || (filter as any)?.title) +const filterPhrase = $computed(() => filter?.title) const isFiltered = $computed(() => filterPhrase && (context && context !== 'details' ? filter?.context.includes(context) : false)) diff --git a/composables/paginator.ts b/composables/paginator.ts index 5c4300a0..6fc2de5b 100644 --- a/composables/paginator.ts +++ b/composables/paginator.ts @@ -1,5 +1,4 @@ -import { Paginator } from 'masto' -import type { WsEvents, mastodon } from 'masto' +import type { Paginator, WsEvents, mastodon } from 'masto' import type { PaginatorState } from '~/types' export function usePaginator( @@ -9,11 +8,10 @@ export function usePaginator( preprocess: (items: (T | U)[]) => U[] = items => items as unknown as U[], buffer = 10, ) { - // TODO: wait PR https://github.com/neet/masto.js/pull/801 - // called `next` method will mutate the internal state of the variable, and we need its initial state after HMR + // called `next` method will mutate the internal state of the variable, + // and we need its initial state after HMR // so clone it - // @ts-expect-error clone it - const paginator: Paginator = new Paginator(_paginator.http, _paginator.nextPath, _paginator.nextParams) + const paginator = _paginator.clone() const state = ref(isMastoInitialised.value ? 'idle' : 'loading') const items = ref([]) diff --git a/composables/users.ts b/composables/users.ts index f9232206..a772ee8a 100644 --- a/composables/users.ts +++ b/composables/users.ts @@ -267,7 +267,7 @@ export const useNotifications = () => { return const lastReadId = notifications[id]![1][0] notifications[id]![1] = [] - // @ts-expect-error https://github.com/neet/masto.js/pull/793 + await masto.v1.markers.create({ notifications: { lastReadId }, }) diff --git a/package.json b/package.json index 60db2eb2..4af47fd7 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "iso-639-1": "^2.1.15", "js-yaml": "^4.1.0", "lru-cache": "^7.14.1", - "masto": "^5.1.2", + "masto": "^5.2.0", "pinia": "^2.0.28", "shiki": "^0.12.1", "shiki-es": "^0.1.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 273c23fc..33289aed 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -69,7 +69,7 @@ importers: jsdom: ^20.0.3 lint-staged: ^13.1.0 lru-cache: ^7.14.1 - masto: ^5.1.2 + masto: ^5.2.0 nuxt: ^3.0.0 pinia: ^2.0.28 postcss-nested: ^6.0.0 @@ -124,7 +124,7 @@ importers: iso-639-1: 2.1.15 js-yaml: 4.1.0 lru-cache: 7.14.1 - masto: 5.1.2 + masto: 5.2.0 pinia: 2.0.28_typescript@4.9.4 shiki: 0.12.1 shiki-es: 0.1.2 @@ -180,7 +180,7 @@ importers: typescript: 4.9.4 unplugin-auto-import: 0.12.1_@vueuse+core@9.10.0 vite-plugin-inspect: 0.7.11 - vite-plugin-pwa: 0.14.1 + vite-plugin-pwa: 0.14.1_workbox-window@6.5.4 vitest: 0.26.2_jsdom@20.0.3 vue-tsc: 1.0.24_typescript@4.9.4 workbox-window: 6.5.4 @@ -7483,12 +7483,12 @@ packages: engines: {node: '>=6.0'} dev: false - /isomorphic-ws/5.0.0_ws@8.11.0: + /isomorphic-ws/5.0.0_ws@8.12.0: resolution: {integrity: sha512-muId7Zzn9ywDsyXgTIafTry2sV3nySZeUDe6YedVd1Hvuuep5AsIlqK+XefWpYTyJG5e503F2xIuT2lcU6rCSw==} peerDependencies: ws: '*' dependencies: - ws: 8.11.0 + ws: 8.12.0 dev: false /jake/10.8.5: @@ -7944,15 +7944,15 @@ packages: resolution: {integrity: sha512-Z1NL3Tb1M9wH4XESsCDEksWoKTdlUafKc4pt0GRwjUyXaCFZ+dc3g2erqB6zm3szA2IUSi7VnPI+o/9jnxh9hw==} dev: true - /masto/5.1.2: - resolution: {integrity: sha512-nLhX0aHdb4ql4o2Afd81hm6dq/V6FZylEKed6VF099ZB0ZqkOZ54m+7yy1eSgPljmwrZbUgli5kXQ7nfloBkyg==} + /masto/5.2.0: + resolution: {integrity: sha512-71pKUdPZDuQSPJqRJSwsZ/QqvO/arOkdRyXEyOdeU9QukQ30OEW1M9BCGBp/b9Lbf6R7d9oCCdefmxXCSAzlFg==} dependencies: '@mastojs/ponyfills': 1.0.4 change-case: 4.1.2 eventemitter3: 5.0.0 - isomorphic-ws: 5.0.0_ws@8.11.0 + isomorphic-ws: 5.0.0_ws@8.12.0 semver: 7.3.8 - ws: 8.11.0 + ws: 8.12.0 transitivePeerDependencies: - bufferutil - encoding @@ -11822,10 +11822,11 @@ packages: - supports-color dev: true - /vite-plugin-pwa/0.14.1: + /vite-plugin-pwa/0.14.1_workbox-window@6.5.4: resolution: {integrity: sha512-5zx7yhQ8RTLwV71+GA9YsQQ63ALKG8XXIMqRJDdZkR8ZYftFcRgnzM7wOWmQZ/DATspyhPih5wCdcZnAIsM+mA==} peerDependencies: vite: ^3.1.0 || ^4.0.0 + workbox-window: ^6.5.4 dependencies: '@rollup/plugin-replace': 5.0.1_rollup@3.9.1 debug: 4.3.4 @@ -12472,6 +12473,20 @@ packages: optional: true utf-8-validate: optional: true + dev: true + + /ws/8.12.0: + resolution: {integrity: sha512-kU62emKIdKVeEIOIKVegvqpXMSTAMLJozpHZaJNDYqBjzlSYXQGviYwN1osDLJ9av68qHd4a2oSjd7yD4pacig==} + engines: {node: '>=10.0.0'} + peerDependencies: + bufferutil: ^4.0.1 + utf-8-validate: '>=5.0.2' + peerDependenciesMeta: + bufferutil: + optional: true + utf-8-validate: + optional: true + dev: false /ws/8.2.3: resolution: {integrity: sha512-wBuoj1BDpC6ZQ1B7DWQBYVLphPWkm8i9Y0/3YdHjHKHiohOJ1ws+3OccDWtH+PoC9DZD5WOTrJvNbWvjS6JWaA==}