Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add method to get the token for the conversation of a file
Signed-off-by: Marco Ambrosini <marcoambrosini@pm.me>
  • Loading branch information
marcoambrosini authored and nickvergessen committed Dec 20, 2019
commit e4ac56e7eaf387b6239c05f26259065b2ae96b28
42 changes: 41 additions & 1 deletion src/FilesSidebarTabApp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,57 @@
</template>

<script>

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

export default {

name: 'FilesSidebarTabApp',

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() {
return this.$store.getters.getToken()
},
},

methods: {
async getFileConversation() {
// Clear previous requests if there's one pending
this.cancelGetFileConversation('canceled')
// 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 })
this.$store.dispatch('updateToken', response.data.ocs.data.token)
} catch (exception) {
if (Axios.isCancel(exception)) {
console.debug('The request has been canceled', exception)
} else {
console.debug(exception)
}
}
},
},
}
Expand Down
44 changes: 44 additions & 0 deletions src/services/filesIntegrationServices.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* @copyright Copyright (c) 2019 Marco Ambrosini <marcoambrosini@pm.me>
*
* @author Marco Ambrosini <marcoambrosini@pm.me>
*
* @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
*
* @param {Object} .fileId the id of the file
* @param {Object} options unused
* @returns {String} the conversation token
*/
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