mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 08:26:37 +02:00
CHAT_MOD/MDL-14651
1. support BEEP message 2. add "console" object to debug
This commit is contained in:
parent
1686b89a54
commit
2c907a53b6
4 changed files with 19 additions and 18 deletions
|
@ -5,13 +5,14 @@ function microtime_float(){
|
|||
return ((float)$usec+(float)$sec);
|
||||
}
|
||||
|
||||
function format_user_list(&$data, $course) {
|
||||
function format_user_list($data, $course) {
|
||||
global $CFG, $DB;
|
||||
$users = array();
|
||||
foreach($data as $v){
|
||||
$user['name'] = fullname($v);
|
||||
$user['url'] = $CFG->wwwroot.'/user/view.php?id='.$v->id.'&course='.$course->id;
|
||||
$user['picture'] = print_user_picture($v->id, 0, $v->picture, false, true, false);
|
||||
$user['id'] = $v->id;
|
||||
$users[] = $user;
|
||||
}
|
||||
return $users;
|
||||
|
|
|
@ -60,7 +60,7 @@ if (!$chat_sid = chat_login_user($chat->id, 'ajax', $groupid, $course)) {
|
|||
<link rel="stylesheet" type="text/css" href="<?php echo $CFG->httpswwwroot;?>/lib/yui/layout/assets/skins/sam/layout.css" />
|
||||
<link rel="stylesheet" type="text/css" href="<?php echo $CFG->httpswwwroot;?>/lib/yui/button/assets/skins/sam/button.css" />
|
||||
<?php
|
||||
print_js_config(array('sid'=>$chat_sid,'timer'=>5000, 'chat_lasttime'=>0,'chat_lastrow'=>null, 'header_title'=>$strchat), 'chat_cfg');
|
||||
print_js_config(array('userid'=>$USER->id, 'sid'=>$chat_sid,'timer'=>5000, 'chat_lasttime'=>0,'chat_lastrow'=>null,'header_title'=>$strchat,'chatroom_name'=>$str_title), 'chat_cfg');
|
||||
print_js_config(array('send'=>$str_send, 'sending'=>$str_sending), 'chat_lang');
|
||||
?>
|
||||
<script type="text/javascript" src="<?php echo $CFG->httpswwwroot;?>/lib/yui/yahoo-dom-event/yahoo-dom-event.js"></script>
|
||||
|
@ -93,5 +93,7 @@ print_js_config(array('send'=>$str_send, 'sending'=>$str_sending), 'chat_lang');
|
|||
<ul id="msg_list">
|
||||
<ul>
|
||||
</div>
|
||||
<div id="notify">
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -3,7 +3,8 @@ include('../../../config.php');
|
|||
include('../lib.php');
|
||||
|
||||
$chat_sid = required_param('chat_sid', PARAM_ALPHANUM);
|
||||
$chat_message = required_param('chat_message', PARAM_RAW);
|
||||
$chat_message = optional_param('chat_message', '', PARAM_RAW);
|
||||
$beep_id = optional_param('beep', '', PARAM_RAW);
|
||||
|
||||
if (!$chatuser = $DB->get_record('chat_users', array('sid'=>$chat_sid))) {
|
||||
echo 'invalid sid';
|
||||
|
@ -24,11 +25,9 @@ session_write_close();
|
|||
chat_delete_old_users();
|
||||
$chat_message = clean_text($chat_message, FORMAT_MOODLE);
|
||||
|
||||
//TODO: Before insert the chat message into database, we should push the
|
||||
//message into a global object (which can hold 100 messages), when user request
|
||||
//the lastest messages, we compare the oldest messsage's timestamp $a to user's
|
||||
//timestamp $b, if $a<$b, directly return messages in global object, otherwise,
|
||||
//fetch the message from database.
|
||||
if (!empty($beep_id)) {
|
||||
$chat_message = 'beep '.$beep_id;
|
||||
}
|
||||
|
||||
if (!empty($chat_message)) {
|
||||
$message = new object();
|
||||
|
@ -49,4 +48,3 @@ if (!empty($chat_message)) {
|
|||
|
||||
add_to_log($course->id, 'chat', 'talk', "view.php?id=$cm->id", $chat->id, $cm->id);
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -109,10 +109,10 @@ header('Content-Type: text/html; charset=utf-8');
|
|||
|
||||
ob_start();
|
||||
|
||||
$beep = false;
|
||||
$sendlist = 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($message->system == 1){
|
||||
$sendlist = true;
|
||||
|
@ -123,11 +123,15 @@ if ($messages && ($chat_lasttime != $chat_newlasttime)) {
|
|||
}
|
||||
$users = format_user_list($users, $course);
|
||||
}
|
||||
$html = chat_format_message($message, $chatuser->course, $USER, $chat_lastrow);
|
||||
if ($html = chat_format_message($message, $chatuser->course, $USER, $chat_lastrow)) {
|
||||
if ($html->beep) {
|
||||
$beep = true;
|
||||
$tmp->type = 'beep';
|
||||
}
|
||||
$tmp->msg = $html->html;
|
||||
$message = $tmp;
|
||||
} else {
|
||||
unset($message);
|
||||
}
|
||||
$message = $html->html;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -136,10 +140,6 @@ if($users && $sendlist){
|
|||
$response['users'] = $users;
|
||||
}
|
||||
|
||||
if ($beep) {
|
||||
$response['beep'] = true;
|
||||
}
|
||||
|
||||
$response['lasttime'] = $chat_newlasttime;
|
||||
$response['lastrow'] = $chat_newrow;
|
||||
if($messages){
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue