From c7d671712a9d5f90752475960c3a602aeb0da8d0 Mon Sep 17 00:00:00 2001 From: Patrick Davison Date: Tue, 15 Jan 2013 01:40:54 -0800 Subject: Chat cleanup --- ajax_chat.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'ajax_chat.php') diff --git a/ajax_chat.php b/ajax_chat.php index 37521de..04a6fd4 100644 --- a/ajax_chat.php +++ b/ajax_chat.php @@ -20,13 +20,14 @@ if ($_REQUEST['messages']) { if ($_REQUEST['getChatFromID']) { + $getChatID = $_REQUEST['getChatFromID']; if ($sent) { //Wait .2 seconds usleep(200000); //echo "yesSent"; for( $i = 1; $i < 3; $i++) { //echo "loop"; - $data = getChat($_REQUEST['getChatFromID']); + $data = getChat($getChatID); if ($data !== false) { //$data['debug'][] = "Count times: $i"; //$data['debug'][] = "Count value:".count($data); @@ -38,17 +39,20 @@ if ($_REQUEST['getChatFromID']) { } } //echo "reachedEnd"; - $json = prepareChatData(getChat($_REQUEST['getChatFromID'])); + $json = prepareChatData(getChat($getChatID)); echo $json; exit; } function prepareChatData($data) { - foreach($data as &$user) { - //$user['message'] = $user['message'].'write-append'; - $user['secondsSince'] = strtotime($user['dateSent']) - strtotime("now"); + if ($data) { + foreach($data as &$user) { + //$user['message'] = $user['message'].'write-append'; + $user['secondsSince'] = strtotime($user['dateSent']) - strtotime("now"); + } + return json_encode($data); } - return json_encode($data); + return $data; } -- cgit v1.2.3