ekiga r7360 - in trunk: . src/endpoints



Author: dsandras
Date: Sat Nov 15 20:15:51 2008
New Revision: 7360
URL: http://svn.gnome.org/viewvc/ekiga?rev=7360&view=rev

Log:
Fixed various problems with the initial notifications and empty ping back
notifications.
If we receive an initial notification with no status information,
then the user is offline. If we receive a notification with an empty
body then do not update the user status to offline or unknown because
it is just a ping from the server indicating no status change.


Modified:
   trunk/ChangeLog
   trunk/src/endpoints/sip-endpoint.cpp
   trunk/src/endpoints/sip-endpoint.h

Modified: trunk/src/endpoints/sip-endpoint.cpp
==============================================================================
--- trunk/src/endpoints/sip-endpoint.cpp	(original)
+++ trunk/src/endpoints/sip-endpoint.cpp	Sat Nov 15 20:15:51 2008
@@ -371,7 +371,7 @@
     data += "</tuple>\r\n";
     data += "</presence>\r\n";
 
-    Publish (to, data, 300); // TODO: allow to change the 500 
+    Publish (to, data, 500); // TODO: allow to change the 500 
   }
 }
 
@@ -1050,41 +1050,49 @@
   PCaselessString b = basic;
   PCaselessString s = note;
 
-  std::string status;
   std::string presence = "unknown";
+  std::string status;
 
-  if (basic.IsEmpty () && note.IsEmpty ())
-    return;
+  if (!basic.IsEmpty () && !note.IsEmpty ()) {
 
-  if (b.Find ("Open") != P_MAX_INDEX)
-    presence = "online";
-  else
-    presence = "offline";
+    if (b.Find ("Open") != P_MAX_INDEX)
+      presence = "online";
+    else
+      presence = "offline";
 
-  if (s.Find ("Away") != P_MAX_INDEX)
-    presence = "away";
-  else if (s.Find ("On the phone") != P_MAX_INDEX
-           || s.Find ("Ringing") != P_MAX_INDEX) 
-    presence = "inacall";
-  else if (s.Find ("dnd") != P_MAX_INDEX
-           || s.Find ("Do Not Disturb") != P_MAX_INDEX) 
-    presence = "dnd";
+    if (s.Find ("Away") != P_MAX_INDEX)
+      presence = "away";
+    else if (s.Find ("On the phone") != P_MAX_INDEX
+             || s.Find ("Ringing") != P_MAX_INDEX) 
+      presence = "inacall";
+    else if (s.Find ("dnd") != P_MAX_INDEX
+             || s.Find ("Do Not Disturb") != P_MAX_INDEX) 
+      presence = "dnd";
 
-  else if (s.Find ("Free For Chat") != P_MAX_INDEX) 
-    presence = "freeforchat";
+    else if (s.Find ("Free For Chat") != P_MAX_INDEX) 
+      presence = "freeforchat";
 
-  if ((j = s.Find (" - ")) != P_MAX_INDEX)
-    status = (const char *) note.Mid (j + 3);
+    if ((j = s.Find (" - ")) != P_MAX_INDEX)
+      status = (const char *) note.Mid (j + 3);
+  }
 
   SIPURL sip_uri = SIPURL (user);
   sip_uri.Sanitise (SIPURL::ExternalURI);
   std::string _uri = sip_uri.AsString ();
+  std::string old_presence = uri_presences[_uri];
 
-  /**
-   * TODO
-   * Wouldn't it be convenient to emit the signal and have the presence core listen to it ?
-   */
-  runtime->run_in_main (sigc::bind (sigc::ptr_fun (presence_status_in_main), this, _uri, presence, status));
+  // If first notification, and no information, then we are offline
+  if (presence == "unknown" && old_presence.empty ())
+    presence = "offline";
+
+  // If presence change, then signal it to the various components
+  // If presence is unknown (notification with empty body), and it is not the 
+  // first notification, and we can conclude it is a ping back from the server 
+  // to indicate the presence status did not change, hence we do nothing.
+  if (presence != "unknown" && old_presence != presence) {
+    uri_presences[_uri] = presence;
+    runtime->run_in_main (sigc::bind (sigc::ptr_fun (presence_status_in_main), this, _uri, presence, status));
+  }
 }
 
 

Modified: trunk/src/endpoints/sip-endpoint.h
==============================================================================
--- trunk/src/endpoints/sip-endpoint.h	(original)
+++ trunk/src/endpoints/sip-endpoint.h	Sat Nov 15 20:15:51 2008
@@ -193,6 +193,8 @@
       unsigned listen_port;
 
       SIP::Dialect *dialect;
+
+      std::map<std::string, std::string> uri_presences;
     };
   };
 };



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]