From cb0b41b8abbcbd6b8fddc74fd1d0d7fe07af9da7 Mon Sep 17 00:00:00 2001
From: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
Date: Fri, 17 Sep 2010 14:59:19 -0400
Subject: [PATCH] [#4071] Test wether the call is IAX or SIP for instant
 messaging in conference

---
 sflphone-common/src/managerimpl.cpp | 44 ++++++++++++++++++++---------
 1 file changed, 30 insertions(+), 14 deletions(-)

diff --git a/sflphone-common/src/managerimpl.cpp b/sflphone-common/src/managerimpl.cpp
index f68fa3d985..8b8a468ed1 100644
--- a/sflphone-common/src/managerimpl.cpp
+++ b/sflphone-common/src/managerimpl.cpp
@@ -1778,12 +1778,23 @@ bool ManagerImpl::sendTextMessage (const CallID& callID, const std::string& mess
 
             AccountID accountId = getAccountFromCall (*iter_participant);
 
-            _debug ("Manager: Send message to %s (%s)", (*iter_participant).c_str(), accountId.c_str());
-            link = SIPVoIPLink::instance (""); // dynamic_cast<SIPVoIPLink *> (getAccountLink (*iter_participant));
+            Account *account = getAccount (accountId);
 
+            if (!account) {
+                _debug ("Manager: Failed to get account while sending instant message");
+                return false;
+            }
 
-            if (link && _imModule)
-                link->sendTextMessage (_imModule, *iter_participant, message, from);
+            if (account->getType() == "SIP")
+                // link = dynamic_cast<SIPVoIPLink *> (getAccountLink (accountId));
+                dynamic_cast<SIPVoIPLink *> (getAccountLink (accountId))->sendTextMessage (_imModule, *iter_participant, message, from);
+            else if (account->getType() == "IAX")
+                // link = dynamic_cast<IAXVoIPLink *> (account->getVoIPLink());
+                dynamic_cast<IAXVoIPLink *> (account->getVoIPLink())->sendTextMessage (_imModule, *iter_participant, message, from);
+            else {
+                _debug ("Manager: Failed to get voip link while sending instant message");
+                return false;
+            }
 
             iter_participant++;
         }
@@ -1803,12 +1814,23 @@ bool ManagerImpl::sendTextMessage (const CallID& callID, const std::string& mess
 
             AccountID accountId = getAccountFromCall (*iter_participant);
 
-            _debug ("Manager: Send message to %s (%s)", (*iter_participant).c_str(), accountId.c_str());
-            link = SIPVoIPLink::instance (""); // dynamic_cast<SIPVoIPLink *> (getAccountLink (*iter_participant));
+            Account *account = getAccount (accountId);
 
+            if (!account) {
+                _debug ("Manager: Failed to get account while sending instant message");
+                return false;
+            }
 
-            if (link && _imModule)
-                link->sendTextMessage (_imModule, *iter_participant, message, from);
+            if (account->getType() == "SIP")
+                // link = dynamic_cast<SIPVoIPLink *> (getAccountLink (accountId));
+                dynamic_cast<SIPVoIPLink *> (getAccountLink (accountId))->sendTextMessage (_imModule, *iter_participant, message, from);
+            else if (account->getType() == "IAX")
+                // link = dynamic_cast<IAXVoIPLink *> (account->getVoIPLink());
+                dynamic_cast<IAXVoIPLink *> (account->getVoIPLink())->sendTextMessage (_imModule, *iter_participant, message, from);
+            else {
+                _debug ("Manager: Failed to get voip link while sending instant message");
+                return false;
+            }
 
             iter_participant++;
         }
@@ -1831,15 +1853,9 @@ bool ManagerImpl::sendTextMessage (const CallID& callID, const std::string& mess
             // link = dynamic_cast<IAXVoIPLink *> (account->getVoIPLink());
             dynamic_cast<IAXVoIPLink *> (account->getVoIPLink())->sendTextMessage (_imModule, callID, message, from);
         else {
-            //link = NULL;
-
-            //if (!link) {
             _debug ("Manager: Failed to get voip link while sending instant message");
             return false;
         }
-
-        // _debug ("Manager: Send message to %s (%s)", callID.c_str(), accountId.c_str());
-        // link->sendTextMessage (callID, message, from);
     }
 
     return true;
-- 
GitLab