$messages = $DB->get_records_select('chat_messages_current', 'chatid = :chatid AND timestamp > :lasttime ' . $groupselect, $params, 'timestamp ASC'); if (!empty($messages)) { $num = count($messages); } else { $num = 0; } $chat_newrow = ($chat_lastrow + $num) % 2; $send_user_list = false; if ($messages && $chat_lasttime != $chat_newlasttime) { foreach ($messages as $n => &$message) { $tmp = new stdClass(); // when somebody enter room, user list will be updated if (!empty($message->system)) { $send_user_list = true; } if ($html = chat_format_message_theme($message, $chatuser, $USER, $cm->groupingid, $theme)) { $message->mymessage = $USER->id == $message->userid; $message->message = $html->html; if (!empty($html->type)) { $message->type = $html->type; } } else { unset($messages[$n]); } } } if ($send_user_list) { // return users when system message coming $users = chat_format_userlist(chat_get_users($chatuser->chatid, $chatuser->groupid, $cm->groupingid), $course); $response['users'] = $users; }
if (!empty($messages)) { $num = count($messages); } else { $num = 0; } $chat_newrow = ($chat_lastrow + $num) % 2; $send_user_list = false; if ($messages && $chat_lasttime != $chat_newlasttime) { foreach ($messages as $n => &$message) { $tmp = new stdClass(); // when somebody enter room, user list will be updated if (!empty($message->system)) { $send_user_list = true; $users = chat_format_userlist(chat_get_users($chatuser->chatid, $chatuser->groupid, $cm->groupingid), $course); } if ($html = chat_format_message_theme($message, $chatuser->course, $USER, $theme)) { $message->mymessage = $USER->id == $message->userid; $message->message = $html->html; if (!empty($html->type)) { $message->type = $html->type; } } else { unset($messages[$n]); } } } if (!empty($users) && $send_user_list) { // return users when system message coming $response['users'] = $users; } $DB->set_field('chat_users', 'lastping', time(), array('id' => $chatuser->id));