From 746e3bb2cd6b4a098d7ebeba973f922d0d0b042b Mon Sep 17 00:00:00 2001
From: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
Date: Thu, 2 Sep 2010 17:20:40 -0400
Subject: [PATCH] [#3963] Frist version for instant message during a conference

---
 sflphone-common/src/dbus/callmanager.cpp |  3 +-
 sflphone-common/src/managerimpl.cpp      | 71 +++++++++++++++++++++---
 sflphone-common/src/managerimpl.h        |  2 +-
 sflphone-common/src/sip/sipvoiplink.cpp  |  1 +
 4 files changed, 66 insertions(+), 11 deletions(-)

diff --git a/sflphone-common/src/dbus/callmanager.cpp b/sflphone-common/src/dbus/callmanager.cpp
index ce9c544c66..a5498d0e64 100644
--- a/sflphone-common/src/dbus/callmanager.cpp
+++ b/sflphone-common/src/dbus/callmanager.cpp
@@ -464,5 +464,6 @@ CallManager::setPBXEnrollment (const std::string& callID, const bool& yesNo)
 void
 CallManager::sendTextMessage (const std::string& callID, const std::string& message)
 {
-    Manager::instance().sendTextMessage (callID, message);
+    if (!Manager::instance().sendTextMessage (callID, message))
+        throw CallManagerException();
 }
diff --git a/sflphone-common/src/managerimpl.cpp b/sflphone-common/src/managerimpl.cpp
index b78acd54e8..ccdfa03f8a 100644
--- a/sflphone-common/src/managerimpl.cpp
+++ b/sflphone-common/src/managerimpl.cpp
@@ -1712,6 +1712,34 @@ void ManagerImpl::incomingMessage (const CallID& callID,
                                    const std::string& from,
                                    const std::string& message)
 {
+    SIPVoIPLink *link = NULL;
+
+    if (participToConference (callID)) {
+        _debug ("Manager: Particip to a conference, send message to everyone");
+
+        Conference *conf = getConferenceFromCallID (callID);
+
+        ParticipantSet participants = conf->getParticipantList();
+        ParticipantSet::iterator iter_participant = participants.begin();
+
+        while (iter_participant != participants.end()) {
+
+            AccountID accountId = getAccountFromCall (*iter_participant);
+
+            _debug ("Manager: Send message to %s, (%s)", (*iter_participant).c_str(), accountId.c_str());
+
+            if (*iter_participant != callID) {
+
+                link = SIPVoIPLink::instance (""); // dynamic_cast<SIPVoIPLink *> (getAccountLink (*iter_participant));
+
+                if (link)
+                    link->sendTextMessage (*iter_participant, message);
+            }
+
+            iter_participant++;
+        }
+    }
+
     if (_dbus) {
         _dbus->getCallManager()->incomingMessage (callID, from, message);
     }
@@ -1719,23 +1747,48 @@ void ManagerImpl::incomingMessage (const CallID& callID,
 
 
 //THREAD=VoIP
-void ManagerImpl::sendTextMessage (const CallID& callID, const std::string& message)
+bool ManagerImpl::sendTextMessage (const CallID& callID, const std::string& message)
 {
+    SIPVoIPLink * link = NULL;
 
-    if (participToConference (callID))
+    if (participToConference (callID)) {
         _debug ("Manager: Particip to a conference, send message on everyone");
 
-    AccountID accountId = getAccountFromCall (callID);
+        Conference *conf = getConferenceFromCallID (callID);
 
-    SIPVoIPLink * link = NULL;
-    link = dynamic_cast<SIPVoIPLink *> (getAccountLink (accountId));
+        ParticipantSet participants = conf->getParticipantList();
+        ParticipantSet::iterator iter_participant = participants.begin();
+
+        while (iter_participant != participants.end()) {
+
+            AccountID accountId = getAccountFromCall (*iter_participant);
 
-    if (link == NULL) {
-        _debug ("Manager: Failed to get sip link");
-        throw CallManagerException();
+            _debug ("Manager: Send message to %s (%s)", (*iter_participant).c_str(), accountId.c_str());
+            link = SIPVoIPLink::instance (""); // dynamic_cast<SIPVoIPLink *> (getAccountLink (*iter_participant));
+
+
+            if (link)
+                link->sendTextMessage (*iter_participant, message);
+
+            iter_participant++;
+        }
+
+    } else {
+
+        AccountID accountId = getAccountFromCall (callID);
+
+        link = dynamic_cast<SIPVoIPLink *> (getAccountLink (accountId));
+
+        if (link == NULL) {
+            _debug ("Manager: Failed to get sip link");
+            return false;
+        }
+
+        _debug ("Manager: Send message to %s (%s)", callID.c_str(), accountId.c_str());
+        link->sendTextMessage (callID, message);
     }
 
-    link->sendTextMessage (callID, message);
+    return true;
 }
 
 //THREAD=VoIP CALL=Outgoing
diff --git a/sflphone-common/src/managerimpl.h b/sflphone-common/src/managerimpl.h
index 1ee15be867..db6c91ccf7 100644
--- a/sflphone-common/src/managerimpl.h
+++ b/sflphone-common/src/managerimpl.h
@@ -452,7 +452,7 @@ class ManagerImpl
          * @param callID	The call to send the message
          * @param message	The content of the message
              */
-        void sendTextMessage (const CallID& callID, const std::string& message);
+        bool sendTextMessage (const CallID& callID, const std::string& message);
 
         /**
          * Notify the client he has voice mails
diff --git a/sflphone-common/src/sip/sipvoiplink.cpp b/sflphone-common/src/sip/sipvoiplink.cpp
index 2c520811a7..a9cb6ff1e4 100644
--- a/sflphone-common/src/sip/sipvoiplink.cpp
+++ b/sflphone-common/src/sip/sipvoiplink.cpp
@@ -1064,6 +1064,7 @@ SIPVoIPLink::onhold (const CallID& id)
 bool
 SIPVoIPLink::sendTextMessage (const std::string& callID, const std::string& message)
 {
+    _debug ("SipVoipLink: Send text message to %s", callID.c_str());
 
     SIPCall *call = getSIPCall (callID);
     pj_status_t status = !PJ_SUCCESS;
-- 
GitLab