From fa8c89b543bb6e23cc7cac5983cb61818a4e3139 Mon Sep 17 00:00:00 2001 From: Scott Ostler Date: Sat, 27 Feb 2010 18:28:06 -0500 Subject: in-progress topics --- static/js/pichat.js | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) (limited to 'static/js/pichat.js') diff --git a/static/js/pichat.js b/static/js/pichat.js index b847f58..8917e7c 100755 --- a/static/js/pichat.js +++ b/static/js/pichat.js @@ -1,8 +1,11 @@ var cache = {} -var pendingMessages = {} +var PendingMessages = {} var MaxImagePosts = 40 +// Utils + + function escapeHtml(txt) { if (!txt) { return ""; } else { return $("").text(txt).html(); } @@ -30,6 +33,8 @@ function linkReplace(url){ } } +// Message Handling + var ImageMsgCount = 0 function removeOldMessages(){ // don't count posts that are all text @@ -73,6 +78,8 @@ function buildUserDiv(user) { } } +// Growl + function buildGrowlDataAndPopDatShit(msg) { var nick = escapeHtml(msg.nick); nick = '' + nick + ':' @@ -95,11 +102,13 @@ function handleMsgError(resp) { } } +// Messages + function submitMessage() { var content = $.trim($('#msgInput').val()); $('#msgInput').val(''); if (content == '') { return; } - pendingMessages[content] = true; + PendingMessages[content] = true; var msg = { 'nick': Nick, 'content': content }; var div = addNewMessage(msg, true); @@ -173,14 +182,34 @@ function updateUI(msgs, users) { } function isDuplicateMessage(m) { - if (m.nick == Nick && m.content in pendingMessages) { - delete pendingMessages[m.content]; + if (m.nick == Nick && m.content in PendingMessages) { + delete PendingMessages[m.content]; return true; } else { return false; } } +var CurrentTopic = null; + +function isSameTopic(curTopic, newTopic) { + if (!!curTopic != !!newTopic) { return false; } + else if (!curTopic) { return false; } // => !newTopic also + else { + return curTopic.topic == newTopic.topic && + curTopic.deadline == newTopic.deadline && + curTopic.maker == newTopic.maker; + } +} + +function updateTopic(newTopic) { + if (isSameTopic(CurrentTopic, newTopic)) { return; } + alert('new topic'); + CurrentTopic = newTopic; + $('#topic').text(topic.topic); + +} + function refresh() { var onSuccess = function(json) { try { @@ -192,6 +221,9 @@ function refresh() { if (typeof UnseenMsgCounter !== 'undefined' && !HasFocus) { UnseenMsgCounter += messages.length; } + if (json.topic) { + updateTopic(json.topic); + } } catch(e) { if (IsAdmin && window.console) { console.error(e); -- cgit v1.2.3-70-g09d2