@@ -18,6 +18,7 @@ import {
1818import Pusher from ' pusher-js'
1919import type { Channel } from ' pusher-js'
2020import { isValidPhoneNumber } from ' libphonenumber-js'
21+ import { storeToRefs } from ' pinia'
2122import type { EntitiesMessage } from ' ~~/shared/types/api'
2223
2324definePageMeta ({
@@ -31,13 +32,14 @@ useHead({
3132const route = useRoute ()
3233const router = useRouter ()
3334const config = useRuntimeConfig ()
34- const { lgAndUp, mdAndDown, mdAndUp } = useDisplay ()
35+ const { lgAndUp, mdAndDown, mdAndUp } = useVDisplay ()
3536const { formatPhoneNumber, startsWithLetter } = useFilters ()
3637const notificationsStore = useNotificationsStore ()
3738const authStore = useAuthStore ()
3839const phonesStore = usePhonesStore ()
3940const threadsStore = useThreadsStore ()
4041const messagesStore = useMessagesStore ()
42+ const { currentThread } = storeToRefs (threadsStore )
4143
4244const formMessage = ref (' ' )
4345const submitting = ref (false )
@@ -58,15 +60,15 @@ const formMessageRules = [
5860let webhookChannel: Channel | null = null
5961
6062const contactIsPhoneNumber = computed (() => {
61- const thread = threadsStore . currentThread
63+ const thread = currentThread . value
6264 if (! thread ) return false
6365 return isValidPhoneNumber (thread .contact ) || ! isNaN (Number (thread .contact ))
6466})
6567
6668const messageVisibility = computed (() =>
6769 hideMessages .value ? ' hidden' : ' visible' ,
6870)
69- const contact = computed (() => threadsStore . currentThread ?.contact ?? ' ' )
71+ const contact = computed (() => currentThread . value ?.contact ?? ' ' )
7072
7173function isMT(message : EntitiesMessage ): boolean {
7274 return message .type === ' mobile-terminated'
@@ -104,7 +106,7 @@ function formatAttachmentName(url: string): string {
104106}
105107
106108function currentThreadContactTitle(): string {
107- const thread = threadsStore . currentThread
109+ const thread = currentThread . value
108110 if (! thread ) return ' '
109111 return (
110112 thread .contact_details ?.name ?.trim () || formatPhoneNumber (thread .contact )
@@ -162,15 +164,15 @@ async function loadData() {
162164
163165async function archiveThread() {
164166 await threadsStore .updateThread ({
165- threadId: threadsStore . currentThread ! .id ,
167+ threadId: currentThread . value ! .id ,
166168 isArchived: true ,
167169 })
168170 await router .push (' /threads' )
169171}
170172
171173async function unArchiveThread() {
172174 await threadsStore .updateThread ({
173- threadId: threadsStore . currentThread ! .id ,
175+ threadId: currentThread . value ! .id ,
174176 isArchived: false ,
175177 })
176178 await router .push (' /threads' )
@@ -225,7 +227,7 @@ async function sendMessage(event: KeyboardEvent | Event) {
225227 submitting .value = true
226228 await messagesStore .sendMessage ({
227229 from: phonesStore .owner ! ,
228- to: threadsStore . currentThread ! .contact ,
230+ to: currentThread . value ! .contact ,
229231 content: formMessage .value ,
230232 sim: ' DEFAULT' ,
231233 })
@@ -274,7 +276,7 @@ onBeforeUnmount(() => {
274276 <VBtn v-if =" mdAndDown " icon to="/threads">
275277 <VIcon :icon =" mdiArrowLeft " />
276278 </VBtn >
277- <VToolbarTitle v-if =" threadsStore . currentThread " >
279+ <VToolbarTitle v-if =" currentThread " >
278280 {{ currentThreadContactTitle() }}
279281 </VToolbarTitle >
280282 <VMenu >
@@ -289,10 +291,7 @@ onBeforeUnmount(() => {
289291 :density =" mdAndDown ? ' compact' : ' default' "
290292 >
291293 <VListItem
292- v-if ="
293- threadsStore .currentThread &&
294- ! threadsStore .currentThread .is_archived
295- "
294+ v-if =" currentThread && ! currentThread .is_archived "
296295 @click .prevent =" archiveThread "
297296 >
298297 <template #prepend >
@@ -301,10 +300,7 @@ onBeforeUnmount(() => {
301300 <VListItemTitle >Archive</VListItemTitle >
302301 </VListItem >
303302 <VListItem
304- v-if ="
305- threadsStore .currentThread &&
306- threadsStore .currentThread .is_archived
307- "
303+ v-if =" currentThread && currentThread .is_archived "
308304 @click .prevent =" unArchiveThread "
309305 >
310306 <template #prepend >
@@ -313,8 +309,8 @@ onBeforeUnmount(() => {
313309 <VListItemTitle >Unarchive</VListItemTitle >
314310 </VListItem >
315311 <VListItem
316- v-if =" threadsStore . currentThread "
317- @click .prevent =" deleteThread (threadsStore . currentThread .id )"
312+ v-if =" currentThread "
313+ @click .prevent =" deleteThread (currentThread .id )"
318314 >
319315 <template #prepend >
320316 <VIcon :icon =" mdiDelete " color="error" />
@@ -330,7 +326,7 @@ onBeforeUnmount(() => {
330326 color="primary"
331327 indeterminate
332328 />
333- <VContainer v-if =" threadsStore . currentThread " class="pa-0">
329+ <VContainer v-if =" currentThread " class="pa-0">
334330 <div
335331 ref =" messageBody"
336332 class =" messages-body no-scrollbar w-100 pl-2"
@@ -357,7 +353,7 @@ onBeforeUnmount(() => {
357353 'ml-2': !mdAndUp,
358354 'ml-4': mdAndUp,
359355 }"
360- :color =" threadsStore. currentThread! .color"
356+ :color =" currentThread.color"
361357 size =" 40"
362358 >
363359 <v-icon
0 commit comments