diff --git a/mod/chat/lib.php b/mod/chat/lib.php index 9c4f050a9d6..7e2aaada979 100644 --- a/mod/chat/lib.php +++ b/mod/chat/lib.php @@ -29,6 +29,9 @@ require_once($CFG->dirroot.'/calendar/lib.php'); // 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 ( is used to get some browsers starting with output. global $CHAT_HTMLHEAD; $CHAT_HTMLHEAD = "\n\n\n".padding(200); @@ -1493,7 +1496,6 @@ function mod_chat_core_calendar_provide_event_action(calendar_event $event, */ function chat_get_sessions($messages, $showall = false) { $sessions = []; - $sessiongap = 5 * 60; // 5 minutes silence means a new session. $start = 0; $end = 0; $sessiontimes = []; @@ -1509,7 +1511,7 @@ function chat_get_sessions($messages, $showall = false) { } // 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; } diff --git a/mod/chat/locallib.php b/mod/chat/locallib.php index 98e1ab0df24..06635fb8f3b 100644 --- a/mod/chat/locallib.php +++ b/mod/chat/locallib.php @@ -116,14 +116,13 @@ class chat_portfolio_caller extends portfolio_module_caller_base { 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 .= '
'; $content .= userdate($message->timestamp); } diff --git a/mod/chat/tests/lib_test.php b/mod/chat/tests/lib_test.php index cd9c9e90aec..b233af18aa8 100644 --- a/mod/chat/tests/lib_test.php +++ b/mod/chat/tests/lib_test.php @@ -214,7 +214,6 @@ class mod_chat_lib_testcase extends advanced_testcase { */ public function test_chat_get_sessions_multiple() { $messages = []; - $widegap = 5 * 60; // 5 mins. $gap = 5; // 5 secs. $now = time(); @@ -282,7 +281,7 @@ class mod_chat_lib_testcase extends advanced_testcase { if ($i == 10 || $i == 25) { // New session. $session++; - $timestamp += $widegap + 1; + $timestamp += CHAT_SESSION_GAP + 1; } else { $timestamp += $gap; }