Commit 5463a4ed authored by Nicolas Jager's avatar Nicolas Jager

add new API allowing the possibility to make an audio-only call

- Use the new placeCallWithDetails and placeCall with details dameon's API.
- New API, placeAudioCall, in conversationmodel.h.
- add new tests.

Change-Id: I3dbd31d0e50b9a7660deb7dc3191295bd35da567
Reviewed-by: default avatarOlivier Soldano <olivier.soldnao@savoirfairelinux.com>
parent fd5a03f5
......@@ -99,6 +99,11 @@ public:
* @param uid of the conversation
*/
void placeCall(const std::string& uid);
/**
* Perform an audio call with contacts linked to this conversation
* @param uid of the conversation
*/
void placeAudioOnlyCall(const std::string& uid);
/**
* Send a message to the conversation
* @param uid of the conversation
......
......@@ -73,9 +73,10 @@ public:
/**
* Create a new call with a contact
* @param url of the contact to call
* @param isAudioOnly, set to false by default
* @return the call uid created
*/
std::string createCall(const std::string& url);
std::string createCall(const std::string& url, bool isAudioOnly = false);
/**
* Get the call from its call id
* @param uid
......
......@@ -118,6 +118,13 @@ public:
const uint64_t id,
const std::string& to, int status);
/**
* place a call
* @param uid, conversation id
* @param isAudioOnly, allow to specify if the call is only audio. Set to false by default.
*/
void placeCall(const std::string& uid, bool isAudioOnly = false);
const ConversationModel& linked;
Database& db;
const CallbacksHandler& callbacksHandler;
......@@ -363,14 +370,14 @@ ConversationModel::removeConversation(const std::string& uid, bool banned)
}
void
ConversationModel::placeCall(const std::string& uid)
ConversationModelPimpl::placeCall(const std::string& uid, bool isAudioOnly)
{
auto conversationIdx = pimpl_->indexOf(uid);
auto conversationIdx = indexOf(uid);
if (conversationIdx == -1)
return;
auto& conversation = pimpl_->conversations.at(conversationIdx);
auto& conversation = conversations.at(conversationIdx);
if (conversation.participants.empty()) {
// Should not
qDebug() << "ConversationModel::placeCall can't call a conversation without participant";
......@@ -380,7 +387,7 @@ ConversationModel::placeCall(const std::string& uid)
// Disallow multiple call
if (!conversation.callId.empty()) {
try {
auto call = owner.callModel->getCall(conversation.callId);
auto call = linked.owner.callModel->getCall(conversation.callId);
switch (call.status) {
case call::Status::INCOMING_RINGING:
case call::Status::OUTGOING_RINGING:
......@@ -405,31 +412,43 @@ ConversationModel::placeCall(const std::string& uid)
}
auto convId = uid;
auto accountId = pimpl_->accountProfileId;
auto accountId = accountProfileId;
auto participant = conversation.participants.front();
auto contactInfo = owner.contactModel->getContact(participant);
auto contactInfo = linked.owner.contactModel->getContact(participant);
auto url = contactInfo.profileInfo.uri;
if (url.empty()) return; // Incorrect item
pimpl_->sendContactRequest(participant);
if (owner.profileInfo.type != profile::Type::SIP) {
sendContactRequest(participant);
if (linked.owner.profileInfo.type != profile::Type::SIP) {
url = "ring:" + url; // Add the ring: before or it will fail.
}
conversation.callId = owner.callModel->createCall(url);
conversation.callId = linked.owner.callModel->createCall(url, isAudioOnly);
if (convId.empty()) {
// The conversation has changed because it was with the temporary item
auto contactProfileId = database::getProfileId(pimpl_->db, contactInfo.profileInfo.uri);
auto common = database::getConversationsBetween(pimpl_->db, accountId, contactProfileId);
auto contactProfileId = database::getProfileId(db, contactInfo.profileInfo.uri);
auto common = database::getConversationsBetween(db, accountId, contactProfileId);
if (common.empty()) return;
convId = common.front();
// Get new conversation
conversationIdx = pimpl_->indexOf(convId);
conversationIdx = indexOf(convId);
if (conversationIdx == -1)
return;
conversation = pimpl_->conversations.at(conversationIdx);
conversation = conversations.at(conversationIdx);
}
pimpl_->dirtyConversations = true;
emit pimpl_->behaviorController.showIncomingCallView(owner.id, conversation);
dirtyConversations = true;
emit behaviorController.showIncomingCallView(linked.owner.id, conversation);
}
void
ConversationModel::placeAudioOnlyCall(const std::string& uid)
{
pimpl_->placeCall(uid, true);
}
void
ConversationModel::placeCall(const std::string& uid)
{
pimpl_->placeCall(uid);
}
void
......
......@@ -127,10 +127,20 @@ NewCallModel::getCall(const std::string& uid) const
}
std::string
NewCallModel::createCall(const std::string& url)
NewCallModel::createCall(const std::string& url, bool isAudioOnly)
{
#ifdef ENABLE_LIBWRAP
auto callId = isAudioOnly ? CallManager::instance().placeCall(owner.id.c_str(),
url.c_str(),
{{"AUDIO_ONLY", "true"}})
: CallManager::instance().placeCall(owner.id.c_str(), url.c_str());
#else // dbus
// do not use auto here (QDBusPendingReply<QString>)
QString callId = CallManager::instance().placeCall(owner.id.c_str(), url.c_str());
QString callId = isAudioOnly ? CallManager::instance().placeCallWithDetails(owner.id.c_str(),
url.c_str(),
{{"AUDIO_ONLY", "true"}})
: CallManager::instance().placeCall(owner.id.c_str(), url.c_str());
#endif // ENABLE_LIBWRAP
if (callId.isEmpty())
qDebug() << "no call placed between (account :" << owner.id.c_str() << ", contact :" << url.c_str() << ")";
......
......@@ -284,6 +284,16 @@ public Q_SLOTS: // METHODS
return temp;
}
QString placeCall(const QString &accountID,
const QString &to,
const std::map<std::string, std::string>& volatileCallDetails)
{
QString temp(DRing::placeCall(accountID.toStdString(),
to.toStdString(),
volatileCallDetails).c_str());
return temp;
}
void playDTMF(const QString &key)
{
DRing::playDTMF(key.toStdString());
......
......@@ -237,6 +237,21 @@ ConversationModelTester::testPlaceCall()
CPPUNIT_ASSERT(!newConv.callId.empty());
}
void
ConversationModelTester::testPlaceAudioOnlyCall()
{
auto conversations = accInfo_.conversationModel->allFilteredConversations();
CPPUNIT_ASSERT(conversations.size() != 0);
auto firstConversation = accInfo_.conversationModel->filteredConversation(0);
CPPUNIT_ASSERT(firstConversation.callId.empty());
accInfo_.conversationModel->placeAudioOnlyCall(firstConversation.uid);
conversations = accInfo_.conversationModel->allFilteredConversations();
CPPUNIT_ASSERT(conversations.size() != 0);
auto newConv = accInfo_.conversationModel->filteredConversation(0);
CPPUNIT_ASSERT_EQUAL(newConv.uid, firstConversation.uid);
CPPUNIT_ASSERT(!newConv.callId.empty());
}
void
ConversationModelTester::testCreateConference()
{
......
......@@ -49,6 +49,7 @@ class ConversationModelTester : public CppUnit::TestFixture {
CPPUNIT_TEST(testReceiveMessageAndSetRead);
CPPUNIT_TEST(testPlaceCall);
CPPUNIT_TEST(testCreateConference);
CPPUNIT_TEST(testPlaceAudioOnlyCall);
CPPUNIT_TEST_SUITE_END();
public:
......@@ -89,6 +90,10 @@ public:
* Call the first conversation
*/
void testPlaceCall();
/**
* Start and audio-only call with the first conversation
*/
void testPlaceAudioOnlyCall();
/**
* Create a conference with the two first conversations
*/
......
......@@ -190,6 +190,21 @@ public Q_SLOTS: // METHODS
return to;
}
#ifdef ENABLE_LIBWRAP
QString placeCall(const QString &accountID, const QString &to, const std::map<std::string, std::string>& VolatileCallDetails)
{
emit newCallCreated(accountID, to, to);
return to;
}
#else // dbus
QString placeCallWithDetails(const QString &accountID, const QString &to, const std::map<std::string, std::string>& VolatileCallDetails)
{
emit newCallCreated(accountID, to, to);
return to;
}
#endif // ENABLE_LIBWRAP
void playDTMF(const QString &key)
{
Q_UNUSED(key)
......
......@@ -60,6 +60,17 @@ NewCallModelTester::testCreateAndGetCall()
CPPUNIT_ASSERT_EQUAL(callFromId.peer, std::string("ring:contact0"));
}
void
NewCallModelTester::testCreateAndGetAudioOnlyCall()
{
auto callId = accInfo_.callModel->createCall("ring:contact0", true);
CPPUNIT_ASSERT(!callId.empty());
CPPUNIT_ASSERT(accInfo_.callModel->hasCall(callId));
auto& call = accInfo_.callModel->getCallFromURI("ring:contact0");
auto& callFromId = accInfo_.callModel->getCall(call.id);
CPPUNIT_ASSERT_EQUAL(callFromId.peer, std::string("ring:contact0"));
}
void
NewCallModelTester::testAcceptHoldUnholdHangupCall()
{
......
......@@ -43,6 +43,7 @@ class NewCallModelTester : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(NewCallModelTester);
CPPUNIT_TEST(testCreateAndGetCall);
CPPUNIT_TEST(testAcceptHoldUnholdHangupCall);
CPPUNIT_TEST(testCreateAndGetAudioOnlyCall);
CPPUNIT_TEST_SUITE_END();
public:
......@@ -55,6 +56,10 @@ public:
* Create a call between "ring2" and "contact0" and retrieve it.
*/
void testCreateAndGetCall();
/**
* Create a audio-only call between "ring2" and "contact0" and retrieve it.
*/
void testCreateAndGetAudioOnlyCall();
/**
* Simulate an incoming call from "contact1" for "ring2"
* Accept the call, call status should be IN_PROGRESS
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment