forked from Mirrors/elk
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
|
||||
})
|
||||
|
||||
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>
|
||||
|
||||
<template>
|
||||
|
|
|
@ -12,7 +12,7 @@ defineSlots<{
|
|||
error: {}
|
||||
}>()
|
||||
|
||||
const isLegacyAccount = computed(() => !currentUser.value?.vapidKey)
|
||||
const isLegacyAccount = computed(() => !currentUser.value.vapidKey)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
|
|
@ -28,7 +28,7 @@ let subscribeError = $ref<string>('')
|
|||
let showSubscribeError = $ref<boolean>(false)
|
||||
|
||||
const hideNotification = () => {
|
||||
const key = currentUser.value?.account?.acct
|
||||
const key = currentUser.value.account?.acct
|
||||
if (key)
|
||||
hiddenNotification.value[key] = true
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ const showWarning = $computed(() => {
|
|||
|
||||
return isSupported
|
||||
&& (!isSubscribed.value || !notificationPermission.value || notificationPermission.value === 'prompt')
|
||||
&& !(hiddenNotification.value[currentUser.value?.account?.acct ?? ''] === true)
|
||||
&& !(hiddenNotification.value[currentUser.value.account?.acct ?? ''] === true)
|
||||
})
|
||||
|
||||
const saveSettings = async () => {
|
||||
|
|
|
@ -23,7 +23,7 @@ const clipboard = useClipboard()
|
|||
const router = useRouter()
|
||||
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 {
|
||||
toggle: _toggleTranslation,
|
||||
|
|
|
@ -6,7 +6,7 @@ const { account, status } = defineProps<{
|
|||
|
||||
const originalUrl = computed(() => {
|
||||
const [handle, _server] = account.split('@')
|
||||
const server = _server || currentUser.value?.server
|
||||
const server = _server || currentUser.value.server
|
||||
if (!server)
|
||||
return null
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<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>
|
||||
|
||||
<template>
|
||||
|
|
|
@ -29,12 +29,12 @@ export const usePushManager = () => {
|
|||
const hiddenNotification = useLocalStorage<PushNotificationRequest>(STORAGE_KEY_NOTIFICATION, {})
|
||||
const configuredPolicy = useLocalStorage<PushNotificationPolicy>(STORAGE_KEY_NOTIFICATION_POLICY, {})
|
||||
const pushNotificationData = ref({
|
||||
follow: currentUser.value?.pushSubscription?.alerts.follow ?? true,
|
||||
favourite: currentUser.value?.pushSubscription?.alerts.favourite ?? true,
|
||||
reblog: currentUser.value?.pushSubscription?.alerts.reblog ?? true,
|
||||
mention: currentUser.value?.pushSubscription?.alerts.mention ?? true,
|
||||
poll: currentUser.value?.pushSubscription?.alerts.poll ?? true,
|
||||
policy: configuredPolicy.value[currentUser.value?.account?.acct ?? ''] ?? 'all',
|
||||
follow: currentUser.value.pushSubscription?.alerts.follow ?? true,
|
||||
favourite: currentUser.value.pushSubscription?.alerts.favourite ?? true,
|
||||
reblog: currentUser.value.pushSubscription?.alerts.reblog ?? true,
|
||||
mention: currentUser.value.pushSubscription?.alerts.mention ?? true,
|
||||
poll: currentUser.value.pushSubscription?.alerts.poll ?? true,
|
||||
policy: configuredPolicy.value[currentUser.value.account?.acct ?? ''] ?? 'all',
|
||||
})
|
||||
// don't clone, we're using indexeddb
|
||||
const { history, commit, clear } = useManualRefHistory(pushNotificationData)
|
||||
|
@ -49,7 +49,7 @@ export const usePushManager = () => {
|
|||
|| current.policy !== previous.policy
|
||||
})
|
||||
|
||||
watch(() => currentUser.value?.pushSubscription, (subscription) => {
|
||||
watch(() => currentUser.value.pushSubscription, (subscription) => {
|
||||
isSubscribed.value = !!subscription
|
||||
pushNotificationData.value = {
|
||||
follow: subscription?.alerts.follow ?? false,
|
||||
|
@ -57,7 +57,7 @@ export const usePushManager = () => {
|
|||
reblog: subscription?.alerts.reblog ?? false,
|
||||
mention: subscription?.alerts.mention ?? 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' })
|
||||
|
||||
|
@ -87,7 +87,7 @@ export const usePushManager = () => {
|
|||
return 'notification-denied'
|
||||
}
|
||||
|
||||
currentUser.value!.pushSubscription = await createPushSubscription(
|
||||
currentUser.value.pushSubscription = await createPushSubscription(
|
||||
{ pushSubscription, server, token, vapidKey },
|
||||
notificationData ?? {
|
||||
alerts: {
|
||||
|
@ -126,9 +126,9 @@ export const usePushManager = () => {
|
|||
commit()
|
||||
|
||||
if (policy)
|
||||
configuredPolicy.value[currentUser.value!.account.acct ?? ''] = policy
|
||||
configuredPolicy.value[currentUser.value.account.acct ?? ''] = policy
|
||||
else
|
||||
configuredPolicy.value[currentUser.value!.account.acct ?? ''] = pushNotificationData.value.policy
|
||||
configuredPolicy.value[currentUser.value.account.acct ?? ''] = pushNotificationData.value.policy
|
||||
|
||||
await nextTick()
|
||||
clear()
|
||||
|
@ -147,7 +147,7 @@ export const usePushManager = () => {
|
|||
current.follow = previous.follow
|
||||
current.poll = previous.poll
|
||||
current.policy = previous.policy
|
||||
configuredPolicy.value[currentUser.value!.account.acct ?? ''] = previous.policy
|
||||
configuredPolicy.value[currentUser.value.account.acct ?? ''] = previous.policy
|
||||
commit()
|
||||
clear()
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ function mentionHTML(acct: string) {
|
|||
|
||||
export function getReplyDraft(status: Status) {
|
||||
const accountsToMention: string[] = []
|
||||
const userId = currentUser.value!.account!.id
|
||||
const userId = currentUser.value.account!.id
|
||||
if (status.account.id !== userId)
|
||||
accountsToMention.push(status.account.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) {
|
||||
// Clear stale data
|
||||
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]
|
||||
|
||||
if (checkUser(currentUser.value)) {
|
||||
|
@ -284,7 +284,7 @@ export async function signout() {
|
|||
const notifications = reactive<Record<string, undefined | [Promise<WsEvents>, number]>>({})
|
||||
|
||||
export const useNotifications = () => {
|
||||
const id = $computed(() => currentUser.value?.account?.id)
|
||||
const id = $computed(() => currentUser.value.account?.id)
|
||||
const masto = useMasto()
|
||||
|
||||
const clearNotifications = () => {
|
||||
|
@ -294,7 +294,7 @@ export const useNotifications = () => {
|
|||
}
|
||||
|
||||
async function connect(): Promise<void> {
|
||||
if (!isMastoInitialised.value || !id || notifications[id] || !currentUser.value?.token)
|
||||
if (!isMastoInitialised.value || !id || notifications[id] || !currentUser.value.token)
|
||||
return
|
||||
|
||||
const stream = masto.stream.streamUser()
|
||||
|
@ -344,7 +344,7 @@ export function useUserLocalStorage<T extends object>(key: string, initial: () =
|
|||
return computed(() => {
|
||||
const id = currentUser.value.guest
|
||||
? GUEST_ID
|
||||
: currentUser.value!.account!.acct
|
||||
: currentUser.value.account!.acct
|
||||
all.value[id] = Object.assign(initial(), 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) {
|
||||
if (!account)
|
||||
account = currentUser.value?.account
|
||||
account = currentUser.value.account
|
||||
if (!account)
|
||||
return
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ useHeadFixed({
|
|||
title: () => `${t('settings.profile.appearance.title')} | ${t('nav.settings')}`,
|
||||
})
|
||||
|
||||
const account = $computed(() => currentUser.value?.account)
|
||||
const account = $computed(() => currentUser.value.account)
|
||||
|
||||
const onlineSrc = $computed(() => ({
|
||||
avatar: account?.avatar || '',
|
||||
|
|
Loading…
Reference in a new issue