From fd2766f7112856df57c68f9d32a2c92b108fdcb8 Mon Sep 17 00:00:00 2001 From: sostler Date: Sun, 25 Apr 2010 11:46:37 -0400 Subject: Added version numbers to chat api --- src/site.clj | 15 +++++++++- static/js/pichat.js | 4 +++ template/browser.st | 80 +++++++++++++++++++++++++++-------------------------- template/chat.st | 1 + 4 files changed, 60 insertions(+), 40 deletions(-) diff --git a/src/site.clj b/src/site.clj index ec58e46..cc30d61 100644 --- a/src/site.clj +++ b/src/site.clj @@ -542,6 +542,18 @@ ;; Chat +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Chat format version history +; +; v0: Keys: users, messages, timestamp +; Date: Mists of dump antiquity +; +; v1: Keys: users, messages, timestamp, v +; Date: 2010/04/25 +; Note: Incorporates explicit version + +(def *chat-version-number* 1) + (defn validate-room-access [room-key session] (let [room (lookup-room room-key)] (and room @@ -566,6 +578,7 @@ (.setAttribute st "isadminroom" (room :admin_only)) (.setAttribute st "json_room_key" (json-str (room :key))) (.setAttribute st "json_user_nick" (if nick (json-str nick) "null")) + (.setAttribute st "version" *chat-version-number*) (.setAttribute st "roomname" (room :name)) (.setAttribute st "timestamp" now) (.toString st))) @@ -587,7 +600,7 @@ (commute users assoc nick (merge user-info {:last-seen now :avatar (session :avatar)})) (commute (room :users) assoc nick (user-struct-from-session session)))) - (resp-success (assoc (updates room since) :timestamp now))))) + (resp-success (assoc (updates room since) :timestamp now :v *chat-version-number*))))) (defn validated-refresh [session params] (let [room-key (params :room) diff --git a/static/js/pichat.js b/static/js/pichat.js index 6279e48..db49bb1 100644 --- a/static/js/pichat.js +++ b/static/js/pichat.js @@ -352,6 +352,10 @@ function updateTopic(newTopic) { function refresh() { var onSuccess = function(json) { try { + if (Version != json.v) { + location.reload(); + } + Timestamp = json.timestamp; $.map(json.messages, function(msg){ MessageContentCache[msg.msg_id.toString()] = msg.content }) diff --git a/template/browser.st b/template/browser.st index 8cb6403..4ebcd1b 100644 --- a/template/browser.st +++ b/template/browser.st @@ -3,38 +3,40 @@ dump.fm | Image Search Beta $head()$ - - - - + + - + $banner()$ @@ -46,26 +48,26 @@
- -
-
- -
- +
+
+
+
-
- + + + - - -
-

- $footer()$

-

-

-
- + + + +
+

+ $footer()$

+

+

+
+ diff --git a/template/chat.st b/template/chat.st index 239f5b9..8c290b7 100644 --- a/template/chat.st +++ b/template/chat.st @@ -18,6 +18,7 @@ $endif$ var Nick = $json_user_nick$; var Room = $json_room_key$; var Timestamp = $timestamp$; + var Version = $version$; $if(isadmin)$ var IsAdmin = true; $else$ -- cgit v1.2.3-70-g09d2