Periodically refresh ConversationsList.

Signed-off-by: Marco Ambrosini <marcoambrosini@pm.me>
This commit is contained in:
Marco Ambrosini 2019-10-22 09:58:08 +02:00
Родитель 755ba10f33
Коммит 5e0d24766e
1 изменённых файлов: 17 добавлений и 8 удалений

Просмотреть файл

@ -45,20 +45,29 @@ export default {
return this.$store.getters.conversations
}
},
async beforeMount() {
/** Fetches the conversations from the server and then
* adds them one by one to the store.
*/
const conversations = await fetchConversations()
conversations.data.ocs.data.forEach(conversation => {
this.$store.dispatch('addConversation', conversation)
})
beforeMount() {
this.fetchConversations()
},
mounted() {
/** Refreshes the conversations every 30 seconds */
window.setInterval(() => {
this.fetchConversations()
}, 30000)
},
methods: {
handleInput(payload) {
const selectedConversationToken = payload.token
this.joinConversation(selectedConversationToken)
this.$router.push({ path: `/call/${selectedConversationToken}` })
},
async fetchConversations() {
/** Fetches the conversations from the server and then adds them one by one
* to the store.
*/
const conversations = await fetchConversations()
conversations.data.ocs.data.forEach(conversation => {
this.$store.dispatch('addConversation', conversation)
})
}
}
}