diff --git a/src/services/conversationSharedItemsService.js b/src/services/conversationSharedItemsService.js new file mode 100644 index 000000000..12922175e --- /dev/null +++ b/src/services/conversationSharedItemsService.js @@ -0,0 +1,49 @@ +/** + * @copyright Copyright (c) 2022 Marco Ambrosini + * + * @author Marco Ambrosini + * + * @license AGPL-3.0-or-later + * + * 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 . + * + */ + +import axios from '@nextcloud/axios' +import { generateOcsUrl } from '@nextcloud/router' + +// Returns the last n shared items for each category and for a given conversation +// (n = limit) +const getSharedItemsOverview = async function(token, limit) { + return axios.get(generateOcsUrl('apps/spreed/api/v1/chat/{token}/share/overview', { + token, + limit, + })) +} + +// Returns the last 200 (or limit) shared items, given a conversation and the type +// of shared item +const getSharedItems = async function(token, objectType, lastKnownMessageId, limit,) { + return axios.get(generateOcsUrl('apps/spreed/api/v1/chat/{token}/share', { + token, + objectType, + lastKnownMessageId, + limit, + })) +} + +export { + getSharedItems, + getSharedItemsOverview, +} diff --git a/src/store/ConversationSharedItemsStore.js b/src/store/ConversationSharedItemsStore.js new file mode 100644 index 000000000..612b70c21 --- /dev/null +++ b/src/store/ConversationSharedItemsStore.js @@ -0,0 +1,78 @@ +/** + * @copyright Copyright (c) 2022 Marco Ambrosini + * + * @author Marco Ambrosini + * + * @license AGPL-3.0-or-later + * + * 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 . + * + */ + +import Vue from 'vue' +import { getSharedItemsOverview, getSharedItems } from '../services/conversationSharedItemsService' + +// Store structure +// token: { +// media: {}, +// file: {}, +// voice: {}, +// location: {} +// deckcard: {}, +// audio: {}, +// other: {}, + +const state = () => ({ + state: {}, +}) + +const getters = { + getterSharedItems: (state, token) => { + return state[token] + }, +} + +export const mutations = { + addSharedItem: (state, { token, type, response }) => { + if (!state[token]) { + Vue.set(state, token, {}) + } + Vue.set(state[token], type, response) + }, +} + +const actions = { + async getSharedItems({ commit }, { token, type, lastKnownMessageId, limit }) { + try { + const response = await getSharedItems(token, type, lastKnownMessageId, limit) + // loop over the response elements and add them to the store + for (const sharedItem in response) { + commit('addSharedItem', sharedItem) + } + + } catch (error) { + console.debug(error) + } + }, + + async getSharedItemsOverview({ commit }, { token }) { + try { + const response = await getSharedItemsOverview(token, 10) + } catch (error) { + console.debug(error) + } + }, +} + +export default { state, mutations, getters, actions } diff --git a/src/store/storeConfig.js b/src/store/storeConfig.js index 8d772fa26..9f5fbe9c1 100644 --- a/src/store/storeConfig.js +++ b/src/store/storeConfig.js @@ -39,6 +39,7 @@ import uiModeStore from './uiModeStore' import windowVisibilityStore from './windowVisibilityStore' import messageActionsStore from './messageActionsStore' import reactionsStore from './reactionsStore' +import conversationSharedItemStore from './conversationSharedItemsStore' export default { modules: { @@ -61,6 +62,7 @@ export default { windowVisibilityStore, messageActionsStore, reactionsStore, + conversationSharedItemStore, }, mutations: {},