From 23fb121734394f103aa9bf63d574220b9a3ebdd2 Mon Sep 17 00:00:00 2001
From: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
Date: Tue, 29 Jun 2010 17:30:28 -0400
Subject: [PATCH] [#3620] Receive the message on the client side

---
 sflphone-client-gnome/src/dbus/dbus.c          |  6 +++---
 sflphone-client-gnome/src/sflnotify.c          | 18 ++++++++++++++++++
 sflphone-client-gnome/src/sflnotify.h          |  7 +++++++
 sflphone-common/src/managerimpl.cpp            |  5 +++--
 sflphone-common/src/managerimpl.h              |  2 +-
 .../src/sip/im/InstantMessaging.cpp            | 15 ++++++++++++++-
 sflphone-common/src/sip/im/InstantMessaging.h  |  2 +-
 sflphone-common/src/sip/sipvoiplink.cpp        |  7 +++++--
 8 files changed, 52 insertions(+), 10 deletions(-)

diff --git a/sflphone-client-gnome/src/dbus/dbus.c b/sflphone-client-gnome/src/dbus/dbus.c
index a5273a2ee0..15977c49ff 100644
--- a/sflphone-client-gnome/src/dbus/dbus.c
+++ b/sflphone-client-gnome/src/dbus/dbus.c
@@ -120,11 +120,11 @@ voice_mail_cb(DBusGProxy *proxy UNUSED, const gchar* accountID, const guint nb,
 }
 
 static void
-incoming_message_cb(DBusGProxy *proxy UNUSED, const gchar* accountID UNUSED,
+incoming_message_cb(DBusGProxy *proxy UNUSED, const gchar* callID UNUSED,
     const gchar* msg, void * foo  UNUSED )
 {
-  DEBUG ("Message %s!",msg);
-
+	DEBUG ("Message %s!",msg);
+	notify_incoming_message (callID, msg);
 }
 
 static void
diff --git a/sflphone-client-gnome/src/sflnotify.c b/sflphone-client-gnome/src/sflnotify.c
index 5ac960e003..32a529d77e 100644
--- a/sflphone-client-gnome/src/sflnotify.c
+++ b/sflphone-client-gnome/src/sflnotify.c
@@ -67,6 +67,24 @@ void create_new_gnome_notification (gchar *title, gchar *body, NotifyUrgency urg
     }
 }
 
+    void
+notify_incoming_message (const gchar *callID, const gchar *msg)
+{
+
+        gchar* text;
+        gchar* title;
+
+        title = g_markup_printf_escaped(_("New message"));
+		text = g_markup_printf_escaped (_("%s says: %s"), callID, msg);
+
+        create_new_gnome_notification (title,
+                                        text, 
+                                        NOTIFY_URGENCY_CRITICAL, 
+                                        (g_strcasecmp(__TIMEOUT_MODE, "default") == 0 )? __TIMEOUT_TIME : NOTIFY_EXPIRES_NEVER,
+                                        &_gnome_notification); 
+}
+
+
 
     void
 notify_incoming_call (callable_obj_t* c)
diff --git a/sflphone-client-gnome/src/sflnotify.h b/sflphone-client-gnome/src/sflnotify.h
index 71cfc91665..8734abec03 100644
--- a/sflphone-client-gnome/src/sflnotify.h
+++ b/sflphone-client-gnome/src/sflnotify.h
@@ -62,6 +62,13 @@ void free_notification (GnomeNotification *g);
  */
 void notify_incoming_call( callable_obj_t* c);
 
+/**
+ * Notify an incoming text message
+ * A dialog box is attached to the status icon
+ * @param c The incoming message
+ */
+void notify_incoming_message (const gchar *callID, const gchar *msg);
+
 /**
  * Notify voice mails count
  * An info box is attached to the status icon
diff --git a/sflphone-common/src/managerimpl.cpp b/sflphone-common/src/managerimpl.cpp
index da9bbcf51f..41c9677e82 100644
--- a/sflphone-common/src/managerimpl.cpp
+++ b/sflphone-common/src/managerimpl.cpp
@@ -1611,11 +1611,12 @@ bool ManagerImpl::incomingCall (Call* call, const AccountID& accountId) {
 	return true;
 }
 
+
 //THREAD=VoIP
-void ManagerImpl::incomingMessage (const AccountID& accountId,
+void ManagerImpl::incomingMessage (const CallID& callID,
 				   const std::string& message) {
 	if (_dbus) {
-		_dbus->getCallManager()->incomingMessage(accountId, message);
+		_dbus->getCallManager()->incomingMessage (callID, message);
 	}
 }
 
diff --git a/sflphone-common/src/managerimpl.h b/sflphone-common/src/managerimpl.h
index 700bb1721d..5a42426d44 100644
--- a/sflphone-common/src/managerimpl.h
+++ b/sflphone-common/src/managerimpl.h
@@ -398,7 +398,7 @@ class ManagerImpl {
      * @param accountId	The account identifier
      * @param message The content of the message
      */
-    void incomingMessage(const AccountID& accountId, const std::string& message);
+    void incomingMessage(const CallID& callId, const std::string& message);
 
     /**
      * Notify the client he has voice mails
diff --git a/sflphone-common/src/sip/im/InstantMessaging.cpp b/sflphone-common/src/sip/im/InstantMessaging.cpp
index b42f5ae8aa..691ef6e877 100644
--- a/sflphone-common/src/sip/im/InstantMessaging.cpp
+++ b/sflphone-common/src/sip/im/InstantMessaging.cpp
@@ -13,13 +13,26 @@ namespace sfl {
 		return PJ_SUCCESS;
 	}
 
-	pj_status_t InstantMessaging::receive (std::string message, CallID& id) {
+	std::string InstantMessaging::receive (std::string message, CallID& id) {
 
 		// We just receive a TEXT message. Before sent it to the recipient, we must assure that the message is complete.
 		// We should use a queue to push these messages in
 
+		_debug ("New message : %s", message.c_str ());
+
+		// TODO Archive the messages
+		// TODO Security check
+		// TODO String cleaning
+
+		return message;
+
 	}
 
+	pj_status_t InstantMessaging::notify (CallID& id) {
+		
+		// Notify the clients through a D-Bus signal
+
+	}
 
 	pj_status_t InstantMessaging::send (pjsip_inv_session *session, const std::string& text) {
 
diff --git a/sflphone-common/src/sip/im/InstantMessaging.h b/sflphone-common/src/sip/im/InstantMessaging.h
index 78749c7423..3c9acecbfd 100644
--- a/sflphone-common/src/sip/im/InstantMessaging.h
+++ b/sflphone-common/src/sip/im/InstantMessaging.h
@@ -43,7 +43,7 @@ namespace sfl  {
   			 * @param message	The message contained in the TEXT message
 			 * @param id		The call recipient of the message
 			 */
-			pj_status_t receive (std::string message, CallID& id);
+			std::string receive (std::string message, CallID& id);
 
 			/*
 			 * Send a SIP string message inside a call 
diff --git a/sflphone-common/src/sip/sipvoiplink.cpp b/sflphone-common/src/sip/sipvoiplink.cpp
index afdfdde80f..75da8298e7 100644
--- a/sflphone-common/src/sip/sipvoiplink.cpp
+++ b/sflphone-common/src/sip/sipvoiplink.cpp
@@ -3409,8 +3409,11 @@ void call_on_tsx_changed (pjsip_inv_session *inv, pjsip_transaction *tsx, pjsip_
 			pjsip_dlg_create_response (inv->dlg, r_data, PJSIP_SC_OK, NULL, &t_data);
 			pjsip_dlg_send_response (inv->dlg, tsx, t_data);
 
-			imModule->receive (message, call->getCallId ());
-
+			// Pass through the instant messaging module if needed
+			// Right now, it does do anything.
+			// And notify the clients
+			Manager::instance ().incomingMessage (	call->getCallId (), 
+													imModule->receive (message, call->getCallId ()));
 		}
 
 			
-- 
GitLab