diff options
author | Patrick Davison <snapwilliam@gmail.com> | 2013-09-25 13:51:41 -0700 |
---|---|---|
committer | Patrick Davison <snapwilliam@gmail.com> | 2013-09-25 13:51:41 -0700 |
commit | 739e810b412d3b79d009e5e847c973ae11ef8a0e (patch) | |
tree | a3bd34363d2dc423c738f6bf16940f1e4824f3e3 | |
parent | 6200fe3fad7e3630410ed1e6d18203a9ec80a155 (diff) | |
parent | 9c20000fb8871437dafb41ec830afbf56a746a57 (diff) | |
download | pathery-739e810b412d3b79d009e5e847c973ae11ef8a0e.tar.xz |
Merge branch 'Messing_with_chat' of ssh://git@git.raylu.net/pathery
-rw-r--r-- | ajax/chat.ajax.php | 35 | ||||
-rw-r--r-- | includes/chats.php | 16 |
2 files changed, 19 insertions, 32 deletions
diff --git a/ajax/chat.ajax.php b/ajax/chat.ajax.php index 02a11c6..f9370aa 100644 --- a/ajax/chat.ajax.php +++ b/ajax/chat.ajax.php @@ -111,35 +111,22 @@ if (isset($_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($getChatID);
- if ($data !== false) {
- //$data['debug'][] = "Count times: $i";
- //$data['debug'][] = "Count value:".count($data);
- echo prepareChatData($data);
- exit;
- }
- //Wait .1 seconds
- usleep(100000);
- }
+ $data = getChat($getChatID);
+ echo prepareChatData($data);
+ exit;
}
- $json = prepareChatData(getChat($getChatID));
- echo $json;
}
exit;
function prepareChatData($data) {
- if ($data) {
- foreach($data as &$user) {
- //$user['message'] = $user['message'].'write-append';
- $user['secondsSince'] = strtotime($user['dateSent']) - strtotime("now");
- }
- return json_encode($data);
+ if (!$data)
+ {
+ return false;
+ }
+ foreach($data as &$user) {
+ //$user['message'] = $user['message'].'write-append';
+ $user['secondsSince'] = strtotime($user['dateSent']) - strtotime("now");
}
- return $data;
+ return json_encode($data);
}
?>
\ No newline at end of file diff --git a/includes/chats.php b/includes/chats.php index 7db4c58..f55ce35 100644 --- a/includes/chats.php +++ b/includes/chats.php @@ -44,12 +44,17 @@ function addChat($userID, $message) { $ID = $stmt->insert_id;
$stmt->close();
+
+ //Turnicate messages.
+ $deleteFromID = $ID - CHAT_ROWS_TO_KEEP;
+ $mysqli->query("DELETE FROM `chat` WHERE `ID` < $deleteFromID");
+ $mysqli->close();
+
return $ID;
}
function getChat($startID = 0) {
global $mysqli;
- $array = array();
if (!is_numeric($startID)) return false;
@@ -68,7 +73,7 @@ function getChat($startID = 0) { LEFT JOIN `users`
ON chat.userID = users.ID
WHERE chat.ID > '$startID'
- ORDER BY chat.ID ASC
+ ORDER BY chat.dateSent ASC, chat.ID ASC
");
$array = array();
if ($res->num_rows == 0) {
@@ -77,16 +82,11 @@ function getChat($startID = 0) { }
while ($response = $res->fetch_assoc()) {
$array[] = $response;
- $lastID = $response['ID'];
}
$res->close();
+ $mysqli->close();
if (count($array) < 1) return false;
-
- //Turnicate messages.
- $deleteFromID = $lastID - CHAT_ROWS_TO_KEEP;
- $mysqli->query("DELETE FROM `chat` WHERE `ID` < $deleteFromID");
- $mysqli->close();
return $array;
}
|