// Event types.
define('CHAT_EVENT_TYPE_CHATTIME', 'chattime');
+// Gap between sessions. 5 minutes or more of idleness between messages in a chat means the messages belong in different sessions.
+define('CHAT_SESSION_GAP', 300);
+
// The HTML head for the message window to start with (<!-- nix --> is used to get some browsers starting with output.
global $CHAT_HTMLHEAD;
$CHAT_HTMLHEAD = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\"><html><head></head>\n<body>\n\n".padding(200);
*/
function chat_get_sessions($messages, $showall = false) {
$sessions = [];
- $sessiongap = 5 * 60; // 5 minutes silence means a new session.
$start = 0;
$end = 0;
$sessiontimes = [];
}
// If this message's timestamp has been more than the gap, it means it's been idle.
- if ($start - $message->timestamp > $sessiongap) {
+ if ($start - $message->timestamp > CHAT_SESSION_GAP) {
// Mark this as the session end of the next session.
$end = $message->timestamp;
}
public function prepare_package() {
$content = '';
$lasttime = 0;
- $sessiongap = 5 * 60; // 5 minutes silence means a new session
foreach ($this->messages as $message) { // We are walking FORWARDS through messages
$m = clone $message; // grrrrrr - this causes the sha1 to change as chat_format_message changes what it's passed.
$formatmessage = chat_format_message($m, $this->cm->course, $this->user);
if (!isset($formatmessage->html)) {
continue;
}
- if (empty($lasttime) || (($message->timestamp - $lasttime) > $sessiongap)) {
+ if (empty($lasttime) || (($message->timestamp - $lasttime) > CHAT_SESSION_GAP)) {
$content .= '<hr />';
$content .= userdate($message->timestamp);
}
*/
public function test_chat_get_sessions_multiple() {
$messages = [];
- $widegap = 5 * 60; // 5 mins.
$gap = 5; // 5 secs.
$now = time();
if ($i == 10 || $i == 25) {
// New session.
$session++;
- $timestamp += $widegap + 1;
+ $timestamp += CHAT_SESSION_GAP + 1;
} else {
$timestamp += $gap;
}