diff options
author | Patrick Davison <snapwilliam@gmail.com> | 2014-01-15 01:39:04 -0800 |
---|---|---|
committer | Patrick Davison <snapwilliam@gmail.com> | 2014-01-15 01:39:04 -0800 |
commit | 640816989a99e069397ed18f3fa703d1ec12d596 (patch) | |
tree | cfacd78341fd48044c6b31d2c9b2854ba8b7f791 | |
parent | 64848a7e2a21d5da9a8c32fd45cd892398db1d42 (diff) | |
download | pathery-640816989a99e069397ed18f3fa703d1ec12d596.tar.xz |
More work on channel list.
-rw-r--r-- | ajax/chat.ajax.php | 13 | ||||
-rw-r--r-- | css/chat.css | 4 | ||||
-rw-r--r-- | includes/chats.php | 30 | ||||
-rw-r--r-- | pages/chat.php | 94 |
4 files changed, 125 insertions, 16 deletions
diff --git a/ajax/chat.ajax.php b/ajax/chat.ajax.php index 8302c33..91c5b95 100644 --- a/ajax/chat.ajax.php +++ b/ajax/chat.ajax.php @@ -7,10 +7,15 @@ session_start(); // }
-ini_set('display_errors',1);
-ini_set('display_startup_errors',1);
-error_reporting(-1);
+//ini_set('display_errors',1);
+//ini_set('display_startup_errors',1);
+//error_reporting(-1);
+if (isset($_REQUEST['pollChannelList'])) {
+ require_once('../includes/chats.php');
+ echo json_encode(getChannelList());
+ exit;
+}
if (isset($_SESSION['chatLastReset'])) $chatLastReset = $_SESSION['chatLastReset'];
else $chatLastReset = 0;
@@ -50,7 +55,9 @@ $use_psuedo_longpoll = true; require_once('../includes/chats.php');
+//exit;
+enterChannel($userID);
$sent = false;
if (isset($_REQUEST['messages'])) {
diff --git a/css/chat.css b/css/chat.css index 5973b4d..d0bccab 100644 --- a/css/chat.css +++ b/css/chat.css @@ -89,7 +89,7 @@ font-family: 'Trebuchet MS1', 'Trebuchet MS', sans-serif; font-size: 16px; display: inline-block; - width: 525px; + width: 335px; padding: 5px 5px 5px 5px; white-space: pre-wrap; /* CSS3 */ white-space: -moz-pre-wrap; /* Firefox */ @@ -122,7 +122,7 @@ } .chatMessage { - width:780px; + width:590px; min-height:35px; margin:1px; display:block; diff --git a/includes/chats.php b/includes/chats.php index 0e48ecf..c4a43dc 100644 --- a/includes/chats.php +++ b/includes/chats.php @@ -103,7 +103,7 @@ function enterChannel($userID, $channel = 1) { (`userID`, `channel`, `dateEntered`, `isHere`)
VALUES (?, ?, NOW(), true)
- ON DUPLICATE KEY UPDATE `isHere` = true
+ ON DUPLICATE KEY UPDATE `isHere` = true, dateLastActive = NOW()
");
$stmt->bind_param('ii', $userID, $channel);
$stmt->execute();
@@ -122,6 +122,23 @@ function exitChannel($userID, $channel = 1) { return;
}
+
+function channelListUpdated($timeStamp) {
+ global $mysqli;
+
+ $stmt = $mysqli->prepare("SELECT `value` FROM `settings`
+ WHERE `name` = 'Channel_Last_Update' AND
+ `value` < '?'"
+ );
+ $stmt->bind_param( "i", $timeStamp);
+ $stmt->execute();
+
+ $stmt->bind_result($value);
+
+ return $value;
+}
+
+
//Get a list of users in channel
function getChannelList($channel = 1) {
global $mysqli;
@@ -130,13 +147,15 @@ function getChannelList($channel = 1) { $res = $mysqli->query("
SELECT
- chatUsers.userID,
+ chatUsers.userID as 'ID',
chatUsers.dateEntered,
- chatUsers.dateLastActive,
+
+ TIME_TO_SEC(TIMEDIFF(NOW(), chatUsers.dateLastActive)) as dateLastActive,
+
chatUsers.isAdmin,
chatUsers.isMod,
- users.displayName,
+ users.displayName as 'display',
users.displayColor,
users.wallColor,
users.wallEmblem,
@@ -144,6 +163,7 @@ function getChannelList($channel = 1) { FROM `chatUsers`
LEFT JOIN `users`
ON chatUsers.userID = users.ID
+ WHERE chatUsers.dateLastActive > NOW() - INTERVAL 5 MINUTE
ORDER BY chatUsers.isMod DESC, chatUsers.dateEntered DESC
");
$array = array();
@@ -152,7 +172,7 @@ function getChannelList($channel = 1) { return false;
}
while ($response = $res->fetch_assoc()) {
- $array[] = $response;
+ $array['users'][] = $response;
}
$res->close();
$mysqli->close();
diff --git a/pages/chat.php b/pages/chat.php index f55476f..992d600 100644 --- a/pages/chat.php +++ b/pages/chat.php @@ -20,10 +20,13 @@ if (!$accepted) { <script>
var lastID = 1;
-const chatTimerDelayUpper = 9000;
-const chatTimerDelayLower = 2000;
-const chatTimerDelayDefault = 5000;
-const chatTimerDelayWindowHidden = 90000;
+//Internet Explorer doesn't support "const"
+//CONSTANTS: ...
+var chatTimerDelayUpper = 9000;
+var chatTimerDelayLower = 2000;
+var chatTimerDelayDefault = 5000;
+var chatTimerDelayWindowHidden = 90000;
+
var chatTimerDelay = chatTimerDelayDefault;
var isChatWindowVisible = true;
var skipNextGetChat = false;
@@ -248,6 +251,76 @@ function getChat(message) { });
}
+function pollChannelList() {
+ $.ajax({
+ //type: "POST",
+ url: "ajax/chat.ajax.php?pollChannelList=1",
+ error: function() {
+ console.log('Error: Failed pollChannelList');
+ },
+ success: function(data) {
+ console.log("ChannelPoll data recieved", data);
+ pollChannelListDone(data);
+ }
+ });
+}
+
+function pollChannelListDone(data) {
+
+ console.log('data recieved:', data);
+ if (data.length < 3 || data == 'false') return;
+ json = jQuery.parseJSON(data);
+
+ console.log('Loading channel.');
+ var c = channelListShow(json)
+ console.log(c);
+
+ var b = $("#channelContainer");
+ b.html(c);
+}
+
+
+function channelListShow(JO) {
+ console.log("Formating channelList");
+
+ var p = "<table class='membersList score' style='width:200px; background-color:transparent;'>";
+
+ console.log('beginloop');
+
+ var previousI = 0;
+
+ for (var i in JO.users) {
+ console.log('loop')
+ var u = JO.users[i];
+ var styleClass = '';
+
+ if (previousI != i + 1) {
+ if (previousI < i - 1 && previousI != 0) {
+ styleClass = 'border-top: 6px solid #777799;';
+ }
+ }
+
+ if (u.wallEmblem == undefined) u.wallEmblem = 'blank.png';
+ p = p+ "<tr style='"+styleClass+" background-color: "+u.background+"; color:"+u.displayColor+";' title='Last Active: "+u.dateLastActive+"'>";
+
+ p = p+ "<td style='vertical-align: middle;width:100px;'>";
+ p = p+ " <div class='grid_td' style='float:left; width:35px; height:35px; background:"+u.wallColor+" url("+linkEmblem(u.wallEmblem, u.wallOrientation)+");'>";
+ p = p+ " <div style='background-color:transparent;' class='grid_td_inner grid_td_rocks'>";
+ p = p+ " </div>";
+ p = p+ " </div>";
+ p = p+ " <span class='scoreName' style='float:left;'><a href='achievements?id="+u.ID+"' style='color:"+u.displayColor+"'>"+u.display+"</a></span>";
+ p = p+ "</td>";
+
+ //p = p+ "<td style='text-align:right;'>"+u.championPoints+"</td>";
+ //p = p+ "</tr>";
+ previousI = i;
+ }
+ p = p+"</table>";
+ return p;
+}
+
+
+
function sendChat() {
var message = $("input#message").val().replace("|:|", "||");
if (message == '') return false;
@@ -363,14 +436,21 @@ function setChatMute() { savePref('chatMute', value);
}
+pollChannelList();
+
</script>
<div class='wrapper'>
<h3>Pathery Chat - BETA</h3>
<div class='chatContainer2'>
- <div id='chatContainer'>
- </div>
+
+ <div id='channelContainer' style='float:right; width:200px;'>Loading...</div>
+
+ <div id='chatContainer' style='float:right; width:610px;'></div>
+
+ <div id='bb' style="clear:both"></div>
+
<form id='sendChat' onsubmit="return false">
<? if($accepted) { /*Only show the chat button if we're logged in*/ ?>
<input type="hidden" name="stuff" value="1724">
@@ -386,6 +466,8 @@ function setChatMute() { </form>
</div>
+
+
</div>
<?
|