Index: chatroom.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/chatroom/Attic/chatroom.js,v
retrieving revision 1.43.2.5
diff -u -p -r1.43.2.5 chatroom.js
--- chatroom.js	8 Feb 2007 17:54:32 -0000	1.43.2.5
+++ chatroom.js	19 Feb 2007 17:17:03 -0000
@@ -55,6 +55,10 @@ var chatroomMsgCallback = function(respo
           chatroom.cacheTimestamp = resArray[i].cacheTimestamp;
           continue;
         }
+        if (typeof resArray[i].time != 'undefined') {
+          chatroom.time = resArray[i].time;
+          continue;
+        }
         if (typeof resArray[i].msgs != 'undefined') {
           chatroomUpdateMsgList(resArray[i].msgs);
           continue;
@@ -392,12 +396,14 @@ function chatroomUpdateChatOnlineList(up
     return;
   }
   var usersToDelete = [];
-  var deleteFlag = true;
+  var deleteFlag = false;
 
   // loop through the user list
   for (var i = 0; i < chatroom.userList.length; i++) {
 
-    deleteFlag = true;
+    if (chatroom.time > (chatroom.cacheTimestamp + 15)) {
+      deleteFlag = true;
+    }
     for (var j = 0; j < updateUsers.length; j++) {
       // if the user in the browser list is in the list from the server
       if (chatroom.userList[i].sessionId == updateUsers[j].sessionId) {
Index: chatroom.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/chatroom/Attic/chatroom.module,v
retrieving revision 1.50.2.40
diff -u -p -r1.50.2.40 chatroom.module
--- chatroom.module	5 Feb 2007 18:29:53 -0000	1.50.2.40
+++ chatroom.module	19 Feb 2007 17:17:06 -0000
@@ -696,8 +696,7 @@ function chatroom_block_chat_online_list
   }
   $title   = '';
   $content = '';
-  $cache_timestamp = @file_exists($cache_file) ? @filemtime($cache_file) : time();
-  if ($users = chatroom_chat_get_online_list($matches[1], $cache_timestamp)) {
+  if ($users = chatroom_chat_get_online_list($matches[1])) {
     $content = '<ul class="menu" id="chatroom-online">';
     foreach ($users as $ol_user) {
       $name = $ol_user->name ? check_plain($ol_user->name) : "guest-{$ol_user->guest_id}";
@@ -948,6 +947,8 @@ function chatroom_archive_old_msgs($chat
 function chatroom_chat_register_user($chat_id) {
   global $user;
   $session_id = session_id();
+  $cache_file = file_directory_temp() .'/drupal_chat_cache/'. chatroom_chat_get_cache_file_name($chat_id);
+  chatroom_chat_update_cache($cache_file);
   $result = db_query("SELECT coid
                       FROM   {chatroom_online_list}
                       WHERE  ccid = %d
@@ -982,8 +983,7 @@ function chatroom_chat_add_state_js($cha
   global $base_url;
 
   $users_js = '[]';
-  $cache_timestamp = @file_exists($cache_file) ? @filemtime($cache_file) : time();
-  if ($users = chatroom_chat_get_online_list($chat->ccid, $cache_timestamp)) {
+  if ($users = chatroom_chat_get_online_list($chat->ccid)) {
     $users_js = chatroom_chat_get_online_list_js($users);
   }
   $kick_url       = url('chatrooms/kicked/user');
@@ -995,7 +995,7 @@ function chatroom_chat_add_state_js($cha
   $cache_file     = file_directory_temp() .'/drupal_chat_cache/'. chatroom_chat_get_cache_file_name($chat->ccid);
   $smileys_base   = drupal_get_path('module', 'smileys') ? "'". drupal_get_path('module', 'smileys') ."'" : 'false';
   $smileys_marker = '------';
-  $timestamp      = 0;
+  $cache_timestamp = @file_exists($cache_file) ? @filemtime($cache_file) : time() - 5;
   $online_list    = variable_get('chatroom_online_list', 0) ? 'true' : 'true';
 
   // timezone support
@@ -1009,7 +1009,7 @@ function chatroom_chat_add_state_js($cha
   $js = <<<JS
 var chatroom = {chatId         : $chat->ccid,
                 lastMsgId      : 0,
-                cacheTimestamp : $timestamp,
+                cacheTimestamp : $cache_timestamp,
                 updateCount    : 0,
                 chatUrl        : '$chat_url',
                 kickUrl        : '$kick_url',
@@ -1146,19 +1146,13 @@ function chatroom_chat_read_msgs($chat_i
   else {
     $msg_js = '[]';
   }
-  $users_js = '[]';
-  $cache_timestamp = @file_exists($cache_file) ? @filemtime($cache_file) : time();
-  if ($users = chatroom_chat_get_online_list($chat_id, $cache_timestamp)) {
+  if ($users = chatroom_chat_get_online_list($chat_id, $cache_file)) {
     $users_js = chatroom_chat_get_online_list_js($users, true);
   }
-  $cache_js = '';
-  if (empty($last_msg_id)) {
-    $cache_timestamp = chatroom_chat_update_cache($cache_file);
-  }
-  if ($cache_timestamp) {
-    $cache_js = ",{cacheTimestamp:$cache_timestamp}";
-  }
-  return chatroom_send_ajax_response("[$msg_js, $users_js $cache_js]");
+  $cache_timestamp = @file_exists($cache_file) ? @filemtime($cache_file) : time() - 5;
+  $cache_js = ",{cacheTimestamp:$cache_timestamp}";
+  $time = ",{time:". time() ."}";
+  return chatroom_send_ajax_response("[$msg_js, $users_js $cache_js $time]");
 }
 
 /**
@@ -1188,16 +1182,14 @@ function chatroom_chat_write_msg($chat_i
     $msg_js = '[]';
   }
   $users_js = '[]';
-  $cache_timestamp  = @file_exists($cache_file) ? @filemtime($cache_file) : time();
-  if ($users = chatroom_chat_get_online_list($chat_id, $cache_timestamp)) {
+  if ($users = chatroom_chat_get_online_list($chat_id, $cache_file)) {
     $users_js = chatroom_chat_get_online_list_js($users, true);
   }
   $cache_js = '';
   $cache_timestamp = chatroom_chat_update_cache($cache_file);
-  if ($cache_timestamp) {
-    $cache_js = ",{cacheTimestamp:$cache_timestamp}";
-  }
-  return chatroom_send_ajax_response("[$msg_js, $users_js $cache_js]");
+  $cache_js = ",{cacheTimestamp:$cache_timestamp}";
+  $time = ",{time:". time() ."}";
+  return chatroom_send_ajax_response("[$msg_js, $users_js $cache_js $time]");
 }
 
 /**
@@ -1218,16 +1210,14 @@ function chatroom_chat_set_away_status($
     $msg_js = '[]';
   }
   $users_js = '[]';
-  $cache_timestamp  = @file_exists($cache_file) ? @filemtime($cache_file) : time();
-  if ($users = chatroom_chat_get_online_list($chat_id, $cache_timestamp)) {
+  if ($users = chatroom_chat_get_online_list($chat_id, $cache_file)) {
     $users_js = chatroom_chat_get_online_list_js($users, true);
   }
   $cache_js = '';
   $cache_timestamp = chatroom_chat_update_cache($cache_file);
-  if ($cache_timestamp) {
-    $cache_js = ",{cacheTimestamp:$cache_timestamp}";
-  }
-  return chatroom_send_ajax_response("[$msg_js, $users_js $cache_js]");
+  $cache_js = ",{cacheTimestamp:$cache_timestamp}";
+  $time = ",{time:". time() ."}";
+  return chatroom_send_ajax_response("[$msg_js, $users_js $cache_js $time]");
 }
 
 /**
@@ -1629,10 +1619,8 @@ function chatroom_get_chatroom_list($sta
  * gets a list of online users in a given chat
  * returns the current user at the top of the list
  */
-function chatroom_chat_get_online_list($chat_id, $cache_timestamp = NULL) {
-  if (empty($cache_timestamp)) {
-    $cache_timestamp = time();
-  }
+function chatroom_chat_get_online_list($chat_id, $cache_file = NULL) {
+  $cache_timestamp = @file_exists($cache_file) ? @filemtime($cache_file) : time() - 5;
   $result = db_query('SELECT     col.uid,
                                  col.session_id,
                                  col.guest_id,
@@ -1645,7 +1633,7 @@ function chatroom_chat_get_online_list($
                       LEFT JOIN  {users} AS du
                       ON         du.uid = col.uid
                       WHERE      col.ccid = %d
-                      AND        col.modified > (%d - 5)',
+                      AND        col.modified >= %d',
                       $chat_id, $cache_timestamp);
   $users = array();
   $session_id = session_id();
Index: chatroomread.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/chatroom/Attic/chatroomread.php,v
retrieving revision 1.23.2.7
diff -u -p -r1.23.2.7 chatroomread.php
--- chatroomread.php	23 Jan 2007 19:01:40 -0000	1.23.2.7
+++ chatroomread.php	19 Feb 2007 17:17:06 -0000
@@ -92,7 +92,7 @@ if (isset($_POST['chat_id'])) {
   if ($write_request === false) {
     // see if we have a cache hit by comparing the timestamps
     if (@file_exists($chat_cache_file)) {
-      if ($browser_timestamp >= @filemtime($chat_cache_file)) {
+      if ($browser_timestamp == @filemtime($chat_cache_file) && time() > $browser_timestamp + 20) {
         echo '/** UR3l33T! 6 **/';
         exit;
       }
