Skip to content

Commit

Permalink
feat: upgrade to masto.js v6 (#2530)
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev authored Jan 9, 2024
1 parent d8ea685 commit 6c5bb83
Show file tree
Hide file tree
Showing 62 changed files with 262 additions and 263 deletions.
4 changes: 2 additions & 2 deletions components/account/AccountFollowButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const { client } = $(useMasto())
async function unblock() {
relationship!.blocking = false
try {
const newRel = await client.v1.accounts.unblock(account.id)
const newRel = await client.v1.accounts.$select(account.id).unblock()
Object.assign(relationship!, newRel)
}
catch (err) {
Expand All @@ -32,7 +32,7 @@ async function unblock() {
async function unmute() {
relationship!.muting = false
try {
const newRel = await client.v1.accounts.unmute(account.id)
const newRel = await client.v1.accounts.$select(account.id).unmute()
Object.assign(relationship!, newRel)
}
catch (err) {
Expand Down
4 changes: 2 additions & 2 deletions components/account/AccountFollowRequestButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async function authorizeFollowRequest() {
relationship!.requestedBy = false
relationship!.followedBy = true
try {
const newRel = await client.v1.followRequests.authorize(account.id)
const newRel = await client.v1.followRequests.$select(account.id).authorize()
Object.assign(relationship!, newRel)
}
catch (err) {
Expand All @@ -25,7 +25,7 @@ async function authorizeFollowRequest() {
async function rejectFollowRequest() {
relationship!.requestedBy = false
try {
const newRel = await client.v1.followRequests.reject(account.id)
const newRel = await client.v1.followRequests.$select(account.id).reject()
Object.assign(relationship!, newRel)
}
catch (err) {
Expand Down
4 changes: 2 additions & 2 deletions components/account/AccountHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function previewAvatar() {
async function toggleNotifications() {
relationship!.notifying = !relationship?.notifying
try {
const newRel = await client.v1.accounts.follow(account.id, { notify: relationship?.notifying })
const newRel = await client.v1.accounts.$select(account.id).follow({ notify: relationship?.notifying })
Object.assign(relationship!, newRel)
}
catch {
Expand Down Expand Up @@ -97,7 +97,7 @@ async function editNote(event: Event) {
if (relationship.note?.trim() === newNote.trim())
return
const newNoteApiResult = await client.v1.accounts.createNote(account.id, { comment: newNote })
const newNoteApiResult = await client.v1.accounts.$select(account.id).note.create({ comment: newNote })
relationship.note = newNoteApiResult.note
personalNoteDraft.value = relationship.note ?? ''
}
Expand Down
4 changes: 2 additions & 2 deletions components/account/AccountMoreButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async function toggleReblogs() {
return
const showingReblogs = !relationship?.showingReblogs
relationship = await client.v1.accounts.follow(account.id, { reblogs: showingReblogs })
relationship = await client.v1.accounts.$select(account.id).follow({ reblogs: showingReblogs })
}
async function addUserNote() {
Expand All @@ -44,7 +44,7 @@ async function removeUserNote() {
if (!relationship!.note || relationship!.note.length === 0)
return
const newNote = await client.v1.accounts.createNote(account.id, { comment: '' })
const newNote = await client.v1.accounts.$select(account.id).note.create({ comment: '' })
relationship!.note = newNote.note
emit('removeNote')
}
Expand Down
4 changes: 2 additions & 2 deletions components/account/AccountPaginator.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script setup lang="ts">
import type { Paginator, mastodon } from 'masto'
import type { mastodon } from 'masto'
const { paginator, account, context } = defineProps<{
paginator: Paginator<mastodon.v1.Account[], mastodon.DefaultPaginationParams>
paginator: mastodon.Paginator<mastodon.v1.Account[], mastodon.DefaultPaginationParams | undefined>
context?: 'following' | 'followers'
account?: mastodon.v1.Account
relationshipContext?: 'followedBy' | 'following'
Expand Down
6 changes: 3 additions & 3 deletions components/common/CommonPaginator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// @ts-expect-error missing types
import { DynamicScroller } from 'vue-virtual-scroller'
import 'vue-virtual-scroller/dist/vue-virtual-scroller.css'
import type { Paginator, WsEvents } from 'masto'
import type { mastodon } from 'masto'
import type { UnwrapRef } from 'vue'
const {
Expand All @@ -14,10 +14,10 @@ const {
preprocess,
endMessage = true,
} = defineProps<{
paginator: Paginator<T[], O>
paginator: mastodon.Paginator<T[], O>
keyProp?: keyof T
virtualScroller?: boolean
stream?: Promise<WsEvents>
stream?: mastodon.streaming.Subscription
eventType?: 'notification' | 'update'
preprocess?: (items: (U | T)[]) => U[]
endMessage?: boolean | string
Expand Down
4 changes: 2 additions & 2 deletions components/conversation/ConversationPaginator.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script setup lang="ts">
import type { Paginator, mastodon } from 'masto'
import type { mastodon } from 'masto'
const { paginator } = defineProps<{
paginator: Paginator<mastodon.v1.Conversation[], mastodon.DefaultPaginationParams>
paginator: mastodon.Paginator<mastodon.v1.Conversation[], mastodon.DefaultPaginationParams>
}>()
function preprocess(items: mastodon.v1.Conversation[]): mastodon.v1.Conversation[] {
Expand Down
4 changes: 2 additions & 2 deletions components/list/Account.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const isRemoved = ref(false)
async function edit() {
try {
isRemoved.value
? await client.v1.lists.addAccount(list, { accountIds: [account.id] })
: await client.v1.lists.removeAccount(list, { accountIds: [account.id] })
? await client.v1.lists.$select(list).accounts.create({ accountIds: [account.id] })
: await client.v1.lists.$select(list).accounts.remove({ accountIds: [account.id] })
isRemoved.value = !isRemoved.value
}
catch (err) {
Expand Down
4 changes: 2 additions & 2 deletions components/list/ListEntry.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async function cancelEdit() {
const { submit, submitting } = submitter(async () => {
try {
list.value = await client.v1.lists.update(form.id, {
list.value = await client.v1.lists.$select(form.id).update({
title: form.title,
})
cancelEdit()
Expand Down Expand Up @@ -70,7 +70,7 @@ async function removeList() {
if (confirmDelete === 'confirm') {
await nextTick()
try {
await client.v1.lists.remove(list.value.id)
await client.v1.lists.$select(list.value.id).remove()
emit('listRemoved', list.value.id)
}
catch (err) {
Expand Down
6 changes: 3 additions & 3 deletions components/list/Lists.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { userId } = defineProps<{
const { client } = $(useMasto())
const paginator = client.v1.lists.list()
const listsWithUser = ref((await client.v1.accounts.listLists(userId)).map(list => list.id))
const listsWithUser = ref((await client.v1.accounts.$select(userId).lists.list()).map(list => list.id))
function indexOfUserInList(listId: string) {
return listsWithUser.value.indexOf(listId)
Expand All @@ -15,11 +15,11 @@ async function edit(listId: string) {
try {
const index = indexOfUserInList(listId)
if (index === -1) {
await client.v1.lists.addAccount(listId, { accountIds: [userId] })
await client.v1.lists.$select(listId).accounts.create({ accountIds: [userId] })
listsWithUser.value.push(listId)
}
else {
await client.v1.lists.removeAccount(listId, { accountIds: [userId] })
await client.v1.lists.$select(listId).accounts.remove({ accountIds: [userId] })
listsWithUser.value = listsWithUser.value.filter(id => id !== listId)
}
}
Expand Down
2 changes: 0 additions & 2 deletions components/notification/NotificationCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const { notification } = defineProps<{
ps-3 pe-4 inset-is-0
rounded-ie-be-3
py-3 bg-base top-0
:lang="notification.status?.language ?? undefined"
>
<div i-ri-user-3-line text-xl me-3 color-blue />
<AccountDisplayName :account="notification.account" text-primary me-1 font-bold line-clamp-1 ws-pre-wrap break-all />
Expand All @@ -26,7 +25,6 @@ const { notification } = defineProps<{
<AccountBigCard
ms10
:account="notification.account"
:lang="notification.status?.language ?? undefined"
/>
</NuxtLink>
</template>
Expand Down
6 changes: 3 additions & 3 deletions components/notification/NotificationPaginator.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<script setup lang="ts">
// @ts-expect-error missing types
import { DynamicScrollerItem } from 'vue-virtual-scroller'
import type { Paginator, WsEvents, mastodon } from 'masto'
import type { mastodon } from 'masto'
import type { GroupedAccountLike, NotificationSlot } from '~/types'
const { paginator, stream } = defineProps<{
paginator: Paginator<mastodon.v1.Notification[], mastodon.v1.ListNotificationsParams>
stream?: Promise<WsEvents>
paginator: mastodon.Paginator<mastodon.v1.Notification[], mastodon.rest.v1.ListNotificationsParams>
stream?: mastodon.streaming.Subscription
}>()
const virtualScroller = false // TODO: fix flickering issue with virtual scroll
Expand Down
5 changes: 3 additions & 2 deletions components/publish/PublishWidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,13 @@ function trimPollOptions() {
}
function editPollOptionDraft(event: Event, index: number) {
draft.params.poll!.options[index] = (event.target as HTMLInputElement).value
draft.params.poll!.options = Object.assign(draft.params.poll!.options.slice(), { [index]: (event.target as HTMLInputElement).value })
trimPollOptions()
}
function deletePollOption(index: number) {
draft.params.poll!.options.splice(index, 1)
draft.params.poll!.options = draft.params.poll!.options.slice().splice(index, 1)
trimPollOptions()
}
Expand Down
6 changes: 3 additions & 3 deletions components/report/ReportModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ function categoryChosen() {
async function loadStatuses() {
if (status) {
// Load the 5 statuses before and after the reported status
const prevStatuses = await client.value.v1.accounts.listStatuses(account.id, {
const prevStatuses = await client.value.v1.accounts.$select(account.id).statuses.list({
maxId: status.id,
limit: 5,
})
const nextStatuses = await client.value.v1.accounts.listStatuses(account.id, {
const nextStatuses = await client.value.v1.accounts.$select(account.id).statuses.list({
minId: status.id,
limit: 5,
})
Expand All @@ -48,7 +48,7 @@ async function loadStatuses() {
else {
// Reporting an account directly
// Load the 10 most recent statuses
const mostRecentStatuses = await client.value.v1.accounts.listStatuses(account.id, {
const mostRecentStatuses = await client.value.v1.accounts.$select(account.id).statuses.list({
limit: 10,
})
availableStatuses.value = mostRecentStatuses
Expand Down
2 changes: 1 addition & 1 deletion components/settings/SettingsProfileMetadata.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import type { mastodon } from 'masto'
const form = defineModel<{
fieldsAttributes: NonNullable<mastodon.v1.UpdateCredentialsParams['fieldsAttributes']>
fieldsAttributes: NonNullable<mastodon.rest.v1.UpdateCredentialsParams['fieldsAttributes']>
}>({ required: true })
const dropdown = $ref<any>()
Expand Down
4 changes: 2 additions & 2 deletions components/status/StatusActionsMore.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async function deleteStatus() {
return
removeCachedStatus(status.id)
await client.v1.statuses.remove(status.id)
await client.v1.statuses.$select(status.id).remove()
if (route.name === 'status')
router.back()
Expand All @@ -96,7 +96,7 @@ async function deleteAndRedraft() {
}
removeCachedStatus(status.id)
await client.v1.statuses.remove(status.id)
await client.v1.statuses.$select(status.id).remove()
await openPublishDialog('dialog', await getDraftFromStatus(status), true)
// Go to the new status, if the page is the old status
Expand Down
2 changes: 1 addition & 1 deletion components/status/StatusFavouritedBoostedBy.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const type = ref<'favourited-by' | 'boosted-by'>('favourited-by')
const { client } = $(useMasto())
function load() {
return client.v1.statuses[type.value === 'favourited-by' ? 'listFavouritedBy' : 'listRebloggedBy'](favouritedBoostedByStatusId.value!)
return client.v1.statuses.$select(favouritedBoostedByStatusId.value!)[type.value === 'favourited-by' ? 'favouritedBy' : 'rebloggedBy'].list()
}
const paginator = $computed(() => load())
Expand Down
2 changes: 1 addition & 1 deletion components/status/StatusPoll.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async function vote(e: Event) {
cacheStatus({ ...status, poll }, undefined, true)
await client.v1.polls.vote(poll.id, { choices })
await client.v1.polls.$select(poll.id).votes.create({ choices })
}
const votersCount = $computed(() => poll.votersCount ?? poll.votesCount ?? 0)
Expand Down
2 changes: 1 addition & 1 deletion components/status/edit/StatusEditHistory.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { status } = defineProps<{
status: mastodon.v1.Status
}>()
const paginator = useMastoClient().v1.statuses.listHistory(status.id)
const paginator = useMastoClient().v1.statuses.$select(status.id).history.list()
function showHistory(edit: mastodon.v1.StatusEdit) {
openEditHistoryDialog(edit)
Expand Down
4 changes: 2 additions & 2 deletions components/tag/TagActionButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ async function toggleFollowTag() {
try {
if (previousFollowingState)
await client.v1.tags.unfollow(tag.name)
await client.v1.tags.$select(tag.name).unfollow()
else
await client.v1.tags.follow(tag.name)
await client.v1.tags.$select(tag.name).follow()
emit('change')
}
Expand Down
4 changes: 2 additions & 2 deletions components/tag/TagCardPaginator.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script setup lang="ts">
import type { Paginator, mastodon } from 'masto'
import type { mastodon } from 'masto'
const { paginator } = defineProps<{
paginator: Paginator<mastodon.v1.Tag[], mastodon.DefaultPaginationParams>
paginator: mastodon.Paginator<mastodon.v1.Tag[], mastodon.DefaultPaginationParams>
}>()
</script>

Expand Down
2 changes: 1 addition & 1 deletion components/timeline/TimelineDomainBlocks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { client } = $(useMasto())
const paginator = client.v1.domainBlocks.list()
async function unblock(domain: string) {
await client.v1.domainBlocks.unblock(domain)
await client.v1.domainBlocks.remove({ domain })
}
</script>

Expand Down
4 changes: 2 additions & 2 deletions components/timeline/TimelineHome.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script setup lang="ts">
import type { mastodon } from 'masto'
const paginator = useMastoClient().v1.timelines.listHome({ limit: 30 })
const stream = $(useStreaming(client => client.v1.stream.streamUser()))
const paginator = useMastoClient().v1.timelines.home.list({ limit: 30 })
const stream = useStreaming(client => client.user.subscribe())
function reorderAndFilter(items: mastodon.v1.Status[]) {
return reorderedTimeline(items, 'home')
}
Expand Down
2 changes: 1 addition & 1 deletion components/timeline/TimelineNotifications.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const options = { limit: 30, types: filter ? [filter] : [] }
// Default limit is 20 notifications, and servers are normally caped to 30
const paginator = useMastoClient().v1.notifications.list(options)
const stream = useStreaming(client => client.v1.stream.streamUser())
const stream = useStreaming(client => client.user.subscribe())
const { clearNotifications } = useNotifications()
onActivated(clearNotifications)
Expand Down
6 changes: 3 additions & 3 deletions components/timeline/TimelinePaginator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// @ts-expect-error missing types
import { DynamicScrollerItem } from 'vue-virtual-scroller'
import 'vue-virtual-scroller/dist/vue-virtual-scroller.css'
import type { Paginator, WsEvents, mastodon } from 'masto'
import type { mastodon } from 'masto'
const { paginator, stream, account, buffer = 10, endMessage = true } = defineProps<{
paginator: Paginator<mastodon.v1.Status[], mastodon.v1.ListAccountStatusesParams>
stream?: Promise<WsEvents>
paginator: mastodon.Paginator<mastodon.v1.Status[], mastodon.rest.v1.ListAccountStatusesParams>
stream?: mastodon.streaming.Subscription
context?: mastodon.v2.FilterContext
account?: mastodon.v1.Account
preprocess?: (items: mastodon.v1.Status[]) => mastodon.v1.Status[]
Expand Down
2 changes: 1 addition & 1 deletion components/timeline/TimelinePinned.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
const paginator = useMastoClient().v1.accounts.listStatuses(currentUser.value!.account.id, { pinned: true })
const paginator = useMastoClient().v1.accounts.$select(currentUser.value!.account.id).statuses.list({ pinned: true })
</script>

<template>
Expand Down
4 changes: 2 additions & 2 deletions components/timeline/TimelinePublic.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script setup lang="ts">
import type { mastodon } from 'masto'
const paginator = useMastoClient().v1.timelines.listPublic({ limit: 30 })
const stream = useStreaming(client => client.v1.stream.streamPublicTimeline())
const paginator = useMastoClient().v1.timelines.public.list({ limit: 30 })
const stream = useStreaming(client => client.public.subscribe())
function reorderAndFilter(items: mastodon.v1.Status[]) {
return reorderedTimeline(items, 'public')
}
Expand Down
4 changes: 2 additions & 2 deletions components/timeline/TimelinePublicLocal.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
const paginator = useMastoClient().v1.timelines.listPublic({ limit: 30, local: true })
const stream = useStreaming(client => client.v1.stream.streamCommunityTimeline())
const paginator = useMastoClient().v1.timelines.public.list({ limit: 30, local: true })
const stream = useStreaming(client => client.direct.subscribe())
</script>

<template>
Expand Down
Loading

0 comments on commit 6c5bb83

Please sign in to comment.