@@ -2,17 +2,23 @@ import { ActionContext } from 'vuex'
22import axios from '~/plugins/axios'
33import { MessageThread } from '~/models/message-thread'
44import { Message } from '~/models/message'
5+ import { Heartbeat } from '~/models/heartbeat'
6+ import { compile } from 'vue-template-compiler'
57
68type State = {
79 owner : string
810 threads : Array < MessageThread >
911 threadId : string | null
12+ heartbeat : null | Heartbeat
13+ pooling : boolean
1014 threadMessages : Array < Message >
1115}
1216
1317export const state = ( ) : State => ( {
1418 threads : [ ] ,
1519 threadId : null ,
20+ heartbeat : null ,
21+ pooling : false ,
1622 threadMessages : [ ] ,
1723 owner : '+37259139660' ,
1824} )
@@ -40,6 +46,14 @@ export const getters = {
4046 }
4147 return thread
4248 } ,
49+
50+ getHeartbeat ( state : State ) : Heartbeat | null {
51+ return state . heartbeat
52+ } ,
53+
54+ getPolling ( state : State ) : boolean {
55+ return state . pooling
56+ } ,
4357}
4458
4559export const mutations = {
@@ -52,6 +66,12 @@ export const mutations = {
5266 setThreadMessages ( state : State , payload : Array < Message > ) {
5367 state . threadMessages = payload
5468 } ,
69+ setHeartbeat ( state : State , payload : Heartbeat | null ) {
70+ state . heartbeat = payload
71+ } ,
72+ setPooling ( state : State , payload : boolean ) {
73+ state . pooling = payload
74+ } ,
5575}
5676
5777export type SendMessageRequest = {
@@ -70,6 +90,26 @@ export const actions = {
7090 context . commit ( 'setThreads' , response . data . data )
7191 } ,
7292
93+ async getHeartbeat ( context : ActionContext < State , State > ) {
94+ const response = await axios . get ( '/v1/heartbeats' , {
95+ params : {
96+ limit : 1 ,
97+ owner : context . getters . getOwner ,
98+ } ,
99+ } )
100+
101+ if ( response . data . data . length > 0 ) {
102+ context . commit ( 'setHeartbeat' , response . data . data [ 0 ] )
103+ return
104+ }
105+
106+ context . commit ( 'setHeartbeat' , null )
107+ } ,
108+
109+ setPolling ( context : ActionContext < State , State > , status : boolean ) {
110+ context . commit ( 'setPooling' , status )
111+ } ,
112+
73113 async sendMessage (
74114 context : ActionContext < State , State > ,
75115 request : SendMessageRequest
0 commit comments