Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 60 additions & 2 deletions src/FilesSidebarTabApp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,79 @@
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<template>
<p>Talk tab coming soon</p>
<MainView :token="token" />
</template>

<script>

import { getFileConversation } from './services/filesIntegrationServices'
import CancelableRequest from './utils/cancelableRequest'
import MainView from './views/MainView'
import Axios from '@nextcloud/axios'

export default {

name: 'FilesSidebarTabApp',

components: {
MainView,
},

data() {
return {
// needed for reactivity
Talk: OCA.Talk,
/**
* Stores the cancel function returned by `cancelableLookForNewMessages`,
*/
cancelGetFileConversation: () => {},
}
},

computed: {
fileInfo() {
return this.Talk.fileInfo
return this.Talk.fileInfo || {}
},
fileId() {
return this.fileInfo.id || {}
},
token() {
if (this.$store.getters.getToken()) {
return this.$store.getters.getToken()
} else {
return ''
}
},
},

mounted() {
console.log(this.fileInfo)
this.getFileConversation()
},

methods: {
async getFileConversation() {
/**
* Clear previous requests if there's one pending
*/
this.cancelGetFileConversation('canceled')
debugger
// Get a new cancelable request function and cancel function pair
const { request, cancel } = CancelableRequest(getFileConversation)
// Assign the new cancel function to our data value
this.cancelGetFileConversation = cancel
// Make the request
try {
const response = await request({ fileId: this.fileId } )
console.log(response)
this.$store.dispatch('updateToken', response.data.ocs.data.token)

} catch (exception) {
console.debug(exception)
if (Axios.isCancel(exception)) {
console.debug('The request has been canceled', exception)
}
}
},
},
}
Expand Down
40 changes: 40 additions & 0 deletions src/services/filesIntegrationServices.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* @copyright Copyright (c) 2019 Marco Ambrosini <[email protected]>
*
* @author Marco Ambrosini <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

import axios from '@nextcloud/axios'
import { generateOcsUrl } from '@nextcloud/router'

/**
* Gets the conversation token for a given file id
*/
const getFileConversation = async function({ fileId }, options) {
try {
const response = await axios.get(generateOcsUrl('apps/spreed/api/v1', 2) + `file/${fileId}`)
return response
} catch (error) {
console.debug('Error while getting the token: ', error)
}
}

export {
getFileConversation,
}
3 changes: 1 addition & 2 deletions src/views/FilesSidebarTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,12 @@ export default {
},
mounted() {
try {
OCA.Talk.fileInfo = this.fileInfo
this.tab = OCA.Talk.newTab()
this.tab.$mount('#talk-tab-mount')
OCA.Talk.fileInfo = this.fileInfo
} catch (error) {
console.error('Unable to mount Chat tab', error)
}
console.info(this.fileInfo)
},
beforeDestroy() {
try {
Expand Down