diff mcabber/src/jabglue.c @ 986:ed697234bd39

Chat states receival (Alexis Hildebrandt) Patch from Alexis Hildebrandt, slightly modified (mostly coding style updates).
author Mikael Berthe <mikael@lilotux.net>
date Sun, 29 Oct 2006 11:43:00 +0100
parents 5b01de4ac5e1
children f47e312560af
line wrap: on
line diff
--- a/mcabber/src/jabglue.c	Sat Oct 28 18:14:22 2006 +0200
+++ b/mcabber/src/jabglue.c	Sun Oct 29 11:43:00 2006 +0100
@@ -51,6 +51,7 @@
 
 static void statehandler(jconn, int);
 static void packethandler(jconn, jpacket);
+void handle_state_events(char* from, xmlnode xmldata);
 
 static void logger(jconn j, int io, const char *buf)
 {
@@ -429,6 +430,22 @@
     y = xmlnode_insert_tag(x, "subject");
     xmlnode_insert_cdata(y, subject, (unsigned) -1);
   }
+
+  // TODO: insert event notifications request
+#undef USE_JEP_85
+#ifdef USE_JEP_85
+#define NS_CHAT_STATES    "http://jabber.org/features/chatstates"
+  // JEP-85
+  xmlnode event = xmlnode_insert_tag(x, "composing");
+  xmlnode_put_attrib(event, "xmlns", NS_CHAT_STATES);
+#else
+  // JEP-22
+  xmlnode event = xmlnode_insert_tag(x, "x");
+  xmlnode_put_attrib(event, "xmlns", NS_EVENT);
+  xmlnode_insert_tag(event, "composing");
+#endif
+
+
   jab_send(jc, x);
   xmlnode_free(x);
 
@@ -1422,6 +1439,8 @@
     }
   }
 
+  handle_state_events(from, xmldata);
+
   // Not used yet...
   x = xml_get_xmlns(xmldata, NS_ENCRYPTED);
   if (x && (p = xmlnode_get_data(x)) != NULL) {
@@ -1440,6 +1459,52 @@
   g_free(tmp);
 }
 
+void handle_state_events(char* from, xmlnode xmldata)
+{
+  xmlnode x   = NULL;
+  char *rname = strchr(from, JID_RESOURCE_SEPARATOR) + 1;
+  char *jid   = jidtodisp(from);
+  GSList *slist = roster_find(jid, jidsearch, ROSTER_TYPE_USER);
+  if (slist == NULL) return;
+  int jep85 = 0;
+
+  guint events  = buddy_resource_getevents(slist->data, rname);
+
+  x = xml_get_xmlns(xmldata, NS_EVENT);
+  if (x == NULL) {
+      x = xmldata;
+      jep85 = 1;
+  }
+
+  xmlnode tag = xmlnode_get_tag(x, "composing");
+  if (tag != NULL) {
+    events |= ROSTER_EVENT_COMPOSING;
+  } else if (!jep85) {
+    events &= ~ROSTER_EVENT_COMPOSING;
+  }
+
+  if (jep85) {
+      tag = xmlnode_get_tag(x, "paused");
+      if (tag != NULL) {
+        events &= ~ROSTER_EVENT_COMPOSING;
+      }
+  }
+
+  // clear composing and set new message event
+  // if message contains message body
+  if (xmlnode_get_tag_data(xmldata, "body") != NULL) {
+    events |= ROSTER_EVENT_MSG;
+    events &= ~ROSTER_EVENT_COMPOSING;
+  }
+
+  buddy_resource_setevents(slist->data, rname, events);
+
+  scr_UpdateBuddyWindow();
+  scr_DrawRoster();
+
+  g_free(jid);
+}
+
 static void evscallback_subscription(eviqs *evp, guint evcontext)
 {
   char *barejid;