Skip to content

Commit 56b8fc8

Browse files
committed
Add message loading
1 parent 92ecdfc commit 56b8fc8

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

web/layouts/default.vue

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,6 @@ export default class DefaultLayout extends Vue {
5050
channel.bind('phone.updated', () => {
5151
this.canPoll = true
5252
})
53-
channel.bind('message.phone.sent', () => {
54-
this.canPoll = true
55-
})
56-
channel.bind('message.send.failed', () => {
57-
this.canPoll = true
58-
})
5953
6054
this.startPoller()
6155
}, 10_000) // delay so that the auth user is present
@@ -79,21 +73,12 @@ export default class DefaultLayout extends Vue {
7973
if (this.$store.getters.getAuthUser && this.$store.getters.getOwner) {
8074
setAuthHeader((await this.$fire.auth.currentUser?.getIdToken()) ?? '')
8175
promises.push(
76+
promises.push(this.$store.dispatch('loadPhones', true)),
8277
this.$store.dispatch('loadThreads'),
8378
this.$store.dispatch('getHeartbeat'),
8479
)
8580
}
86-
promises.push(this.$store.dispatch('loadPhones', true))
87-
8881
this.canPoll = false
89-
if (this.$store.getters.hasThread) {
90-
promises.push(
91-
this.$store.dispatch(
92-
'loadThreadMessages',
93-
this.$store.getters.getThread.id,
94-
),
95-
)
96-
}
9782
await Promise.all(promises)
9883
9984
setTimeout(() => {

web/pages/threads/_id/index.vue

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ import {
343343
mdiSim,
344344
mdiContentCopy,
345345
} from '@mdi/js'
346+
import Pusher, { Channel } from 'pusher-js'
346347
import { Message } from '~/models/message'
347348
import { NotificationRequest, SendMessageRequest, SIM } from '~/store'
348349
@@ -382,6 +383,7 @@ export default Vue.extend({
382383
formMessage: '',
383384
formMessageRules,
384385
submitting: false,
386+
webhookChannel: null as Channel | null,
385387
selectedMenuItem: -1,
386388
}
387389
},
@@ -410,6 +412,27 @@ export default Vue.extend({
410412
411413
async mounted() {
412414
await this.loadData()
415+
416+
const pusher = new Pusher(this.$config.pusherKey, {
417+
cluster: this.$config.pusherCluster,
418+
})
419+
this.webhookChannel = pusher.subscribe(this.$store.getters.getAuthUser.id)
420+
this.webhookChannel.bind('message.phone.sent', () => {
421+
if (!this.loadingMessages) {
422+
this.loadMessages(false)
423+
}
424+
})
425+
this.webhookChannel.bind('message.send.failed', () => {
426+
if (!this.loadingMessages) {
427+
this.loadMessages(false)
428+
}
429+
})
430+
},
431+
432+
beforeDestroy() {
433+
if (this.webhookChannel) {
434+
this.webhookChannel.unsubscribe()
435+
}
413436
},
414437
415438
methods: {

0 commit comments

Comments
 (0)