diff --git a/src/FilesSidebarTabLoader.vue b/src/FilesSidebarTabLoader.vue
new file mode 100644
index 00000000000..e6a8d568597
--- /dev/null
+++ b/src/FilesSidebarTabLoader.vue
@@ -0,0 +1,80 @@
+
+
+
+
+
+
+
+
diff --git a/src/mainFilesSidebar.js b/src/mainFilesSidebar.js
index 1809fb42baf..0f911f697dd 100644
--- a/src/mainFilesSidebar.js
+++ b/src/mainFilesSidebar.js
@@ -9,14 +9,13 @@ import VueObserveVisibility from 'vue-observe-visibility'
import VueShortKey from 'vue-shortkey'
import Vuex from 'vuex'
-import { getRequestToken } from '@nextcloud/auth'
-import { generateFilePath } from '@nextcloud/router'
-
import FilesSidebarCallViewApp from './FilesSidebarCallViewApp.vue'
import FilesSidebarTabApp from './FilesSidebarTabApp.vue'
import './init.js'
+import PrivateTalk from './mainFilesSidebarLoader.js'
import store from './store/index.js'
+import FilesSidebarCallView from './views/FilesSidebarCallView.js'
// Leaflet icon patch
import 'leaflet/dist/leaflet.css'
@@ -25,17 +24,6 @@ import 'leaflet-defaulticon-compatibility/dist/leaflet-defaulticon-compatibility
// eslint-disable-next-line
import 'leaflet-defaulticon-compatibility'
-// CSP config for webpack dynamic chunk loading
-// eslint-disable-next-line
-__webpack_nonce__ = btoa(getRequestToken())
-
-// Correct the root of the app for chunk loading
-// OC.linkTo matches the apps folders
-// OC.generateUrl ensure the index.php (or not)
-// We do not want the index.php since we're loading files
-// eslint-disable-next-line
-__webpack_public_path__ = generateFilePath('spreed', '', 'js/')
-
Vue.prototype.OC = OC
Vue.prototype.OCA = OCA
@@ -61,12 +49,16 @@ const newTab = () => new Vue({
render: h => h(FilesSidebarTabApp),
})
-if (!window.OCA.Talk) {
- window.OCA.Talk = {}
-}
Object.assign(window.OCA.Talk, {
- fileInfo: null,
newCallView,
newTab,
store,
})
+
+export const mountSidebar = (mountEl) => {
+ if (OCA.Files?.Sidebar) {
+ OCA.Files.Sidebar.registerSecondaryView(new FilesSidebarCallView())
+ PrivateTalk.tabInstance = OCA.Talk.newTab()
+ PrivateTalk.tabInstance.$mount(mountEl)
+ }
+}
diff --git a/src/mainFilesSidebarLoader.js b/src/mainFilesSidebarLoader.js
index 1b30b2a0a3a..5376c53b19c 100644
--- a/src/mainFilesSidebarLoader.js
+++ b/src/mainFilesSidebarLoader.js
@@ -3,24 +3,47 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
-import './init.js'
-import FilesSidebarCallView from './views/FilesSidebarCallView.js'
+import Vue from 'vue'
+
+import { getRequestToken } from '@nextcloud/auth'
+import { generateFilePath } from '@nextcloud/router'
+
+import FilesSidebarTabLoader from './FilesSidebarTabLoader.vue'
+
+// CSP config for webpack dynamic chunk loading
+// eslint-disable-next-line
+__webpack_nonce__ = btoa(getRequestToken())
+
+// Correct the root of the app for chunk loading
+// OC.linkTo matches the apps folders
+// OC.generateUrl ensure the index.php (or not)
+// We do not want the index.php since we're loading files
+// eslint-disable-next-line
+__webpack_public_path__ = generateFilePath('spreed', '', 'js/')
+
+Vue.prototype.OC = OC
+Vue.prototype.OCA = OCA
+
+const loaderTab = () => new Vue({
+ id: 'talk-chat-tab',
+ render: h => h(FilesSidebarTabLoader),
+})
const isEnabled = function(fileInfo) {
if (fileInfo && !fileInfo.isDirectory()) {
return true
}
- const token = OCA.Talk.store.getters.getToken()
+ const token = OCA.Talk.store?.getters.getToken()
// If the Talk tab can not be displayed then the current conversation is
// left; this must be done here because "setFileInfo" will not get
// called with the new file if the tab can not be displayed.
if (token) {
- OCA.Talk.store.dispatch('leaveConversation', { token })
+ OCA.Talk.store?.dispatch('leaveConversation', { token })
}
- OCA.Talk.store.dispatch('updateTokenAndFileIdForToken', {
+ OCA.Talk.store?.dispatch('updateTokenAndFileIdForToken', {
newToken: null,
newFileId: null,
})
@@ -28,16 +51,26 @@ const isEnabled = function(fileInfo) {
return false
}
+if (!window.OCA.Talk) {
+ window.OCA.Talk = {}
+}
+Object.assign(window.OCA.Talk, {
+ fileInfo: null,
+ loaderTab,
+ isFirstLoad: true,
+})
+
// It might be enough to keep the instance only in the Tab object itself,
// without using a shared variable that can be destroyed if a new tab is
// mounted and the previous one was not destroyed yet, as the tabs seem to
// always be properly destroyed. However, this is how it is done for tabs in
// server, so it is done here too just to be safe.
-let tabInstance = null
+const PrivateTalk = {
+ tabInstance: null,
+}
window.addEventListener('DOMContentLoaded', () => {
if (OCA.Files && OCA.Files.Sidebar) {
- OCA.Files.Sidebar.registerSecondaryView(new FilesSidebarCallView())
OCA.Files.Sidebar.registerTab(new OCA.Files.Sidebar.Tab({
id: 'chat',
name: t('spreed', 'Chat'),
@@ -45,8 +78,8 @@ window.addEventListener('DOMContentLoaded', () => {
enabled: isEnabled,
async mount(el, fileInfo, context) {
- if (tabInstance) {
- tabInstance.$destroy()
+ if (PrivateTalk.tabInstance) {
+ PrivateTalk.tabInstance.$destroy()
}
// Dirty hack to force the style on parent component
@@ -56,17 +89,23 @@ window.addEventListener('DOMContentLoaded', () => {
tabChat.style.padding = '0'
OCA.Talk.fileInfo = this.fileInfo
- tabInstance = OCA.Talk.newTab()
- tabInstance.$mount(el)
+ if (OCA.Talk.isFirstLoad === true) {
+ PrivateTalk.tabInstance = OCA.Talk.loaderTab()
+ } else {
+ PrivateTalk.tabInstance = OCA.Talk.newTab()
+ }
+ PrivateTalk.tabInstance.$mount(el)
},
update(fileInfo) {
OCA.Talk.fileInfo = fileInfo
},
destroy() {
OCA.Talk.fileInfo = null
- tabInstance.$destroy()
- tabInstance = null
+ PrivateTalk.tabInstance.$destroy()
+ PrivateTalk.tabInstance = null
},
}))
}
})
+
+export default PrivateTalk
diff --git a/webpack.config.js b/webpack.config.js
index 699b1dfd4c0..55cf6b335cf 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -27,7 +27,6 @@ module.exports = mergeWithRules({
main: path.join(__dirname, 'src', 'main.js'),
recording: path.join(__dirname, 'src', 'mainRecording.js'),
'files-sidebar': [
- path.join(__dirname, 'src', 'mainFilesSidebar.js'),
path.join(__dirname, 'src', 'mainFilesSidebarLoader.js'),
],
'public-share-auth-sidebar': path.join(__dirname, 'src', 'mainPublicShareAuthSidebar.js'),