Line data Source code
1 : /* 2 : * Copyright (C) 2004-2025 Savoir-faire Linux Inc. 3 : * 4 : * This program is free software: you can redistribute it and/or modify 5 : * it under the terms of the GNU General Public License as published by 6 : * the Free Software Foundation, either version 3 of the License, or 7 : * (at your option) any later version. 8 : * 9 : * This program is distributed in the hope that it will be useful, 10 : * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 : * GNU General Public License for more details. 13 : * 14 : * You should have received a copy of the GNU General Public License 15 : * along with this program. If not, see <https://www.gnu.org/licenses/>. 16 : */ 17 : 18 : #include "datatransfer_interface.h" 19 : 20 : #include "manager.h" 21 : #include "data_transfer.h" 22 : #include "client/ring_signal.h" 23 : #include "jamidht/jamiaccount.h" 24 : 25 : namespace libjami { 26 : 27 : void 28 0 : registerDataXferHandlers(const std::map<std::string, std::shared_ptr<CallbackWrapperBase>>& handlers) 29 : { 30 0 : registerSignalHandlers(handlers); 31 0 : } 32 : 33 : void 34 13 : sendFile(const std::string& accountId, 35 : const std::string& conversationId, 36 : const std::string& path, 37 : const std::string& displayName, 38 : const std::string& replyTo) noexcept 39 : { 40 13 : if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId)) { 41 13 : acc->sendFile(conversationId, path, displayName, replyTo); 42 13 : } 43 13 : } 44 : 45 : bool 46 13 : downloadFile(const std::string& accountId, 47 : const std::string& conversationId, 48 : const std::string& interactionId, 49 : const std::string& fileId, 50 : const std::string& path) noexcept 51 : { 52 13 : if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId)) 53 13 : if (auto convModule = acc->convModule(true)) 54 13 : return convModule->downloadFile(conversationId, interactionId, fileId, path); 55 0 : return {}; 56 : } 57 : 58 : DataTransferError 59 1 : cancelDataTransfer(const std::string& accountId, const std::string& conversationId, const std::string& fileId) noexcept 60 : { 61 1 : if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId)) { 62 1 : if (auto dt = acc->dataTransfer(conversationId)) 63 1 : return dt->cancel(fileId) ? libjami::DataTransferError::success 64 1 : : libjami::DataTransferError::invalid_argument; 65 1 : } 66 0 : return libjami::DataTransferError::invalid_argument; 67 : } 68 : 69 : DataTransferError 70 2 : fileTransferInfo(const std::string& accountId, 71 : const std::string& conversationId, 72 : const std::string& fileId, 73 : std::string& path, 74 : int64_t& total, 75 : int64_t& progress) noexcept 76 : { 77 2 : if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId)) { 78 2 : if (auto dt = acc->dataTransfer(conversationId)) 79 2 : return dt->info(fileId, path, total, progress) ? libjami::DataTransferError::success 80 2 : : libjami::DataTransferError::invalid_argument; 81 2 : } 82 0 : return libjami::DataTransferError::invalid_argument; 83 : } 84 : 85 : } // namespace libjami