* When searching instant message logs for transcripts to flush, if it is discovered...
authorArt Cancro <ajc@citadel.org>
Mon, 26 Jul 2010 20:23:11 +0000 (20:23 +0000)
committerArt Cancro <ajc@citadel.org>
Mon, 26 Jul 2010 20:23:11 +0000 (20:23 +0000)
citadel/modules/instmsg/serv_instmsg.c
citadel/serv_extensions.c

index fd0fa8e33a07231d0308fcfaa1b9db00f2713a52..a061fc8465c720b0f955dcc10021d3011d69aa2a 100644 (file)
@@ -523,12 +523,38 @@ void flush_conversations_to_disk(time_t if_older_than) {
        struct imlog *flush_these = NULL;
        struct imlog *dont_flush_these = NULL;
        struct imlog *imptr = NULL;
+       struct CitContext *nptr;
+       int nContexts, i;
+
+       nptr = CtdlGetContextArray(&nContexts) ;        /* Make a copy of the current wholist */
 
        begin_critical_section(S_IM_LOGS);
        while (imlist)
        {
                imptr = imlist;
                imlist = imlist->next;
+
+               /* For a two party conversation, if one party has logged out, force flush. */
+               if (nptr) {
+                       int user0_is_still_online = 0;
+                       int user1_is_still_online = 0;
+                       for (i=0; i<nContexts; i++)  {
+                               if (nptr[i].user.usernum == imptr->usernums[0]) ++user0_is_still_online;
+                               if (nptr[i].user.usernum == imptr->usernums[1]) ++user1_is_still_online;
+                       }
+                       if (imptr->usernums[0] != imptr->usernums[1]) {         /* two party conversation */
+                               if ((!user0_is_still_online) || (!user1_is_still_online)) {
+                                       imptr->lastmsg = 0L;    /* force flush */
+                               }
+                       }
+                       else {          /* one party conversation (yes, people do IM themselves) */
+                               if (!user0_is_still_online) {
+                                       imptr->lastmsg = 0L;    /* force flush */
+                               }
+                       }
+               }
+
+               /* Now test this conversation to see if it qualifies for flushing. */
                if ((time(NULL) - imptr->lastmsg) > if_older_than)
                {
                        /* This conversation qualifies.  Move it to the list of ones to flush. */
@@ -543,6 +569,7 @@ void flush_conversations_to_disk(time_t if_older_than) {
        }
        imlist = dont_flush_these;
        end_critical_section(S_IM_LOGS);
+       free(nptr);
 
        /* We are now outside of the critical section, and we are the only thread holding a
         * pointer to a linked list of conversations to be flushed to disk.
index dee9b45499a5e46c5b4f77d928b9de7fd643e592..0617cce0a750a0622258352736915230c5acdb35 100644 (file)
@@ -891,6 +891,9 @@ void PerformSessionHooks(int EventType)
 
        for (fcn = SessionHookTable; fcn != NULL; fcn = fcn->next) {
                if (fcn->eventtype == EventType) {
+                       if (EventType == EVT_TIMER) {
+                               citthread_setspecific(MyConKey, NULL);  /* for every hook */
+                       }
                        (*fcn->h_function_pointer) ();
                }
        }