LCOV - code coverage report
Current view: top level - src/client - datatransfer.cpp (source / functions) Hit Total Coverage
Test: jami-coverage-filtered.info Lines: 22 28 78.6 %
Date: 2024-12-21 08:56:24 Functions: 4 5 80.0 %

          Line data    Source code
       1             : /*
       2             :  *  Copyright (C) 2004-2024 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          11 : 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          11 :     if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId)) {
      41          11 :         acc->sendFile(conversationId, path, displayName, replyTo);
      42          11 :     }
      43          11 : }
      44             : 
      45             : bool
      46          11 : 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          11 :     if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId))
      53          11 :         if (auto convModule = acc->convModule(true))
      54          11 :             return convModule->downloadFile(conversationId, interactionId, fileId, path);
      55           0 :     return {};
      56             : }
      57             : 
      58             : DataTransferError
      59           1 : cancelDataTransfer(const std::string& accountId,
      60             :                    const std::string& conversationId,
      61             :                    const std::string& fileId) noexcept
      62             : {
      63           1 :     if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId)) {
      64           1 :         if (auto dt = acc->dataTransfer(conversationId))
      65           1 :             return dt->cancel(fileId) ? libjami::DataTransferError::success
      66           1 :                                       : libjami::DataTransferError::invalid_argument;
      67           1 :     }
      68           0 :     return libjami::DataTransferError::invalid_argument;
      69             : }
      70             : 
      71             : DataTransferError
      72           2 : fileTransferInfo(const std::string& accountId,
      73             :                  const std::string& conversationId,
      74             :                  const std::string& fileId,
      75             :                  std::string& path,
      76             :                  int64_t& total,
      77             :                  int64_t& progress) noexcept
      78             : {
      79           2 :     if (auto acc = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId)) {
      80           2 :         if (auto dt = acc->dataTransfer(conversationId))
      81           2 :             return dt->info(fileId, path, total, progress)
      82           2 :                        ? libjami::DataTransferError::success
      83           2 :                        : libjami::DataTransferError::invalid_argument;
      84           2 :     }
      85           0 :     return libjami::DataTransferError::invalid_argument;
      86             : }
      87             : 
      88             : } // namespace libjami

Generated by: LCOV version 1.14