diff --git a/src/App.vue b/src/App.vue index 8c697b5093..dd4d47f002 100644 --- a/src/App.vue +++ b/src/App.vue @@ -58,6 +58,7 @@ import AppSidebar from 'nextcloud-vue/dist/Components/AppSidebar' import AppSidebarTab from 'nextcloud-vue/dist/Components/AppSidebarTab' import Navigation from './components/Navigation/Navigation' import Router from './router/router' +import { EventBus } from './services/EventBus' export default { name: 'App', @@ -82,12 +83,30 @@ export default { computed: { conversations() { return this.$store.getters.conversations + }, + /** + * The current conversation token + * @returns {string} The token. + */ + token() { + return this.$route.params.token } }, beforeMount() { window.addEventListener('resize', this.onResize) this.onResize() + /** + * Listens to the conversationsReceived globalevent, emitted by the conversationsList + * component each time a new batch of conversations is received and processed in + * the store. + */ + EventBus.$once('conversationsReceived', () => { + if (this.$route.name === 'conversation') { + const CURRENT_CONVERSATION_NAME = this.getConversationName(this.token) + this.setPageTitle(CURRENT_CONVERSATION_NAME) + } + }) /** * Global before guard, this is called whenever a navigation is triggered. */ @@ -96,7 +115,7 @@ export default { * This runs whenever the new route is a conversation. */ if (to.name === 'conversation') { - const NEXT_CONVERSATION_NAME = this.$store.getters.conversations[to.params.token].displayName + const NEXT_CONVERSATION_NAME = this.getConversationName(to.params.token) this.setPageTitle(NEXT_CONVERSATION_NAME) } }) @@ -119,6 +138,14 @@ export default { }, log(e) { console.debug(e) + }, + /** + * Get a conversation's name. + * @param {string} token The conversation's token + * @returns {string} The conversation's name + */ + getConversationName(token) { + return this.$store.getters.conversations[token].displayName } } } diff --git a/src/components/Navigation/ConversationsList/ConversationsList.vue b/src/components/Navigation/ConversationsList/ConversationsList.vue index 3fce535e78..0aada3ce5a 100644 --- a/src/components/Navigation/ConversationsList/ConversationsList.vue +++ b/src/components/Navigation/ConversationsList/ConversationsList.vue @@ -31,6 +31,7 @@