summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsrc/site.clj36
-rwxr-xr-xstatic/js/pichat.js40
-rwxr-xr-xtemplate/banner.st4
3 files changed, 72 insertions, 8 deletions
diff --git a/src/site.clj b/src/site.clj
index cd2b82f..28dadcb 100755
--- a/src/site.clj
+++ b/src/site.clj
@@ -148,10 +148,11 @@
(map process-user (sort-by #(% :nick)
(vals @(room :users)))))
-(defn updates [room since]
+(defn updates [room since]
{"users" (prepare-user-list room)
"messages" (map process-message-for-json
- (new-messages room since))})
+ (new-messages room since))
+ "topic" @(room :topic)})
(def *dumps-per-page* 20)
@@ -200,7 +201,9 @@
:name (room-db :name)
:description (room-db :description)
:users (ref {})
- :messages (ref (fetch-messages-by-room (room-db :room_id) false))})
+ :messages (ref (fetch-messages-by-room (room-db :room_id) false))
+ :topic (ref nil)
+ })
;; Templates
@@ -357,6 +360,32 @@
:else (do (update-user-db user-id attr val)
(resp-success "OK")))))
+;; Topics
+
+(defn valid-topic? [topic]
+ topic)
+
+(defn valid-deadline? [deadline]
+ deadline)
+
+(defn set-topic! [room topic deadline maker]
+ (ref-set (room :topic)
+ {:topic topic
+ :deadline deadline
+ :maker maker}))
+
+(defn validate-set-topic [session params]
+ (let [room (@rooms (params :room))
+ topic (params :topic)
+ deadline (params :deadline)]
+ (cond (not (session :is_admin)) (resp-error "NOT_VIP")
+ (not (valid-topic? topic)) (resp-error "INVALID_TOPIC")
+ (not (valid-deadline? deadline)) (resp-error "INVALID_DEADLINE")
+ (not room) (resp-error "INVALID_ROOM")
+ :else (do
+ (dosync (set-topic! room topic deadline (session :nick)))
+ (resp-success "OK")))))
+
;; Chat
(defn validate-room-access [room-key session]
@@ -620,6 +649,7 @@
(POST "/msg" (validated-msg session params))
(POST "/submit-registration" (register session params))
(POST "/update-profile" (update-profile session params))
+ (POST "/set-topic" (validate-set-topic session params))
(GET "/about_us" (serve-template "about_us" session))
(GET "/goodies" (serve-template "goodies" session))
(GET "/help" (serve-template "help" session))
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 $("<span>").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 = '<a href="/u/' + nick + ' " style="color:pink">' + nick + '</a>:'
@@ -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);
diff --git a/template/banner.st b/template/banner.st
index 557a0e0..dd7a7b3 100755
--- a/template/banner.st
+++ b/template/banner.st
@@ -28,7 +28,9 @@
</div>
</div>
-
+
+ <div id="topic"></div>
+
$if(isadmin)$
<div id="vippp">
<a href="/VIP/chat"> &#x2605; VIP &#x2605; </a>