refactor: no reactivity transform (#2600)

This commit is contained in:
patak 2024-02-21 16:20:08 +01:00 committed by GitHub
parent b9394c2fa5
commit ccfa7a8d10
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
102 changed files with 649 additions and 652 deletions

View file

@ -20,18 +20,18 @@ export function useAriaAnnouncer() {
}
export function useAriaLog() {
let logs = $ref<any[]>([])
const logs = ref<any[]>([])
const announceLogs = (messages: any[]) => {
logs = messages
logs.value = messages
}
const appendLogs = (messages: any[]) => {
logs = logs.concat(messages)
logs.value = logs.value.concat(messages)
}
const clearLogs = () => {
logs = []
logs.value = []
}
return {
@ -43,14 +43,14 @@ export function useAriaLog() {
}
export function useAriaStatus() {
let status = $ref<any>('')
const status = ref<any>('')
const announceStatus = (message: any) => {
status = message
status.value = message
}
const clearStatus = () => {
status = ''
status.value = ''
}
return {

View file

@ -19,8 +19,8 @@ export async function updateCustomEmojis() {
if (Date.now() - currentCustomEmojis.value.lastUpdate < TTL)
return
const { client } = $(useMasto())
const emojis = await client.v1.customEmojis.list()
const { client } = useMasto()
const emojis = await client.value.v1.customEmojis.list()
Object.assign(currentCustomEmojis.value, {
lastUpdate: Date.now(),
emojis,

View file

@ -32,10 +32,10 @@ export function useHumanReadableNumber() {
export function useFormattedDateTime(value: MaybeRefOrGetter<string | number | Date | undefined | null>,
options: Intl.DateTimeFormatOptions = { dateStyle: 'long', timeStyle: 'medium' }) {
const { locale } = useI18n()
const formatter = $computed(() => Intl.DateTimeFormat(locale.value, options))
const formatter = computed(() => Intl.DateTimeFormat(locale.value, options))
return computed(() => {
const v = resolveUnref(value)
return v ? formatter.format(new Date(v)) : ''
return v ? formatter.value.format(new Date(v)) : ''
})
}

View file

@ -5,7 +5,7 @@ const notifications = reactive<Record<string, undefined | [Promise<mastodon.stre
export function useNotifications() {
const id = currentUser.value?.account.id
const { client, streamingClient } = $(useMasto())
const { client, streamingClient } = useMasto()
async function clearNotifications() {
if (!id || !notifications[id])
@ -15,7 +15,7 @@ export function useNotifications() {
notifications[id]![1] = []
if (lastReadId) {
await client.v1.markers.create({
await client.value.v1.markers.create({
notifications: { lastReadId },
})
}
@ -36,15 +36,15 @@ export function useNotifications() {
const streamPromise = new Promise<mastodon.streaming.Subscription>(resolve => resolveStream = resolve)
notifications[id] = [streamPromise, []]
await until($$(streamingClient)).toBeTruthy()
await until(streamingClient).toBeTruthy()
const stream = streamingClient!.user.subscribe()
const stream = streamingClient.value!.user.subscribe()
resolveStream!(stream)
processNotifications(stream, id)
const position = await client.v1.markers.fetch({ timeline: ['notifications'] })
const paginator = client.v1.notifications.list({ limit: 30 })
const position = await client.value.v1.markers.fetch({ timeline: ['notifications'] })
const paginator = client.value.v1.notifications.list({ limit: 30 })
do {
const result = await paginator.next()

View file

@ -10,69 +10,68 @@ export function usePublish(options: {
isUploading: Ref<boolean>
initialDraft: Ref<() => Draft>
}) {
const { expanded, isUploading, initialDraft } = $(options)
let { draft, isEmpty } = $(options.draftState)
const { client } = $(useMasto())
const { draft, isEmpty } = options.draftState
const { client } = useMasto()
const settings = useUserSettings()
const preferredLanguage = $computed(() => (currentUser.value?.account.source.language || settings.value?.language || 'en').split('-')[0])
const preferredLanguage = computed(() => (currentUser.value?.account.source.language || settings.value?.language || 'en').split('-')[0])
let isSending = $ref(false)
const isExpanded = $ref(false)
const failedMessages = $ref<string[]>([])
const isSending = ref(false)
const isExpanded = ref(false)
const failedMessages = ref<string[]>([])
const publishSpoilerText = $computed({
const publishSpoilerText = computed({
get() {
return draft.params.sensitive ? draft.params.spoilerText : ''
return draft.value.params.sensitive ? draft.value.params.spoilerText : ''
},
set(val) {
if (!draft.params.sensitive)
if (!draft.value.params.sensitive)
return
draft.params.spoilerText = val
draft.value.params.spoilerText = val
},
})
const shouldExpanded = $computed(() => expanded || isExpanded || !isEmpty)
const isPublishDisabled = $computed(() => {
const firstEmptyInputIndex = draft.params.poll?.options.findIndex(option => option.trim().length === 0)
return isEmpty
|| isUploading
|| isSending
|| (draft.attachments.length === 0 && !draft.params.status)
|| failedMessages.length > 0
|| (draft.attachments.length > 0 && draft.params.poll !== null && draft.params.poll !== undefined)
|| ((draft.params.poll !== null && draft.params.poll !== undefined)
const shouldExpanded = computed(() => options.expanded.value || isExpanded.value || !isEmpty.value)
const isPublishDisabled = computed(() => {
const { params, attachments } = draft.value
const firstEmptyInputIndex = params.poll?.options.findIndex(option => option.trim().length === 0)
return isEmpty.value
|| options.isUploading.value
|| isSending.value
|| (attachments.length === 0 && !params.status)
|| failedMessages.value.length > 0
|| (attachments.length > 0 && params.poll !== null && params.poll !== undefined)
|| ((params.poll !== null && params.poll !== undefined)
&& (
(firstEmptyInputIndex !== -1
&& firstEmptyInputIndex !== draft.params.poll.options.length - 1
&& firstEmptyInputIndex !== params.poll.options.length - 1
)
|| draft.params.poll.options.findLastIndex(option => option.trim().length > 0) + 1 < 2
|| (new Set(draft.params.poll.options).size !== draft.params.poll.options.length)
|| params.poll.options.findLastIndex(option => option.trim().length > 0) + 1 < 2
|| (new Set(params.poll.options).size !== params.poll.options.length)
|| (currentInstance.value?.configuration?.polls.maxCharactersPerOption !== undefined
&& draft.params.poll.options.find(option => option.length > currentInstance.value!.configuration!.polls.maxCharactersPerOption) !== undefined
&& params.poll.options.find(option => option.length > currentInstance.value!.configuration!.polls.maxCharactersPerOption) !== undefined
)
)
)
})
watch(() => draft, () => {
if (failedMessages.length > 0)
failedMessages.length = 0
if (failedMessages.value.length > 0)
failedMessages.value.length = 0
}, { deep: true })
async function publishDraft() {
if (isPublishDisabled)
if (isPublishDisabled.value)
return
let content = htmlToText(draft.params.status || '')
if (draft.mentions?.length)
content = `${draft.mentions.map(i => `@${i}`).join(' ')} ${content}`
let content = htmlToText(draft.value.params.status || '')
if (draft.value.mentions?.length)
content = `${draft.value.mentions.map(i => `@${i}`).join(' ')} ${content}`
let poll
if (draft.params.poll) {
let options = draft.params.poll.options
if (draft.value.params.poll) {
let options = draft.value.params.poll.options
if (currentInstance.value?.configuration !== undefined
&& (
@ -82,15 +81,15 @@ export function usePublish(options: {
)
options = options.slice(0, options.length - 1)
poll = { ...draft.params.poll, options }
poll = { ...draft.value.params.poll, options }
}
const payload = {
...draft.params,
spoilerText: publishSpoilerText,
...draft.value.params,
spoilerText: publishSpoilerText.value,
status: content,
mediaIds: draft.attachments.map(a => a.id),
language: draft.params.language || preferredLanguage,
mediaIds: draft.value.attachments.map(a => a.id),
language: draft.value.params.language || preferredLanguage.value,
poll,
...(isGlitchEdition.value ? { 'content-type': 'text/markdown' } : {}),
} as mastodon.rest.v1.CreateStatusParams
@ -98,7 +97,7 @@ export function usePublish(options: {
if (process.dev) {
// eslint-disable-next-line no-console
console.info({
raw: draft.params.status,
raw: draft.value.params.status,
...payload,
})
// eslint-disable-next-line no-alert
@ -108,39 +107,39 @@ export function usePublish(options: {
}
try {
isSending = true
isSending.value = true
let status: mastodon.v1.Status
if (!draft.editingStatus) {
status = await client.v1.statuses.create(payload)
if (!draft.value.editingStatus) {
status = await client.value.v1.statuses.create(payload)
}
else {
status = await client.v1.statuses.$select(draft.editingStatus.id).update({
status = await client.value.v1.statuses.$select(draft.value.editingStatus.id).update({
...payload,
mediaAttributes: draft.attachments.map(media => ({
mediaAttributes: draft.value.attachments.map(media => ({
id: media.id,
description: media.description,
})),
})
}
if (draft.params.inReplyToId)
if (draft.value.params.inReplyToId)
navigateToStatus({ status })
draft = initialDraft()
draft.value = options.initialDraft.value()
return status
}
catch (err) {
console.error(err)
failedMessages.push((err as Error).message)
failedMessages.value.push((err as Error).message)
}
finally {
isSending = false
isSending.value = false
}
}
return $$({
return {
isSending,
isExpanded,
shouldExpanded,
@ -149,22 +148,21 @@ export function usePublish(options: {
preferredLanguage,
publishSpoilerText,
publishDraft,
})
}
}
export type MediaAttachmentUploadError = [filename: string, message: string]
export function useUploadMediaAttachment(draftRef: Ref<Draft>) {
const draft = $(draftRef)
const { client } = $(useMasto())
export function useUploadMediaAttachment(draft: Ref<Draft>) {
const { client } = useMasto()
const { t } = useI18n()
let isUploading = $ref<boolean>(false)
let isExceedingAttachmentLimit = $ref<boolean>(false)
let failedAttachments = $ref<MediaAttachmentUploadError[]>([])
const isUploading = ref<boolean>(false)
const isExceedingAttachmentLimit = ref<boolean>(false)
const failedAttachments = ref<MediaAttachmentUploadError[]>([])
const dropZoneRef = ref<HTMLDivElement>()
const maxPixels = $computed(() => {
const maxPixels = computed(() => {
return currentInstance.value?.configuration?.mediaAttachments?.imageMatrixLimit
?? 4096 ** 2
})
@ -186,8 +184,8 @@ export function useUploadMediaAttachment(draftRef: Ref<Draft>) {
const canvas = document.createElement('canvas')
const resizedWidth = canvas.width = Math.round(Math.sqrt(maxPixels * aspectRatio))
const resizedHeight = canvas.height = Math.round(Math.sqrt(maxPixels / aspectRatio))
const resizedWidth = canvas.width = Math.round(Math.sqrt(maxPixels.value * aspectRatio))
const resizedHeight = canvas.height = Math.round(Math.sqrt(maxPixels.value / aspectRatio))
const context = canvas.getContext('2d')
@ -202,7 +200,7 @@ export function useUploadMediaAttachment(draftRef: Ref<Draft>) {
try {
const image = await loadImage(file) as HTMLImageElement
if (image.width * image.height > maxPixels)
if (image.width * image.height > maxPixels.value)
file = await resizeImage(image, file.type) as File
return file
@ -222,32 +220,32 @@ export function useUploadMediaAttachment(draftRef: Ref<Draft>) {
}
async function uploadAttachments(files: File[]) {
isUploading = true
failedAttachments = []
isUploading.value = true
failedAttachments.value = []
// TODO: display some kind of message if too many media are selected
// DONE
const limit = currentInstance.value!.configuration?.statuses.maxMediaAttachments || 4
for (const file of files.slice(0, limit)) {
if (draft.attachments.length < limit) {
isExceedingAttachmentLimit = false
if (draft.value.attachments.length < limit) {
isExceedingAttachmentLimit.value = false
try {
const attachment = await client.v1.media.create({
const attachment = await client.value.v1.media.create({
file: await processFile(file),
})
draft.attachments.push(attachment)
draft.value.attachments.push(attachment)
}
catch (e) {
// TODO: add some human-readable error message, problem is that masto api will not return response code
console.error(e)
failedAttachments = [...failedAttachments, [file.name, (e as Error).message]]
failedAttachments.value = [...failedAttachments.value, [file.name, (e as Error).message]]
}
}
else {
isExceedingAttachmentLimit = true
failedAttachments = [...failedAttachments, [file.name, t('state.attachments_limit_error')]]
isExceedingAttachmentLimit.value = true
failedAttachments.value = [...failedAttachments.value, [file.name, t('state.attachments_limit_error')]]
}
}
isUploading = false
isUploading.value = false
}
async function pickAttachments() {
@ -264,12 +262,12 @@ export function useUploadMediaAttachment(draftRef: Ref<Draft>) {
async function setDescription(att: mastodon.v1.MediaAttachment, description: string) {
att.description = description
if (!draft.editingStatus)
await client.v1.media.$select(att.id).update({ description: att.description })
if (!draft.value.editingStatus)
await client.value.v1.media.$select(att.id).update({ description: att.description })
}
function removeAttachment(index: number) {
draft.attachments.splice(index, 1)
draft.value.attachments.splice(index, 1)
}
async function onDrop(files: File[] | null) {
@ -279,7 +277,7 @@ export function useUploadMediaAttachment(draftRef: Ref<Draft>) {
const { isOverDropZone } = useDropZone(dropZoneRef, onDrop)
return $$({
return {
isUploading,
isExceedingAttachmentLimit,
isOverDropZone,
@ -291,5 +289,5 @@ export function useUploadMediaAttachment(draftRef: Ref<Draft>) {
pickAttachments,
setDescription,
removeAttachment,
})
}
}

View file

@ -33,7 +33,7 @@ async function fetchRelationships() {
}
export async function toggleFollowAccount(relationship: mastodon.v1.Relationship, account: mastodon.v1.Account) {
const { client } = $(useMasto())
const { client } = useMasto()
const i18n = useNuxtApp().$i18n
const unfollow = relationship!.following || relationship!.requested
@ -59,11 +59,11 @@ export async function toggleFollowAccount(relationship: mastodon.v1.Relationship
relationship!.following = true
}
relationship = await client.v1.accounts.$select(account.id)[unfollow ? 'unfollow' : 'follow']()
relationship = await client.value.v1.accounts.$select(account.id)[unfollow ? 'unfollow' : 'follow']()
}
export async function toggleMuteAccount(relationship: mastodon.v1.Relationship, account: mastodon.v1.Account) {
const { client } = $(useMasto())
const { client } = useMasto()
const i18n = useNuxtApp().$i18n
if (!relationship!.muting && await openConfirmDialog({
@ -76,14 +76,14 @@ export async function toggleMuteAccount(relationship: mastodon.v1.Relationship,
relationship!.muting = !relationship!.muting
relationship = relationship!.muting
? await client.v1.accounts.$select(account.id).mute({
? await client.value.v1.accounts.$select(account.id).mute({
// TODO support more options
})
: await client.v1.accounts.$select(account.id).unmute()
: await client.value.v1.accounts.$select(account.id).unmute()
}
export async function toggleBlockAccount(relationship: mastodon.v1.Relationship, account: mastodon.v1.Account) {
const { client } = $(useMasto())
const { client } = useMasto()
const i18n = useNuxtApp().$i18n
if (!relationship!.blocking && await openConfirmDialog({
@ -95,11 +95,11 @@ export async function toggleBlockAccount(relationship: mastodon.v1.Relationship,
return
relationship!.blocking = !relationship!.blocking
relationship = await client.v1.accounts.$select(account.id)[relationship!.blocking ? 'block' : 'unblock']()
relationship = await client.value.v1.accounts.$select(account.id)[relationship!.blocking ? 'block' : 'unblock']()
}
export async function toggleBlockDomain(relationship: mastodon.v1.Relationship, account: mastodon.v1.Account) {
const { client } = $(useMasto())
const { client } = useMasto()
const i18n = useNuxtApp().$i18n
if (!relationship!.domainBlocking && await openConfirmDialog({
@ -111,5 +111,5 @@ export async function toggleBlockDomain(relationship: mastodon.v1.Relationship,
return
relationship!.domainBlocking = !relationship!.domainBlocking
await client.v1.domainBlocks[relationship!.domainBlocking ? 'create' : 'remove']({ domain: getServerName(account) })
await client.value.v1.domainBlocks[relationship!.domainBlocking ? 'create' : 'remove']({ domain: getServerName(account) })
}

View file

@ -22,13 +22,13 @@ export type SearchResult = HashTagSearchResult | AccountSearchResult | StatusSea
export function useSearch(query: MaybeRefOrGetter<string>, options: UseSearchOptions = {}) {
const done = ref(false)
const { client } = $(useMasto())
const { client } = useMasto()
const loading = ref(false)
const accounts = ref<AccountSearchResult[]>([])
const hashtags = ref<HashTagSearchResult[]>([])
const statuses = ref<StatusSearchResult[]>([])
const q = $computed(() => resolveUnref(query).trim())
const q = computed(() => resolveUnref(query).trim())
let paginator: mastodon.Paginator<mastodon.v2.Search, mastodon.rest.v2.SearchParams> | undefined
@ -72,8 +72,8 @@ export function useSearch(query: MaybeRefOrGetter<string>, options: UseSearchOpt
* Based on the source it seems like modifying the params when calling next would result in a new search,
* but that doesn't seem to be the case. So instead we just create a new paginator with the new params.
*/
paginator = client.v2.search.list({
q,
paginator = client.value.v2.search.list({
q: q.value,
...resolveUnref(options),
resolve: !!currentUser.value,
})

View file

@ -8,17 +8,17 @@ export interface StatusActionsProps {
}
export function useStatusActions(props: StatusActionsProps) {
let status = $ref<mastodon.v1.Status>({ ...props.status })
const { client } = $(useMasto())
const status = ref<mastodon.v1.Status>({ ...props.status })
const { client } = useMasto()
watch(
() => props.status,
val => status = { ...val },
val => status.value = { ...val },
{ deep: true, immediate: true },
)
// Use different states to let the user press different actions right after the other
const isLoading = $ref({
const isLoading = ref({
reblogged: false,
favourited: false,
bookmarked: false,
@ -32,10 +32,10 @@ export function useStatusActions(props: StatusActionsProps) {
if (!checkLogin())
return
const prevCount = countField ? status[countField] : undefined
const prevCount = countField ? status.value[countField] : undefined
isLoading[action] = true
const isCancel = status[action]
isLoading.value[action] = true
const isCancel = status.value[action]
fetchNewStatus().then((newStatus) => {
// when the action is cancelled, the count is not updated highly likely (if they're the same)
// issue of Mastodon API
@ -45,24 +45,24 @@ export function useStatusActions(props: StatusActionsProps) {
Object.assign(status, newStatus)
cacheStatus(newStatus, undefined, true)
}).finally(() => {
isLoading[action] = false
isLoading.value[action] = false
})
// Optimistic update
status[action] = !status[action]
cacheStatus(status, undefined, true)
status.value[action] = !status.value[action]
cacheStatus(status.value, undefined, true)
if (countField)
status[countField] += status[action] ? 1 : -1
status.value[countField] += status.value[action] ? 1 : -1
}
const canReblog = $computed(() =>
status.visibility !== 'direct'
&& (status.visibility !== 'private' || status.account.id === currentUser.value?.account.id),
const canReblog = computed(() =>
status.value.visibility !== 'direct'
&& (status.value.visibility !== 'private' || status.value.account.id === currentUser.value?.account.id),
)
const toggleReblog = () => toggleStatusAction(
'reblogged',
() => client.v1.statuses.$select(status.id)[status.reblogged ? 'unreblog' : 'reblog']().then((res) => {
if (status.reblogged)
() => client.value.v1.statuses.$select(status.value.id)[status.value.reblogged ? 'unreblog' : 'reblog']().then((res) => {
if (status.value.reblogged)
// returns the original status
return res.reblog!
return res
@ -72,29 +72,29 @@ export function useStatusActions(props: StatusActionsProps) {
const toggleFavourite = () => toggleStatusAction(
'favourited',
() => client.v1.statuses.$select(status.id)[status.favourited ? 'unfavourite' : 'favourite'](),
() => client.value.v1.statuses.$select(status.value.id)[status.value.favourited ? 'unfavourite' : 'favourite'](),
'favouritesCount',
)
const toggleBookmark = () => toggleStatusAction(
'bookmarked',
() => client.v1.statuses.$select(status.id)[status.bookmarked ? 'unbookmark' : 'bookmark'](),
() => client.value.v1.statuses.$select(status.value.id)[status.value.bookmarked ? 'unbookmark' : 'bookmark'](),
)
const togglePin = async () => toggleStatusAction(
'pinned',
() => client.v1.statuses.$select(status.id)[status.pinned ? 'unpin' : 'pin'](),
() => client.value.v1.statuses.$select(status.value.id)[status.value.pinned ? 'unpin' : 'pin'](),
)
const toggleMute = async () => toggleStatusAction(
'muted',
() => client.v1.statuses.$select(status.id)[status.muted ? 'unmute' : 'mute'](),
() => client.value.v1.statuses.$select(status.value.id)[status.value.muted ? 'unmute' : 'mute'](),
)
return {
status: $$(status),
isLoading: $$(isLoading),
canReblog: $$(canReblog),
status,
isLoading,
canReblog,
toggleMute,
toggleReblog,
toggleFavourite,

View file

@ -60,7 +60,7 @@ interface TranslationErr {
export async function translateText(text: string, from: string | null | undefined, to: string) {
const config = useRuntimeConfig()
const status = $ref({
const status = ref({
success: false,
error: '',
text: '',
@ -77,9 +77,9 @@ export async function translateText(text: string, from: string | null | undefine
api_key: '',
},
}) as TranslationResponse
status.success = true
status.value.success = true
// replace the translated links with the original
status.text = response.translatedText.replace(regex, (match) => {
status.value.text = response.translatedText.replace(regex, (match) => {
const tagLink = regex.exec(text)
return tagLink ? tagLink[0] : match
})
@ -87,9 +87,9 @@ export async function translateText(text: string, from: string | null | undefine
catch (err) {
// TODO: improve type
if ((err as TranslationErr).data?.error)
status.error = (err as TranslationErr).data!.error!
status.value.error = (err as TranslationErr).data!.error!
else
status.error = 'Unknown Error, Please check your console in browser devtool.'
status.value.error = 'Unknown Error, Please check your console in browser devtool.'
console.error('Translate Post Error: ', err)
}
return status
@ -115,10 +115,10 @@ export function useTranslation(status: mastodon.v1.Status | mastodon.v1.StatusEd
return
if (!translation.text) {
const { success, text, error } = await translateText(status.content, status.language, to)
translation.error = error
translation.text = text
translation.success = success
const translated = await translateText(status.content, status.language, to)
translation.error = translated.value.error
translation.text = translated.value.text
translation.success = translated.value.success
}
translation.visible = !translation.visible

View file

@ -19,8 +19,8 @@ export function usePaginator<T, P, U = T>(
const prevItems = ref<T[]>([])
const endAnchor = ref<HTMLDivElement>()
const bound = reactive(useElementBounding(endAnchor))
const isInScreen = $computed(() => bound.top < window.innerHeight * 2)
const bound = useElementBounding(endAnchor)
const isInScreen = computed(() => bound.top.value < window.innerHeight * 2)
const error = ref<unknown | undefined>()
const deactivated = useDeactivated()
@ -29,11 +29,11 @@ export function usePaginator<T, P, U = T>(
prevItems.value = []
}
watch(stream, async (stream) => {
if (!stream)
watch(() => stream, async (stream) => {
if (!stream.value)
return
for await (const entry of stream) {
for await (const entry of stream.value) {
if (entry.event === 'update') {
const status = entry.payload
@ -115,11 +115,10 @@ export function usePaginator<T, P, U = T>(
})
}
watch(
() => [isInScreen, state],
watchEffect(
() => {
if (
isInScreen
isInScreen.value
&& state.value === 'idle'
// No new content is loaded when the keepAlive page enters the background
&& deactivated.value === false

View file

@ -14,7 +14,7 @@ const supportsPushNotifications = typeof window !== 'undefined'
&& 'getKey' in PushSubscription.prototype
export function usePushManager() {
const { client } = $(useMasto())
const { client } = useMasto()
const isSubscribed = ref(false)
const notificationPermission = ref<PermissionState | undefined>(
Notification.permission === 'denied'
@ -25,7 +25,7 @@ export function usePushManager() {
? 'prompt'
: undefined,
)
const isSupported = $computed(() => supportsPushNotifications)
const isSupported = computed(() => supportsPushNotifications)
const hiddenNotification = useLocalStorage<PushNotificationRequest>(STORAGE_KEY_NOTIFICATION, {})
const configuredPolicy = useLocalStorage<PushNotificationPolicy>(STORAGE_KEY_NOTIFICATION_POLICY, {})
const pushNotificationData = ref(createRawSettings(
@ -173,7 +173,7 @@ export function usePushManager() {
if (policyChanged)
await subscribe(data, policy, true)
else
currentUser.value.pushSubscription = await client.v1.push.subscription.update({ data })
currentUser.value.pushSubscription = await client.value.v1.push.subscription.update({ data })
policyChanged && await nextTick()

View file

@ -121,7 +121,7 @@ export function useSelfAccount(user: MaybeRefOrGetter<mastodon.v1.Account | unde
export const characterLimit = computed(() => currentInstance.value?.configuration?.statuses.maxCharacters ?? DEFAULT_POST_CHARS_LIMIT)
export async function loginTo(masto: ElkMasto, user: Overwrite<UserLogin, { account?: mastodon.v1.AccountCredentials }>) {
const { client } = $(masto)
const { client } = masto
const instance = mastoLogin(masto, user)
// GoToSocial only API
@ -145,11 +145,11 @@ export async function loginTo(masto: ElkMasto, user: Overwrite<UserLogin, { acco
currentUserHandle.value = account.acct
const [me, pushSubscription] = await Promise.all([
fetchAccountInfo(client, user.server),
fetchAccountInfo(client.value, user.server),
// if PWA is not enabled, don't get push subscription
useAppConfig().pwaEnabled
// we get 404 response instead empty data
? client.v1.push.subscription.fetch().catch(() => Promise.resolve(undefined))
? client.value.v1.push.subscription.fetch().catch(() => Promise.resolve(undefined))
: Promise.resolve(undefined),
])