refactor: remove optional chainning & non-null assertion
This commit is contained in:
parent
4ed0b339e0
commit
8af8abfc9f
10 changed files with 26 additions and 26 deletions
|
|
@ -60,7 +60,7 @@ watchEffect(() => {
|
||||||
iconFields.value = icons
|
iconFields.value = icons
|
||||||
})
|
})
|
||||||
|
|
||||||
const isSelf = $computed(() => checkUser(currentUser.value) && currentUser.value?.account.id === account.id)
|
const isSelf = $computed(() => checkUser(currentUser.value) && currentUser.value.account.id === account.id)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ defineSlots<{
|
||||||
error: {}
|
error: {}
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const isLegacyAccount = computed(() => !currentUser.value?.vapidKey)
|
const isLegacyAccount = computed(() => !currentUser.value.vapidKey)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ let subscribeError = $ref<string>('')
|
||||||
let showSubscribeError = $ref<boolean>(false)
|
let showSubscribeError = $ref<boolean>(false)
|
||||||
|
|
||||||
const hideNotification = () => {
|
const hideNotification = () => {
|
||||||
const key = currentUser.value?.account?.acct
|
const key = currentUser.value.account?.acct
|
||||||
if (key)
|
if (key)
|
||||||
hiddenNotification.value[key] = true
|
hiddenNotification.value[key] = true
|
||||||
}
|
}
|
||||||
|
|
@ -39,7 +39,7 @@ const showWarning = $computed(() => {
|
||||||
|
|
||||||
return isSupported
|
return isSupported
|
||||||
&& (!isSubscribed.value || !notificationPermission.value || notificationPermission.value === 'prompt')
|
&& (!isSubscribed.value || !notificationPermission.value || notificationPermission.value === 'prompt')
|
||||||
&& !(hiddenNotification.value[currentUser.value?.account?.acct ?? ''] === true)
|
&& !(hiddenNotification.value[currentUser.value.account?.acct ?? ''] === true)
|
||||||
})
|
})
|
||||||
|
|
||||||
const saveSettings = async () => {
|
const saveSettings = async () => {
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ const clipboard = useClipboard()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
|
|
||||||
const isAuthor = $computed(() => checkUser(currentUser.value) && status.account.id === currentUser.value?.account.id)
|
const isAuthor = $computed(() => checkUser(currentUser.value) && status.account.id === currentUser.value.account.id)
|
||||||
|
|
||||||
const {
|
const {
|
||||||
toggle: _toggleTranslation,
|
toggle: _toggleTranslation,
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ const { account, status } = defineProps<{
|
||||||
|
|
||||||
const originalUrl = computed(() => {
|
const originalUrl = computed(() => {
|
||||||
const [handle, _server] = account.split('@')
|
const [handle, _server] = account.split('@')
|
||||||
const server = _server || currentUser.value?.server
|
const server = _server || currentUser.value.server
|
||||||
if (!server)
|
if (!server)
|
||||||
return null
|
return null
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
const paginator = useMasto().accounts.iterateStatuses(currentUser.value!.account!.id, { pinned: true })
|
const paginator = useMasto().accounts.iterateStatuses(currentUser.value.account!.id, { pinned: true })
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
|
||||||
|
|
@ -29,12 +29,12 @@ export const usePushManager = () => {
|
||||||
const hiddenNotification = useLocalStorage<PushNotificationRequest>(STORAGE_KEY_NOTIFICATION, {})
|
const hiddenNotification = useLocalStorage<PushNotificationRequest>(STORAGE_KEY_NOTIFICATION, {})
|
||||||
const configuredPolicy = useLocalStorage<PushNotificationPolicy>(STORAGE_KEY_NOTIFICATION_POLICY, {})
|
const configuredPolicy = useLocalStorage<PushNotificationPolicy>(STORAGE_KEY_NOTIFICATION_POLICY, {})
|
||||||
const pushNotificationData = ref({
|
const pushNotificationData = ref({
|
||||||
follow: currentUser.value?.pushSubscription?.alerts.follow ?? true,
|
follow: currentUser.value.pushSubscription?.alerts.follow ?? true,
|
||||||
favourite: currentUser.value?.pushSubscription?.alerts.favourite ?? true,
|
favourite: currentUser.value.pushSubscription?.alerts.favourite ?? true,
|
||||||
reblog: currentUser.value?.pushSubscription?.alerts.reblog ?? true,
|
reblog: currentUser.value.pushSubscription?.alerts.reblog ?? true,
|
||||||
mention: currentUser.value?.pushSubscription?.alerts.mention ?? true,
|
mention: currentUser.value.pushSubscription?.alerts.mention ?? true,
|
||||||
poll: currentUser.value?.pushSubscription?.alerts.poll ?? true,
|
poll: currentUser.value.pushSubscription?.alerts.poll ?? true,
|
||||||
policy: configuredPolicy.value[currentUser.value?.account?.acct ?? ''] ?? 'all',
|
policy: configuredPolicy.value[currentUser.value.account?.acct ?? ''] ?? 'all',
|
||||||
})
|
})
|
||||||
// don't clone, we're using indexeddb
|
// don't clone, we're using indexeddb
|
||||||
const { history, commit, clear } = useManualRefHistory(pushNotificationData)
|
const { history, commit, clear } = useManualRefHistory(pushNotificationData)
|
||||||
|
|
@ -49,7 +49,7 @@ export const usePushManager = () => {
|
||||||
|| current.policy !== previous.policy
|
|| current.policy !== previous.policy
|
||||||
})
|
})
|
||||||
|
|
||||||
watch(() => currentUser.value?.pushSubscription, (subscription) => {
|
watch(() => currentUser.value.pushSubscription, (subscription) => {
|
||||||
isSubscribed.value = !!subscription
|
isSubscribed.value = !!subscription
|
||||||
pushNotificationData.value = {
|
pushNotificationData.value = {
|
||||||
follow: subscription?.alerts.follow ?? false,
|
follow: subscription?.alerts.follow ?? false,
|
||||||
|
|
@ -57,7 +57,7 @@ export const usePushManager = () => {
|
||||||
reblog: subscription?.alerts.reblog ?? false,
|
reblog: subscription?.alerts.reblog ?? false,
|
||||||
mention: subscription?.alerts.mention ?? false,
|
mention: subscription?.alerts.mention ?? false,
|
||||||
poll: subscription?.alerts.poll ?? false,
|
poll: subscription?.alerts.poll ?? false,
|
||||||
policy: configuredPolicy.value[currentUser.value?.account?.acct ?? ''] ?? 'all',
|
policy: configuredPolicy.value[currentUser.value.account?.acct ?? ''] ?? 'all',
|
||||||
}
|
}
|
||||||
}, { immediate: true, flush: 'post' })
|
}, { immediate: true, flush: 'post' })
|
||||||
|
|
||||||
|
|
@ -87,7 +87,7 @@ export const usePushManager = () => {
|
||||||
return 'notification-denied'
|
return 'notification-denied'
|
||||||
}
|
}
|
||||||
|
|
||||||
currentUser.value!.pushSubscription = await createPushSubscription(
|
currentUser.value.pushSubscription = await createPushSubscription(
|
||||||
{ pushSubscription, server, token, vapidKey },
|
{ pushSubscription, server, token, vapidKey },
|
||||||
notificationData ?? {
|
notificationData ?? {
|
||||||
alerts: {
|
alerts: {
|
||||||
|
|
@ -126,9 +126,9 @@ export const usePushManager = () => {
|
||||||
commit()
|
commit()
|
||||||
|
|
||||||
if (policy)
|
if (policy)
|
||||||
configuredPolicy.value[currentUser.value!.account.acct ?? ''] = policy
|
configuredPolicy.value[currentUser.value.account.acct ?? ''] = policy
|
||||||
else
|
else
|
||||||
configuredPolicy.value[currentUser.value!.account.acct ?? ''] = pushNotificationData.value.policy
|
configuredPolicy.value[currentUser.value.account.acct ?? ''] = pushNotificationData.value.policy
|
||||||
|
|
||||||
await nextTick()
|
await nextTick()
|
||||||
clear()
|
clear()
|
||||||
|
|
@ -147,7 +147,7 @@ export const usePushManager = () => {
|
||||||
current.follow = previous.follow
|
current.follow = previous.follow
|
||||||
current.poll = previous.poll
|
current.poll = previous.poll
|
||||||
current.policy = previous.policy
|
current.policy = previous.policy
|
||||||
configuredPolicy.value[currentUser.value!.account.acct ?? ''] = previous.policy
|
configuredPolicy.value[currentUser.value.account.acct ?? ''] = previous.policy
|
||||||
commit()
|
commit()
|
||||||
clear()
|
clear()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ function mentionHTML(acct: string) {
|
||||||
|
|
||||||
export function getReplyDraft(status: Status) {
|
export function getReplyDraft(status: Status) {
|
||||||
const accountsToMention: string[] = []
|
const accountsToMention: string[] = []
|
||||||
const userId = currentUser.value!.account!.id
|
const userId = currentUser.value.account!.id
|
||||||
if (status.account.id !== userId)
|
if (status.account.id !== userId)
|
||||||
accountsToMention.push(status.account.acct)
|
accountsToMention.push(status.account.acct)
|
||||||
accountsToMention.push(...(status.mentions.filter(mention => mention.id !== userId).map(mention => mention.acct)))
|
accountsToMention.push(...(status.mentions.filter(mention => mention.id !== userId).map(mention => mention.acct)))
|
||||||
|
|
|
||||||
|
|
@ -261,7 +261,7 @@ export async function signout() {
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
// Clear stale data
|
// Clear stale data
|
||||||
clearUserLocalStorage()
|
clearUserLocalStorage()
|
||||||
if (!users.value.some((u, i) => u.server === currentUser.value!.server && i !== index))
|
if (!users.value.some((u, i) => u.server === currentUser.value.server && i !== index))
|
||||||
delete instances.value[currentUser.value.server]
|
delete instances.value[currentUser.value.server]
|
||||||
|
|
||||||
if (checkUser(currentUser.value)) {
|
if (checkUser(currentUser.value)) {
|
||||||
|
|
@ -284,7 +284,7 @@ export async function signout() {
|
||||||
const notifications = reactive<Record<string, undefined | [Promise<WsEvents>, number]>>({})
|
const notifications = reactive<Record<string, undefined | [Promise<WsEvents>, number]>>({})
|
||||||
|
|
||||||
export const useNotifications = () => {
|
export const useNotifications = () => {
|
||||||
const id = $computed(() => currentUser.value?.account?.id)
|
const id = $computed(() => currentUser.value.account?.id)
|
||||||
const masto = useMasto()
|
const masto = useMasto()
|
||||||
|
|
||||||
const clearNotifications = () => {
|
const clearNotifications = () => {
|
||||||
|
|
@ -294,7 +294,7 @@ export const useNotifications = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function connect(): Promise<void> {
|
async function connect(): Promise<void> {
|
||||||
if (!isMastoInitialised.value || !id || notifications[id] || !currentUser.value?.token)
|
if (!isMastoInitialised.value || !id || notifications[id] || !currentUser.value.token)
|
||||||
return
|
return
|
||||||
|
|
||||||
const stream = masto.stream.streamUser()
|
const stream = masto.stream.streamUser()
|
||||||
|
|
@ -344,7 +344,7 @@ export function useUserLocalStorage<T extends object>(key: string, initial: () =
|
||||||
return computed(() => {
|
return computed(() => {
|
||||||
const id = currentUser.value.guest
|
const id = currentUser.value.guest
|
||||||
? GUEST_ID
|
? GUEST_ID
|
||||||
: currentUser.value!.account!.acct
|
: currentUser.value.account!.acct
|
||||||
all.value[id] = Object.assign(initial(), all.value[id] || {})
|
all.value[id] = Object.assign(initial(), all.value[id] || {})
|
||||||
return all.value[id]
|
return all.value[id]
|
||||||
})
|
})
|
||||||
|
|
@ -355,7 +355,7 @@ export function useUserLocalStorage<T extends object>(key: string, initial: () =
|
||||||
*/
|
*/
|
||||||
export function clearUserLocalStorage(account?: Account) {
|
export function clearUserLocalStorage(account?: Account) {
|
||||||
if (!account)
|
if (!account)
|
||||||
account = currentUser.value?.account
|
account = currentUser.value.account
|
||||||
if (!account)
|
if (!account)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ useHeadFixed({
|
||||||
title: () => `${t('settings.profile.appearance.title')} | ${t('nav.settings')}`,
|
title: () => `${t('settings.profile.appearance.title')} | ${t('nav.settings')}`,
|
||||||
})
|
})
|
||||||
|
|
||||||
const account = $computed(() => currentUser.value?.account)
|
const account = $computed(() => currentUser.value.account)
|
||||||
|
|
||||||
const onlineSrc = $computed(() => ({
|
const onlineSrc = $computed(() => ({
|
||||||
avatar: account?.avatar || '',
|
avatar: account?.avatar || '',
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue