From 1d1e7d369080702f82a4cf1cc528928a54e6a6b2 Mon Sep 17 00:00:00 2001 From: Snap Date: Tue, 5 May 2015 16:47:00 -0700 Subject: Partial multiple channels for chat implementation --- includes/chats.php | 29 ++++++++++++++++------------- js/chat.js | 5 +++++ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/includes/chats.php b/includes/chats.php index d9616fd..92bd90e 100644 --- a/includes/chats.php +++ b/includes/chats.php @@ -34,27 +34,27 @@ function muteUser($userID, $numMinutes) { -function addChat($userID, $message) { +function addChat($userID, $message, $channel = 1) { global $mysqli; if ($message == '') return; $stmt = $mysqli->prepare("INSERT INTO `chat` - (`userID`, `message`) - VALUES (?, ?)"); - $stmt->bind_param('is', $userID, $message); + (`userID`, `message`, `channel`) + VALUES (?, ?, ?)"); + $stmt->bind_param('isi', $userID, $message, $channel); $stmt->execute(); $ID = $stmt->insert_id; $stmt->close(); //Turnicate messages. - $deleteFromID = $ID - CHAT_ROWS_TO_KEEP; - $mysqli->query("DELETE FROM `chat` WHERE `ID` < $deleteFromID"); + //$deleteFromID = $ID - CHAT_ROWS_TO_KEEP; + //$mysqli->query("DELETE FROM `chat` WHERE `ID` < $deleteFromID"); return $ID; } -function getChat($startID = 0) { +function getChat($startID = 0, $channel = 1) { global $mysqli; if (!is_numeric($startID)) return false; @@ -74,19 +74,22 @@ function getChat($startID = 0) { LEFT JOIN `users` ON chat.userID = users.ID WHERE chat.ID > '$startID' - ORDER BY chat.dateSent ASC, chat.ID ASC - ")) { - $array = array(); + AND chat.channel = '$channel' + ORDER BY chat.dateSent DESC, chat.ID DESC + LIMIT " . CHAT_ROWS_TO_KEEP) + ) { + $chatData = array(); if ($res->num_rows == 0) { $res->close(); return false; } while ($response = $res->fetch_assoc()) { - $array[] = $response; + $chatData[] = $response; } $res->close(); - if (count($array) < 1) return false; - return $array; + if (count($chatData) < 1) return false; + $chatData = array_reverse($chatData); + return $chatData; } else { printf("DError: %s\n", $mysqli->error); return false; diff --git a/js/chat.js b/js/chat.js index 1a2aed3..6ea5f8e 100644 --- a/js/chat.js +++ b/js/chat.js @@ -1,4 +1,6 @@ +//TODO: Add an initiateChat() function. + var lastID = 1; //Internet Explorer doesn't support "const" //CONSTANTS: ... @@ -11,8 +13,10 @@ var chatTimerDelayWindowHidden = 90000; var chatTimerDelay = chatTimerDelayDefault; var isChatWindowVisible = true; var skipNextGetChat = false; +var channel = 1; var chatBuffer = new Array(); + getChatTimer(); function getChatTimer() { setTimeout("getChatTimer()", chatTimerDelay); @@ -214,6 +218,7 @@ function prepChat(chat) { var chatIsBusy = false; function getChat(message) { var dataString = 'getChatFromID='+lastID; + dataString += '&channel='+channel; var backup = new Array(); var fncComplete = ''; -- cgit v1.2.3