XMPP service ... remove from tech preview, as several
[citadel.git] / citadel / modules / jabber / xmpp_queue.c
index 744c4ce3fa6803f8e084de0cd4eff400bd1f4f0a..a6e99bb1de40131126854c2e664d9a9c1eace932 100644 (file)
 #include <expat.h>
 #include "serv_xmpp.h"
 
-
+int queue_event_seq = 0;
 
 void xmpp_queue_event(int event_type, char *email_addr) {
 
-       static int seq = 0;
        struct xmpp_event *xptr = NULL;
        struct xmpp_event *new_event = NULL;
        struct xmpp_event *last = NULL;
@@ -79,8 +78,9 @@ void xmpp_queue_event(int event_type, char *email_addr) {
        new_event = (struct xmpp_event *) malloc(sizeof(struct xmpp_event));
        new_event->next = NULL;
        new_event->event_time = time(NULL);
-       new_event->event_seq = ++seq;
+       new_event->event_seq = ++queue_event_seq;
        new_event->event_type = event_type;
+       new_event->session_which_generated_this_event = CC->cs_pid;
        safestrncpy(new_event->event_jid, email_addr, sizeof new_event->event_jid);
 
        /* Add it to the list */
@@ -117,7 +117,22 @@ void xmpp_process_events(void) {
        for (xptr=xmpp_queue; xptr!=NULL; xptr=xptr->next) {
                if (xptr->event_seq > XMPP->last_event_processed) {
 
-                       /* FIXME do something */
+                       switch(xptr->event_type) {
+
+                               case XMPP_EVT_LOGIN:
+                                       if (xptr->session_which_generated_this_event != CC->cs_pid) {
+                                               xmpp_presence_notify(xptr->event_jid, "available");
+                                       }
+                                       break;
+
+                               case XMPP_EVT_LOGOUT:
+                                       if (xptr->session_which_generated_this_event != CC->cs_pid) {
+                                               xmpp_presence_notify(xptr->event_jid, "unavailable");
+                                               xmpp_presence_notify(xptr->event_jid, "unsubscribed");
+                                       }
+                                       break;
+
+                       }
 
                        if (xptr->event_seq > highest_event) {
                                highest_event = xptr->event_seq;