$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)) {
+ 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)) {
/**
* @global object
- * @param object $message
- * @param int $courseid
- * @param object $currentuser
- * @param string $chat_lastrow
+ * @param object $message message to be displayed.
+ * @param mixed $chatuser user chat data
+ * @param object $currentuser current user for whom the message should be displayed.
+ * @param int $groupingid course module grouping id
+ * @param string $theme name of the chat theme.
* @return bool|string Returns HTML or false
*/
-function chat_format_message_theme ($message, $courseid, $currentuser, $theme = 'bubble') {
+function chat_format_message_theme ($message, $chatuser, $currentuser, $groupingid, $theme = 'bubble') {
global $CFG, $USER, $OUTPUT, $COURSE, $DB;
static $users; // Cache user lookups
$tz = get_user_timezone($currentuser->timezone);
$USER->timezone = $tz;
- if (empty($courseid)) {
+ if (empty($chatuser->course)) {
$courseid = $COURSE->id;
+ } else {
+ $courseid = $chatuser->course;
}
$message->strtime = userdate($message->timestamp, get_string('strftimemessage', 'chat'), $tz);
$special = false;
$outtime = $message->strtime;
+ //Initilise output variable.
+ $outmain = '';
+
if (substr($text, 0, 5) == 'beep ') {
$special = true;
/// It's a beep!
} else if ($beepwho == $currentuser->id) { // current user
$outmain = get_string('messagebeepsyou', 'chat', fullname($sender));
} else if ($sender->id == $currentuser->id) { //something is not caught?
-
- $receiver = $DB->get_record('user', array('id'=>$beepwho), 'id,picture,firstname,lastname');
- $outmain = get_string('messageyoubeep', 'chat', fullname($receiver));
+ //allow beep for a active chat user only, else user can beep anyone and get fullname
+ if (!empty($chatuser) && is_numeric($beepwho)) {
+ $chatusers = chat_get_users($chatuser->chatid, $chatuser->groupid, $groupingid);
+ if (array_key_exists($beepwho, $chatusers)) {
+ $outmain = get_string('messageyoubeep', 'chat', fullname($chatusers[$beepwho]));
+ } else {
+ $outmain = get_string('messageyoubeep', 'chat', $beepwho);
+ }
+ } else {
+ $outmain = get_string('messageyoubeep', 'chat', $beepwho);
+ }
}
} else if (substr($text, 0, 1) == '/') { /// It's a user command
$special = true;
$result->html = str_replace($patterns, $replacements, $chattheme_cfg->user_message);
}
- return $result;
+ //When user beeps other user, then don't show any timestamp to other users in chat.
+ if (('' === $outmain) && $special) {
+ return false;
+ } else {
+ return $result;
+ }
}