From 4422a57f491fa2ee53ca303b9e693127caec83a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90=20Kevin=20Deng?= Date: Sun, 15 Jan 2023 16:38:02 +0800 Subject: [PATCH] refactor: sync masto (#1121) --- components/account/AccountFollowButton.vue | 8 +- components/account/AccountHeader.vue | 4 +- components/account/AccountMoreButton.vue | 12 +- components/common/CommonPaginator.vue | 2 +- components/main/MainContent.vue | 2 +- components/modal/ModalContainer.vue | 2 +- components/nav/NavBottom.vue | 4 +- components/nav/NavSide.vue | 6 +- components/nav/NavSideItem.vue | 6 +- components/nav/NavUser.vue | 2 +- components/publish/PublishButton.vue | 4 +- components/publish/PublishWidget.vue | 2 +- components/status/StatusActionsMore.vue | 8 +- .../status/StatusFavouritedBoostedBy.vue | 4 +- components/status/StatusPoll.vue | 5 +- components/status/edit/StatusEditHistory.vue | 2 +- components/tag/TagActionButton.vue | 6 +- components/timeline/TimelineBlocks.vue | 2 +- components/timeline/TimelineBookmarks.vue | 2 +- components/timeline/TimelineConversations.vue | 2 +- components/timeline/TimelineDomainBlocks.vue | 6 +- components/timeline/TimelineFavourites.vue | 2 +- components/timeline/TimelineHome.vue | 5 +- components/timeline/TimelineMentions.vue | 5 +- components/timeline/TimelineMutes.vue | 2 +- components/timeline/TimelineNotifications.vue | 5 +- components/timeline/TimelinePinned.vue | 2 +- components/timeline/TimelinePublic.vue | 5 +- components/timeline/TimelinePublicLocal.vue | 5 +- components/user/UserPicker.vue | 9 +- components/user/UserSignIn.vue | 3 +- components/user/UserSignInEntry.vue | 2 +- components/user/UserSwitcher.vue | 9 +- composables/cache.ts | 6 +- composables/command.ts | 2 +- composables/emojis.ts | 4 +- composables/masto/masto.ts | 116 +++++++++- composables/masto/notification.ts | 21 +- composables/masto/publish.ts | 16 +- composables/masto/relationship.ts | 2 +- composables/masto/search.ts | 10 +- composables/masto/status.ts | 12 +- composables/paginator.ts | 65 +++--- .../createPushSubscription.ts | 2 +- .../push-notifications/usePushManager.ts | 4 +- composables/tiptap/suggestion.ts | 4 +- composables/users.ts | 202 ++++++------------ composables/vue.ts | 4 + error.vue | 3 - layouts/default.vue | 2 +- middleware/auth.ts | 2 +- middleware/permalink.global.ts | 20 +- pages/[[server]]/@[account]/[status].vue | 8 +- pages/[[server]]/@[account]/index.vue | 2 +- .../[[server]]/@[account]/index/followers.vue | 2 +- .../[[server]]/@[account]/index/following.vue | 2 +- pages/[[server]]/@[account]/index/index.vue | 2 +- pages/[[server]]/@[account]/index/media.vue | 2 +- .../@[account]/index/with_replies.vue | 2 +- pages/[[server]]/explore.vue | 4 +- pages/[[server]]/explore/index.vue | 2 +- pages/[[server]]/explore/links.vue | 2 +- pages/[[server]]/explore/tags.vue | 4 +- pages/[[server]]/explore/users.vue | 2 +- pages/[[server]]/public/index.vue | 2 +- pages/[[server]]/public/local.vue | 2 +- pages/[[server]]/tags/[tag].vue | 9 +- pages/blocks.vue | 2 +- pages/bookmarks.vue | 2 +- pages/conversations.vue | 2 +- pages/domain_blocks.vue | 2 +- pages/favourites.vue | 2 +- pages/home.vue | 7 +- pages/mutes.vue | 2 +- pages/notifications/index.vue | 2 +- pages/notifications/mention.vue | 2 +- pages/pinned.vue | 2 +- pages/search.vue | 2 +- pages/settings/profile/appearance.vue | 12 +- plugins/masto.ts | 30 ++- types/index.ts | 6 - 81 files changed, 397 insertions(+), 367 deletions(-) diff --git a/components/account/AccountFollowButton.vue b/components/account/AccountFollowButton.vue index 255d455d..f1ef9f0b 100644 --- a/components/account/AccountFollowButton.vue +++ b/components/account/AccountFollowButton.vue @@ -12,11 +12,11 @@ const isSelf = $(useSelfAccount(() => account)) const enable = $computed(() => !isSelf && currentUser.value) const relationship = $computed(() => props.relationship || useRelationship(account).value) -const masto = useMasto() +const { client } = $(useMasto()) async function toggleFollow() { relationship!.following = !relationship!.following try { - const newRel = await masto.v1.accounts[relationship!.following ? 'follow' : 'unfollow'](account.id) + const newRel = await client.v1.accounts[relationship!.following ? 'follow' : 'unfollow'](account.id) Object.assign(relationship!, newRel) } catch (err) { @@ -29,7 +29,7 @@ async function toggleFollow() { async function unblock() { relationship!.blocking = false try { - const newRel = await masto.v1.accounts.unblock(account.id) + const newRel = await client.v1.accounts.unblock(account.id) Object.assign(relationship!, newRel) } catch (err) { @@ -42,7 +42,7 @@ async function unblock() { async function unmute() { relationship!.muting = false try { - const newRel = await masto.v1.accounts.unmute(account.id) + const newRel = await client.v1.accounts.unmute(account.id) Object.assign(relationship!, newRel) } catch (err) { diff --git a/components/account/AccountHeader.vue b/components/account/AccountHeader.vue index 8de0605c..8b307989 100644 --- a/components/account/AccountHeader.vue +++ b/components/account/AccountHeader.vue @@ -6,7 +6,7 @@ const { account } = defineProps<{ command?: boolean }>() -const masto = useMasto() +const { client } = $(useMasto()) const { t } = useI18n() @@ -46,7 +46,7 @@ function previewAvatar() { async function toggleNotify() { relationship!.notifying = !relationship!.notifying try { - const newRel = await masto.v1.accounts.follow(account.id, { notify: relationship!.notifying }) + const newRel = await client.v1.accounts.follow(account.id, { notify: relationship!.notifying }) Object.assign(relationship!, newRel) } catch { diff --git a/components/account/AccountMoreButton.vue b/components/account/AccountMoreButton.vue index 70c99b1a..52276d75 100644 --- a/components/account/AccountMoreButton.vue +++ b/components/account/AccountMoreButton.vue @@ -10,7 +10,7 @@ let relationship = $(useRelationship(account)) const isSelf = $(useSelfAccount(() => account)) const { t } = useI18n() -const masto = useMasto() +const { client } = $(useMasto()) const isConfirmed = async (title: string) => { return await openConfirmDialog(t('common.confirm_dialog.title', [title])) === 'confirm' @@ -22,10 +22,10 @@ const toggleMute = async (title: string) => { relationship!.muting = !relationship!.muting relationship = relationship!.muting - ? await masto.v1.accounts.mute(account.id, { + ? await client.v1.accounts.mute(account.id, { // TODO support more options }) - : await masto.v1.accounts.unmute(account.id) + : await client.v1.accounts.unmute(account.id) } const toggleBlockUser = async (title: string) => { @@ -33,7 +33,7 @@ const toggleBlockUser = async (title: string) => { return relationship!.blocking = !relationship!.blocking - relationship = await masto.v1.accounts[relationship!.blocking ? 'block' : 'unblock'](account.id) + relationship = await client.v1.accounts[relationship!.blocking ? 'block' : 'unblock'](account.id) } const toggleBlockDomain = async (title: string) => { @@ -41,7 +41,7 @@ const toggleBlockDomain = async (title: string) => { return relationship!.domainBlocking = !relationship!.domainBlocking - await masto.v1.domainBlocks[relationship!.domainBlocking ? 'block' : 'unblock'](getServerName(account)) + await client.v1.domainBlocks[relationship!.domainBlocking ? 'block' : 'unblock'](getServerName(account)) } const toggleReblogs = async (title: string) => { @@ -49,7 +49,7 @@ const toggleReblogs = async (title: string) => { return const showingReblogs = !relationship?.showingReblogs - relationship = await masto.v1.accounts.follow(account.id, { reblogs: showingReblogs }) + relationship = await client.v1.accounts.follow(account.id, { reblogs: showingReblogs }) } diff --git a/components/common/CommonPaginator.vue b/components/common/CommonPaginator.vue index 1191f17d..52feb76a 100644 --- a/components/common/CommonPaginator.vue +++ b/components/common/CommonPaginator.vue @@ -42,7 +42,7 @@ defineSlots<{ const { t } = useI18n() -const { items, prevItems, update, state, endAnchor, error } = usePaginator(paginator, stream, eventType, preprocess) +const { items, prevItems, update, state, endAnchor, error } = usePaginator(paginator, $$(stream), eventType, preprocess)