From 273ac54baafe56ef598853a3d0d021cfb4d1f010 Mon Sep 17 00:00:00 2001 From: Rajesh Taneja Date: Tue, 16 Aug 2011 16:14:58 +0800 Subject: [PATCH] MDL-27219 chat: Beep will not display user fullname if user is not in chat --- mod/chat/chat_ajax.php | 2 +- mod/chat/lib.php | 39 +++++++++++++++++++++++++++++---------- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/mod/chat/chat_ajax.php b/mod/chat/chat_ajax.php index 6d665232cf5..d9e6b374829 100644 --- a/mod/chat/chat_ajax.php +++ b/mod/chat/chat_ajax.php @@ -135,7 +135,7 @@ case 'update': $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)) { diff --git a/mod/chat/lib.php b/mod/chat/lib.php index a59a5e2fe7b..a462b6e2d65 100644 --- a/mod/chat/lib.php +++ b/mod/chat/lib.php @@ -898,13 +898,14 @@ function chat_format_message($message, $courseid, $currentuser, $chat_lastrow=NU /** * @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 @@ -927,8 +928,10 @@ function chat_format_message_theme ($message, $courseid, $currentuser, $theme = $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); @@ -968,6 +971,9 @@ function chat_format_message_theme ($message, $courseid, $currentuser, $theme = $special = false; $outtime = $message->strtime; + //Initilise output variable. + $outmain = ''; + if (substr($text, 0, 5) == 'beep ') { $special = true; /// It's a beep! @@ -979,9 +985,17 @@ function chat_format_message_theme ($message, $courseid, $currentuser, $theme = } 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; @@ -1043,7 +1057,12 @@ function chat_format_message_theme ($message, $courseid, $currentuser, $theme = $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; + } }