diff options
author | Marco <marcoambrosini@pm.me> | 2022-04-29 16:48:57 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-29 16:48:57 +0300 |
commit | bec039c41769affbe30b1a2b68780a34394d41f1 (patch) | |
tree | c1f7381097ba48e00e0dd7d521895f60a54dc37a | |
parent | 36811b9f524da0b449793b8cd9a9eb7fdb68ea70 (diff) | |
parent | e264885e756fc28f2a183812ca1709e2fe8af6ff (diff) |
Merge pull request #7250 from nextcloud/backport/7169/stable24
[stable24] Fix store stuff
-rw-r--r-- | src/services/conversationSharedItemsService.js | 20 | ||||
-rw-r--r-- | src/store/conversationSharedItemsStore.js | 30 |
2 files changed, 36 insertions, 14 deletions
diff --git a/src/services/conversationSharedItemsService.js b/src/services/conversationSharedItemsService.js index 12922175e..a0537ecf9 100644 --- a/src/services/conversationSharedItemsService.js +++ b/src/services/conversationSharedItemsService.js @@ -28,19 +28,25 @@ import { generateOcsUrl } from '@nextcloud/router' const getSharedItemsOverview = async function(token, limit) { return axios.get(generateOcsUrl('apps/spreed/api/v1/chat/{token}/share/overview', { token, - limit, - })) + }), { + params: { + 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,) { +const getSharedItems = async function(token, objectType, lastKnownMessageId, limit) { return axios.get(generateOcsUrl('apps/spreed/api/v1/chat/{token}/share', { token, - objectType, - lastKnownMessageId, - limit, - })) + }), { + params: { + limit, + objectType, + lastKnownMessageId, + }, + }) } export { diff --git a/src/store/conversationSharedItemsStore.js b/src/store/conversationSharedItemsStore.js index b58de46fc..9242dd0c8 100644 --- a/src/store/conversationSharedItemsStore.js +++ b/src/store/conversationSharedItemsStore.js @@ -113,16 +113,32 @@ export const mutations = { } const actions = { - async getSharedItems({ commit }, { token, type, lastKnownMessageId, limit }) { + async getSharedItems({ commit, state }, { token, type }) { + if (!state.sharedItemsByConversationAndType[token] + || !state.sharedItemsByConversationAndType[token][type]) { + console.error('Missing overview for shared items in ', token) + return false + } + + const limit = 100 + const lastKnownMessageId = Math.min.apply(Math, Object.keys(state.sharedItemsByConversationAndType[token][type])) try { const response = await getSharedItems(token, type, lastKnownMessageId, limit) + const messages = response.data.ocs.data + const hasMore = messages.length >= limit + // loop over the response elements and add them to the store - for (const sharedItem in response) { - commit('addSharedItem', sharedItem) + for (const message in messages) { + commit('addSharedItemMessage', { + token, + type, + message, + }) } - + return hasMore } catch (error) { - console.debug(error) + console.error(error) + return false } }, @@ -132,13 +148,13 @@ const actions = { } try { - const response = await getSharedItemsOverview(token, 10) + const response = await getSharedItemsOverview(token, 7) commit('addSharedItemsOverview', { token, data: response.data.ocs.data, }) } catch (error) { - console.debug(error) + console.error(error) } }, |