Fixing global chat bug when refreshing the window see #3565

skala
Julio Montoya 13 years ago
parent 2d05ee14d5
commit 20e75257ae
  1. 63
      main/inc/lib/chat.lib.php
  2. 30
      main/inc/lib/javascript/chat/js/chat.js
  3. 6
      main/inc/lib/main_api.lib.php
  4. 25
      main/inc/lib/social.lib.php

@ -18,20 +18,31 @@ class Chat extends Model {
$this->window_list = $_SESSION['window_list'] = isset($_SESSION['window_list']) ? $_SESSION['window_list'] : array();
}
/**
* Get user chat status
* @return type
*/
function get_user_status() {
$status = UserManager::get_extra_user_data_by_field(api_get_user_id(), 'user_chat_status', false, true);
return $status['user_chat_status'];
}
/*
* Set user chat status
*/
function set_user_status($status) {
UserManager::update_extra_field_value(api_get_user_id(), 'user_chat_status', $status);
}
/*
* Starts a chat session
*/
public function start_session() {
$items = array();
if (isset($_SESSION['chatHistory'])) {
$items = $_SESSION['chatHistory'];
}
}
//print_r($items);
$return = array('user_status' => $this->get_user_status(), 'me' => get_lang('Me'), 'items' => $items);
echo json_encode($return);
exit;
@ -52,18 +63,10 @@ class Chat extends Model {
while ($chat = Database::fetch_array($result,'ASSOC')) {
$chat_list[$chat['from_user']]['items'][] = $chat;
}
}
$items = array();
if (isset($_SESSION['chatHistory'])) {
foreach($_SESSION['chatHistory'] as $user_id => $data) {
if (!empty($data)) {
//$items[$user_id] = $data;
}
}
}
foreach ($chat_list as $from_user_id => $rows) {
$rows = $rows['items'];
$user_info = api_get_user_info($from_user_id, true);
@ -76,16 +79,18 @@ class Chat extends Model {
$item = array( 's' => '0',
'f' => $from_user_id,
'm' => $chat['message'],
'online' => $user_info['user_is_online'],
'm' => $chat['message'],
'username' => $user_info['complete_name'],
'id' => $chat['id']
);
$items[$from_user_id][] = $item;
$items[$from_user_id]['items'][] = $item;
$items[$from_user_id]['user_info']['user_name'] = $user_info['complete_name'];
$items[$from_user_id]['user_info']['online'] = $user_info['user_is_online'];
$_SESSION['openChatBoxes'][$from_user_id] = api_strtotime($chat['sent'],'UTC');
}
$_SESSION['chatHistory'][$from_user_id][] = $item;
$_SESSION['chatHistory'][$from_user_id]['items'][] = $item;
$_SESSION['chatHistory'][$from_user_id]['user_info']['user_name'] = $user_info['complete_name'];
$_SESSION['chatHistory'][$from_user_id]['user_info']['online'] = $user_info['user_is_online'];
}
if (!empty($_SESSION['openChatBoxes'])) {
@ -99,17 +104,16 @@ class Chat extends Model {
$item = array('s' => '2', 'f' => $user_id, 'm' => $message);
if (isset($_SESSION['chatHistory'][$user_id])) {
$_SESSION['chatHistory'][$user_id][] = $item;
}
//$_SESSION['chatHistory'][$user_id][] = $item;
$_SESSION['chatHistory'][$user_id]['items'][] = $item;
}
$_SESSION['tsChatBoxes'][$user_id] = 1;
}
}
}
}
}
//print_r($_SESSION['chatHistory']);
/*
var_dump($_SESSION['openChatBoxes']);
var_dump($_SESSION['tsChatBoxes']);
@ -118,7 +122,7 @@ class Chat extends Model {
*/
//print_r($_SESSION['chatHistory']);
$sql = "UPDATE ".$this->table." SET recd = 1 WHERE to_user = '".$to_user_id."' AND recd = 0";
$query = Database::query($sql);
Database::query($sql);
if ($items != '') {
//$items = substr($items, 0, -1);
@ -143,7 +147,7 @@ class Chat extends Model {
}
function send($from_user_id, $to_user_id, $message) {
$user_info = api_get_user_info($to_user_id, true);
$this->save_window($to_user_id);
$_SESSION['openChatBoxes'][$to_user_id] = api_get_utc_datetime();
@ -152,16 +156,14 @@ class Chat extends Model {
if (!isset($_SESSION['chatHistory'][$to_user_id])) {
$_SESSION['chatHistory'][$to_user_id] = array();
}
/*
$user_info = api_get_user_info($to_user_id);
$complete_name = $user_info['complete_name'];
*/
$item = array ( "s" => "1",
"f" => $from_user_id,
"m" => $messagesan,
"username" => get_lang('Me')
);
$_SESSION['chatHistory'][$to_user_id][] = $item;
$_SESSION['chatHistory'][$to_user_id]['items'][] = $item;
$_SESSION['chatHistory'][$to_user_id]['user_info']['user_name'] = $user_info['complete_name'];
$_SESSION['chatHistory'][$to_user_id]['user_info']['online'] = $user_info['user_is_online'];
unset($_SESSION['tsChatBoxes'][$to_user_id]);
@ -174,6 +176,7 @@ class Chat extends Model {
if (!empty($from_user_id) && !empty($to_user_id)) {
$this->save($params);
}
//print_r($_SESSION['chatHistory']);
echo "1";
exit;
}

@ -136,15 +136,16 @@ function startChatSession() {
startChatHeartBeat();
} else {
stopChatHeartBeat();
}
}
$.each(data.items, function(my_user_id, user_items) {
//received_messages[item.f][item.id] = true;
$.each(user_items, function(i, item) {
my_items = user_items['items'];
$.each(my_items, function(i, item) {
if (item) { // fix strange ie bug
//my_user_id = item.f;
if ($("#chatbox_"+my_user_id).length <= 0) {
createChatBox(my_user_id, item.username, 1, item.online);
//my_user_id = item.f;
if ($("#chatbox_"+my_user_id).length <= 0) {
createChatBox(my_user_id, user_items.user_info.user_name, 1, user_items.user_info.online);
}
if (item.s == 1) {
@ -235,15 +236,15 @@ function chatHeartbeat() {
dataType: "json",
success: function(data) {
$.each(data.items, function(my_user_id, user_items) {
$.each(user_items, function(i, item) {
$.each(data.items, function(my_user_id, user_items) {
my_items = user_items['items'];
$.each(my_items, function(i, item) {
if (item) { // fix strange ie bug
if ($("#chatbox_"+my_user_id).length <= 0) {
createChatBox(my_user_id, item.username, 0, item.online);
createChatBox(my_user_id, my_items.user_info.user_name, 0, my_items.user_info.online);
}
if ($("#chatbox_"+my_user_id).css('display') == 'none') {
$("#chatbox_"+my_user_id).css('display','block');
restructureChatBoxes();
@ -253,19 +254,18 @@ function chatHeartbeat() {
//item.f = username;
}
update_online_user(my_user_id, item.online);
update_online_user(my_user_id, user_items.user_info.online);
if (item.s == 2) {
$("#chatbox_"+my_user_id+" .chatboxcontent").append('<div class="chatboxmessage"><span class="chatboxinfo">'+item.m+'</span></div>');
} else {
newMessages[my_user_id] = {'status':true,'username':item.username};
newMessagesWin[my_user_id] = {'status':true,'username':item.username};
newMessages[my_user_id] = {'status':true, 'username':item.username};
newMessagesWin[my_user_id] = {'status':true, 'username':item.username};
$("#chatbox_"+my_user_id+" .chatboxcontent").append('<div class="chatboxmessage">\n\
<span class="chatboxmessagefrom">'+item.username+':&nbsp;&nbsp;</span>\n\
<span class="chatboxmessagecontent">'+item.m+'</span></div>');
}
$("#chatbox_"+my_user_id+" .chatboxcontent").scrollTop($("#chatbox_"+my_user_id+" .chatboxcontent")[0].scrollHeight);
itemsfound += 1;
}

@ -993,11 +993,11 @@ function api_get_user_info($user_id = '', $check_if_user_is_online = false) {
$user_online_in_chat = 0;
if ($use_status_in_platform) {
$user_status = UserManager::get_extra_user_data_by_field($user_id, 'chat_user_status', false, true);
if (intval($user_status['chat_user_status']) == 1) {
$user_status = UserManager::get_extra_user_data_by_field($user_id, 'user_chat_status', false, true);
if (intval($user_status['user_chat_status']) == 1) {
$user_online_in_chat = 1;
}
}
}
$result_array['user_is_online_in_chat'] = $user_online_in_chat;
}
$user = _api_format_user($result_array);

@ -595,8 +595,7 @@ class SocialManager extends UserManager {
//--- Group image
$group_info = GroupPortalManager::get_group_data($group_id);
$big = GroupPortalManager::get_picture_group($group_id, $group_info['picture_uri'],160,GROUP_IMAGE_SIZE_BIG);
//$original = GroupPortalManager::get_picture_group($group_id, $group_info['picture_uri'],'',GROUP_IMAGE_SIZE_ORIGINAL);
$html .= '<div class="social-content-image">';
$html .= '<div class="social-background-content" onmouseout="hide_icon_edit()" onmouseover="show_icon_edit()">';
$html .= Display::url('<img src='.$big['file'].' class="social-groups-image" /> </a><br /><br />', api_get_path(WEB_PATH).'main/social/groups.php?id='.$group_id);
@ -629,11 +628,7 @@ class SocialManager extends UserManager {
}
if (!in_array($show, array('shared_profile', 'groups', 'group_edit', 'member_list','waiting_list','invite_friends'))) {
//echo Display::div(get_lang('Actions') ,array('class' => 'social_menu_option'));
/*echo '<div align="center" class="social-menu-title">';
echo '<span>'.get_lang('Option').'</span>';
echo '</div>';*/
if (!in_array($show, array('shared_profile', 'groups', 'group_edit', 'member_list','waiting_list','invite_friends'))) {
$html .= '<div class="social_menu_items"><ul>';
$html .= '<li><a href="'.api_get_path(WEB_PATH).'main/social/home.php">'.Display::return_icon('home.png',get_lang('Home'),array('hspace'=>'6')).'<span class="'.($show=='home'?'social-menu-text-active':'social-menu-text4').'" >'.get_lang('Home').'</span></a></li>';
@ -707,22 +702,6 @@ class SocialManager extends UserManager {
}
$html .= '</ul></div>';
/*
// ---- My Agenda Items
$my_agenda_items = show_simple_personal_agenda($user_id);
if (!empty($my_agenda_items)) {
echo '<div class="sectiontitle">';
echo get_lang('MyAgenda');
echo '</div>';
$tbl_personal_agenda = Database :: get_user_personal_table(TABLE_PERSONAL_AGENDA);
echo '<div class="social-content-agenda">';
echo '<div class="social-background-content">';
echo $my_agenda_items;
echo '</div>';
echo '<br /><br />';
echo '</div>';
}
*/
if ($show_full_profile && $user_id == intval(api_get_user_id())) {
$personal_course_list = UserManager::get_personal_session_course_list($user_id);
$course_list_code = array();

Loading…
Cancel
Save