LCOV - code coverage report
Current view: top level - foo/src/client - datatransfer.cpp (source / functions) Hit Total Coverage
Test: jami-coverage-filtered.info Lines: 21 27 77.8 %
Date: 2026-02-28 10:41:24 Functions: 4 5 80.0 %

          Line data    Source code
       1             : /*
       2             :  *  Copyright (C) 2004-2026 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 "jamidht/jamiaccount.h"
      22             : 
      23             : namespace libjami {
      24             : 
      25             : void
      26           0 : registerDataXferHandlers(const std::map<std::string, std::shared_ptr<CallbackWrapperBase>>& handlers)
      27             : {
      28           0 :     registerSignalHandlers(handlers);
      29           0 : }
      30             : 
      31             : void
      32          13 : sendFile(const std::string& accountId,
      33             :          const std::string& conversationId,
      34             :          const std::string& path,
      35             :          const std::string& displayName,
      36             :          const std::string& replyTo) noexcept
      37             : {
      38          13 :     if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId)) {
      39          13 :         acc->sendFile(conversationId, path, displayName, replyTo);
      40          13 :     }
      41          13 : }
      42             : 
      43             : bool
      44          13 : downloadFile(const std::string& accountId,
      45             :              const std::string& conversationId,
      46             :              const std::string& interactionId,
      47             :              const std::string& fileId,
      48             :              const std::string& path) noexcept
      49             : {
      50          13 :     if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId))
      51          13 :         if (auto* convModule = acc->convModule(true))
      52          13 :             return convModule->downloadFile(conversationId, interactionId, fileId, path);
      53           0 :     return {};
      54             : }
      55             : 
      56             : DataTransferError
      57           1 : cancelDataTransfer(const std::string& accountId, const std::string& conversationId, const std::string& fileId) noexcept
      58             : {
      59           1 :     if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId)) {
      60           1 :         if (auto dt = acc->dataTransfer(conversationId))
      61           1 :             return dt->cancel(fileId) ? libjami::DataTransferError::success
      62           1 :                                       : libjami::DataTransferError::invalid_argument;
      63           1 :     }
      64           0 :     return libjami::DataTransferError::invalid_argument;
      65             : }
      66             : 
      67             : DataTransferError
      68           2 : fileTransferInfo(const std::string& accountId,
      69             :                  const std::string& conversationId,
      70             :                  const std::string& fileId,
      71             :                  std::string& path,
      72             :                  int64_t& total,
      73             :                  int64_t& progress) noexcept
      74             : {
      75           2 :     if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId)) {
      76           2 :         if (auto dt = acc->dataTransfer(conversationId))
      77           2 :             return dt->info(fileId, path, total, progress) ? libjami::DataTransferError::success
      78           2 :                                                            : libjami::DataTransferError::invalid_argument;
      79           2 :     }
      80           0 :     return libjami::DataTransferError::invalid_argument;
      81             : }
      82             : 
      83             : } // namespace libjami

Generated by: LCOV version 1.14