diff --git a/src/api/newcallmodel.h b/src/api/newcallmodel.h index af80deec6240153f06cc4b817b108ce97b2c7304..09dd71d1baf0acc4a3058b669f7cd5980226cc0f 100644 --- a/src/api/newcallmodel.h +++ b/src/api/newcallmodel.h @@ -186,6 +186,15 @@ public: */ void joinCalls(const std::string& callIdA, const std::string& callIdB) const; + /** + * Call a participant and add it to a call + * @param uri URI of the participant + * @param callId Call receiving the participant + * @param audioOnly If the call is audio only + * @return id for a new call + */ + std::string callAndAddParticipant(const std::string uri, const std::string& callId, bool audioOnly); + /** * Not implemented yet */ diff --git a/src/newcallmodel.cpp b/src/newcallmodel.cpp index 1aa165c6f16dea6d8c8eeaf54697769f1720788a..b20b157fe850e2dd19a5457be1f7ee308c8dcaed 100644 --- a/src/newcallmodel.cpp +++ b/src/newcallmodel.cpp @@ -22,6 +22,7 @@ // std #include <chrono> #include <random> +#include <map> // Lrc #include "callbackshandler.h" @@ -145,6 +146,7 @@ public: bool manageCurrentCall_ {true}; bool dontHoldConferences_ {false}; + std::map<std::string, std::string> pendingConferences_; public Q_SLOTS: /** * Listen from CallbacksHandler when a call is incoming @@ -450,6 +452,14 @@ NewCallModel::joinCalls(const std::string& callIdA, const std::string& callIdB) } } +std::string +NewCallModel::callAndAddParticipant(const std::string uri, const std::string& callId, bool audioOnly) +{ + auto newCallId = createCall(uri, audioOnly); + pimpl_->pendingConferences_.insert({newCallId, callId}); + return newCallId; +} + void NewCallModel::removeParticipant(const std::string& callId, const std::string& participant) const { @@ -573,6 +583,10 @@ void NewCallModelPimpl::setCurrentCall(const std::string& callId) { if (!manageCurrentCall_) return; + auto it = pendingConferences_.find(callId); + // Set current call only if not adding this call + // to a current conference + if (it != pendingConferences_.end()) return; std::vector<std::string> filterCalls; if (dontHoldConferences_) { // Do not hold calls in a conference @@ -671,16 +685,28 @@ NewCallModelPimpl::slotCallStateChanged(const std::string& callId, const std::st // NOTE: signal emission order matters, always emit CallStatusChanged before CallEnded emit linked.callStatusChanged(callId, code); - if (call->status == call::Status::ENDED) { + if (call->status == call::Status::OUTGOING_RINGING) { + setCurrentCall(callId); + } else if (call->status == call::Status::ENDED) { emit linked.callEnded(callId); } else if (call->status == call::Status::IN_PROGRESS) { if (previousStatus == call::Status::INCOMING_RINGING || previousStatus == call::Status::OUTGOING_RINGING) { + + if (previousStatus == call::Status::INCOMING_RINGING) + setCurrentCall(callId); + call->startTime = std::chrono::steady_clock::now(); setCurrentCall(callId); emit linked.callStarted(callId); sendProfile(callId); } + // Add to calls if in pendingConferences_ + auto it = pendingConferences_.find(callId); + if (it != pendingConferences_.end()) { + linked.joinCalls(it->second, it->first); + pendingConferences_.erase(it); + } } }