diff options
author | Maksim Sukharev <antreesy.web@gmail.com> | 2024-03-14 18:55:15 +0100 |
---|---|---|
committer | Maksim Sukharev <antreesy.web@gmail.com> | 2024-03-15 10:23:15 +0100 |
commit | 38224b754e8ecdf968d67c1debaa17167a686266 (patch) | |
tree | 940b368761db6e2cac24ab80d62bb82e8a5842b6 | |
parent | 0caa8f229be2769e64bbd0145002ccbe858522ae (diff) |
fix(typescript): move unrelated methods to appropriate services
Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
-rw-r--r-- | src/components/MessagesList/MessagesGroup/Message/MessageButtonsBar/MessageTranslateDialog.vue | 2 | ||||
-rw-r--r-- | src/components/MessagesList/MessagesGroup/Message/MessagePart/Reactions.spec.js | 4 | ||||
-rw-r--r-- | src/services/__tests__/messagesService.spec.js (renamed from src/services/messagesService.spec.js) | 8 | ||||
-rw-r--r-- | src/services/messagesService.ts | 36 | ||||
-rw-r--r-- | src/services/reactionsService.js | 55 | ||||
-rw-r--r-- | src/services/translationService.js | 38 | ||||
-rw-r--r-- | src/stores/__tests__/reactions.spec.js | 4 | ||||
-rw-r--r-- | src/stores/reactions.js | 2 |
8 files changed, 105 insertions, 44 deletions
diff --git a/src/components/MessagesList/MessagesGroup/Message/MessageButtonsBar/MessageTranslateDialog.vue b/src/components/MessagesList/MessagesGroup/Message/MessageButtonsBar/MessageTranslateDialog.vue index 403b53b3e..234cbc6dd 100644 --- a/src/components/MessagesList/MessagesGroup/Message/MessageButtonsBar/MessageTranslateDialog.vue +++ b/src/components/MessagesList/MessagesGroup/Message/MessageButtonsBar/MessageTranslateDialog.vue @@ -91,7 +91,7 @@ import NcModal from '@nextcloud/vue/dist/Components/NcModal.js' import NcRichText from '@nextcloud/vue/dist/Components/NcRichText.js' import NcSelect from '@nextcloud/vue/dist/Components/NcSelect.js' -import { getTranslationLanguages, translateText } from '../../../../../services/messagesService.js' +import { getTranslationLanguages, translateText } from '../../../../../services/translationService.js' export default { name: 'MessageTranslateDialog', diff --git a/src/components/MessagesList/MessagesGroup/Message/MessagePart/Reactions.spec.js b/src/components/MessagesList/MessagesGroup/Message/MessagePart/Reactions.spec.js index 5975bae63..4bccb521b 100644 --- a/src/components/MessagesList/MessagesGroup/Message/MessagePart/Reactions.spec.js +++ b/src/components/MessagesList/MessagesGroup/Message/MessagePart/Reactions.spec.js @@ -16,13 +16,13 @@ import { addReactionToMessage, removeReactionFromMessage, getReactionsDetails, -} from '../../../../../services/messagesService.js' +} from '../../../../../services/reactionsService.js' import vuexStore from '../../../../../store/index.js' import storeConfig from '../../../../../store/storeConfig.js' import { useReactionsStore } from '../../../../../stores/reactions.js' import { generateOCSResponse } from '../../../../../test-helpers.js' -jest.mock('../../../../../services/messagesService', () => ({ +jest.mock('../../../../../services/reactionsService', () => ({ getReactionsDetails: jest.fn(), addReactionToMessage: jest.fn(), removeReactionFromMessage: jest.fn(), diff --git a/src/services/messagesService.spec.js b/src/services/__tests__/messagesService.spec.js index 32fc33827..dc918a1f2 100644 --- a/src/services/messagesService.spec.js +++ b/src/services/__tests__/messagesService.spec.js @@ -1,6 +1,7 @@ import axios from '@nextcloud/axios' import { generateOcsUrl } from '@nextcloud/router' +import { CHAT } from '../../constants.js' import { fetchMessages, getMessageContext, @@ -10,13 +11,16 @@ import { editMessage, postRichObjectToConversation, updateLastReadMessage, +} from '../messagesService.ts' +import { addReactionToMessage, removeReactionFromMessage, getReactionsDetails, +} from '../reactionsService.js' +import { getTranslationLanguages, translateText, -} from './messagesService.js' -import { CHAT } from '../constants.js' +} from '../translationService.js' jest.mock('@nextcloud/axios', () => ({ get: jest.fn(), diff --git a/src/services/messagesService.ts b/src/services/messagesService.ts index dd8f38c7d..e24b3247d 100644 --- a/src/services/messagesService.ts +++ b/src/services/messagesService.ts @@ -204,37 +204,6 @@ const updateLastReadMessage = async function(token: string, lastReadMessage: set } as setReadMarkerParams, options) } -const addReactionToMessage = async function(token, messageId, selectedEmoji, options) { - return axios.post(generateOcsUrl('apps/spreed/api/v1/reaction/{token}/{messageId}', { token, messageId }, options), { - reaction: selectedEmoji, - }, options) -} - -const removeReactionFromMessage = async function(token, messageId, selectedEmoji, options) { - return axios.delete(generateOcsUrl('apps/spreed/api/v1/reaction/{token}/{messageId}', { token, messageId }, options), { - ...options, - params: { - reaction: selectedEmoji, - }, - }) -} - -const getReactionsDetails = async function(token, messageId, options) { - return axios.get(generateOcsUrl('apps/spreed/api/v1/reaction/{token}/{messageId}', { token, messageId }, options), options) -} - -const getTranslationLanguages = async function(options) { - return axios.get(generateOcsUrl('/translation/languages', undefined, options), options) -} - -const translateText = async function(text, fromLanguage, toLanguage, options) { - return axios.post(generateOcsUrl('/translation/translate', undefined, options), { - text, - fromLanguage, - toLanguage, - }, options) -} - export { fetchMessages, lookForNewMessages, @@ -243,10 +212,5 @@ export { deleteMessage, postRichObjectToConversation, updateLastReadMessage, - addReactionToMessage, - removeReactionFromMessage, - getReactionsDetails, editMessage, - getTranslationLanguages, - translateText, } diff --git a/src/services/reactionsService.js b/src/services/reactionsService.js new file mode 100644 index 000000000..7714efd7e --- /dev/null +++ b/src/services/reactionsService.js @@ -0,0 +1,55 @@ +/** + * @copyright Copyright (c) 2024 Maksim Sukharev <antreesy.web@gmail.com> + * + * @author Marco Ambrosini <marcoambrosini@icloud.com> + * @author Maksim Sukharev <antreesy.web@gmail.com> + * + * @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 <http://www.gnu.org/licenses/>. + * + */ + +import axios from '@nextcloud/axios' +import { generateOcsUrl } from '@nextcloud/router' + +const addReactionToMessage = async function(token, messageId, selectedEmoji, options) { + return axios.post(generateOcsUrl('apps/spreed/api/v1/reaction/{token}/{messageId}', { + token, + messageId + }, options), { + reaction: selectedEmoji, + }, options) +} + +const removeReactionFromMessage = async function(token, messageId, selectedEmoji, options) { + return axios.delete(generateOcsUrl('apps/spreed/api/v1/reaction/{token}/{messageId}', { + token, + messageId + }, options), { + ...options, + params: { + reaction: selectedEmoji, + }, + }) +} + +const getReactionsDetails = async function(token, messageId, options) { + return axios.get(generateOcsUrl('apps/spreed/api/v1/reaction/{token}/{messageId}', { + token, + messageId + }, options), options) +} + +export { addReactionToMessage, removeReactionFromMessage, getReactionsDetails } diff --git a/src/services/translationService.js b/src/services/translationService.js new file mode 100644 index 000000000..b494cec23 --- /dev/null +++ b/src/services/translationService.js @@ -0,0 +1,38 @@ +/** + * @copyright Copyright (c) 2024 Maksim Sukharev <antreesy.web@gmail.com> + * + * @author Maksim Sukharev <antreesy.web@gmail.com> + * + * @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 <http://www.gnu.org/licenses/>. + * + */ + +import axios from '@nextcloud/axios' +import { generateOcsUrl } from '@nextcloud/router' + +const getTranslationLanguages = async function(options) { + return axios.get(generateOcsUrl('/translation/languages', undefined, options), options) +} + +const translateText = async function(text, fromLanguage, toLanguage, options) { + return axios.post(generateOcsUrl('/translation/translate', undefined, options), { + text, + fromLanguage, + toLanguage, + }, options) +} + +export { getTranslationLanguages, translateText } diff --git a/src/stores/__tests__/reactions.spec.js b/src/stores/__tests__/reactions.spec.js index c41b49efd..d971add0a 100644 --- a/src/stores/__tests__/reactions.spec.js +++ b/src/stores/__tests__/reactions.spec.js @@ -4,12 +4,12 @@ import Vuex from 'vuex' import { showError } from '@nextcloud/dialogs' -import { getReactionsDetails, addReactionToMessage, removeReactionFromMessage } from '../../services/messagesService.js' +import { getReactionsDetails, addReactionToMessage, removeReactionFromMessage } from '../../services/reactionsService.js' import vuexStore from '../../store/index.js' import { generateOCSErrorResponse, generateOCSResponse } from '../../test-helpers.js' import { useReactionsStore } from '../reactions.js' -jest.mock('../../services/messagesService', () => ({ +jest.mock('../../services/reactionsService', () => ({ getReactionsDetails: jest.fn(), addReactionToMessage: jest.fn(), removeReactionFromMessage: jest.fn(), diff --git a/src/stores/reactions.js b/src/stores/reactions.js index 58606b922..8d0c8f582 100644 --- a/src/stores/reactions.js +++ b/src/stores/reactions.js @@ -30,7 +30,7 @@ import { getReactionsDetails, addReactionToMessage, removeReactionFromMessage, -} from '../services/messagesService.js' +} from '../services/reactionsService.js' import store from '../store/index.js' /** |