CHAT_MOD/MDL-14651

1. support BEEP message
2. add "console" object to debug
This commit is contained in:
dongsheng 2008-11-19 04:22:10 +00:00
parent 1686b89a54
commit 2c907a53b6
4 changed files with 19 additions and 18 deletions

View file

@ -5,13 +5,14 @@ function microtime_float(){
return ((float)$usec+(float)$sec); return ((float)$usec+(float)$sec);
} }
function format_user_list(&$data, $course) { function format_user_list($data, $course) {
global $CFG, $DB; global $CFG, $DB;
$users = array(); $users = array();
foreach($data as $v){ foreach($data as $v){
$user['name'] = fullname($v); $user['name'] = fullname($v);
$user['url'] = $CFG->wwwroot.'/user/view.php?id='.$v->id.'&course='.$course->id; $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['picture'] = print_user_picture($v->id, 0, $v->picture, false, true, false);
$user['id'] = $v->id;
$users[] = $user; $users[] = $user;
} }
return $users; return $users;

View file

@ -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/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" /> <link rel="stylesheet" type="text/css" href="<?php echo $CFG->httpswwwroot;?>/lib/yui/button/assets/skins/sam/button.css" />
<?php <?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'); 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> <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 id="msg_list">
<ul> <ul>
</div> </div>
<div id="notify">
</div>
</body> </body>
</html> </html>

View file

@ -3,7 +3,8 @@ include('../../../config.php');
include('../lib.php'); include('../lib.php');
$chat_sid = required_param('chat_sid', PARAM_ALPHANUM); $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))) { if (!$chatuser = $DB->get_record('chat_users', array('sid'=>$chat_sid))) {
echo 'invalid sid'; echo 'invalid sid';
@ -24,11 +25,9 @@ session_write_close();
chat_delete_old_users(); chat_delete_old_users();
$chat_message = clean_text($chat_message, FORMAT_MOODLE); $chat_message = clean_text($chat_message, FORMAT_MOODLE);
//TODO: Before insert the chat message into database, we should push the if (!empty($beep_id)) {
//message into a global object (which can hold 100 messages), when user request $chat_message = 'beep '.$beep_id;
//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($chat_message)) { if (!empty($chat_message)) {
$message = new object(); $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); add_to_log($course->id, 'chat', 'talk', "view.php?id=$cm->id", $chat->id, $cm->id);
} }
?>

View file

@ -109,10 +109,10 @@ header('Content-Type: text/html; charset=utf-8');
ob_start(); ob_start();
$beep = false;
$sendlist = false; $sendlist = false;
if ($messages && ($chat_lasttime != $chat_newlasttime)) { if ($messages && ($chat_lasttime != $chat_newlasttime)) {
foreach ($messages as $n => &$message) { foreach ($messages as $n => &$message) {
$tmp = new stdclass;
// when somebody enter room, user list will be updated // when somebody enter room, user list will be updated
if($message->system == 1){ if($message->system == 1){
$sendlist = true; $sendlist = true;
@ -123,11 +123,15 @@ if ($messages && ($chat_lasttime != $chat_newlasttime)) {
} }
$users = format_user_list($users, $course); $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) { 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; $response['users'] = $users;
} }
if ($beep) {
$response['beep'] = true;
}
$response['lasttime'] = $chat_newlasttime; $response['lasttime'] = $chat_newlasttime;
$response['lastrow'] = $chat_newrow; $response['lastrow'] = $chat_newrow;
if($messages){ if($messages){