2929<script lang="ts">
3030import { Vue , Component } from ' vue-property-decorator'
3131import { mdiBullhorn } from ' @mdi/js'
32+ import Pusher from ' pusher-js'
3233import { setAuthHeader } from ' ~/plugins/axios'
3334
3435@Component
@@ -41,15 +42,18 @@ export default class DefaultLayout extends Vue {
4142 }
4243
4344 mounted() {
44- // this.startPoller()
45- setTimeout (
46- () => {
47- if (this .poller ) {
48- clearInterval (this .poller )
49- }
50- },
51- 60 * 1000 * 60 ,
52- )
45+ setTimeout (() => {
46+ const pusher = new Pusher (this .$config .pusherKey , {
47+ cluster: this .$config .pusherCluster ,
48+ })
49+
50+ const channel = pusher .subscribe (this .$store .getters .getAuthUser .id )
51+ channel .bind (' phone.updated' , () => {
52+ this .$store .dispatch (' setCanPoll' , true )
53+ })
54+
55+ this .startPoller ()
56+ }, 5000 ) // delay so that the auth user is present
5357 }
5458
5559 beforeDestroy(): void {
@@ -60,6 +64,13 @@ export default class DefaultLayout extends Vue {
6064
6165 startPoller() {
6266 this .poller = window .setInterval (async () => {
67+ if (
68+ ! this .$store .getters .getCanPoll ||
69+ this .$store .getters .getAuthUser == null
70+ ) {
71+ return
72+ }
73+
6374 await this .$store .dispatch (' setPolling' , true )
6475
6576 const promises = []
@@ -70,12 +81,12 @@ export default class DefaultLayout extends Vue {
7081 this .$store .dispatch (' getHeartbeat' ),
7182 )
7283 }
84+ promises .push (
85+ this .$store .dispatch (' loadPhones' , true ),
86+ this .$store .dispatch (' setCanPoll' , false ),
87+ )
7388
74- if (this .$store .getters .getAuthUser ) {
75- promises .push (this .$store .dispatch (' loadPhones' , true ))
76- }
77-
78- if (this .$store .getters .hasThread && this .$store .getters .getUser ) {
89+ if (this .$store .getters .hasThread ) {
7990 promises .push (
8091 this .$store .dispatch (
8192 ' loadThreadMessages' ,
0 commit comments