diff options
| author | sostler <sbostler@gmail.com> | 2010-05-27 19:01:01 -0400 |
|---|---|---|
| committer | sostler <sbostler@gmail.com> | 2010-05-27 19:01:01 -0400 |
| commit | 1f52229775ac654aaf4e1807b38a4bc1527a1434 (patch) | |
| tree | 7e2d90a3fe6b654bad01c81066bb3a948794b4cf | |
| parent | a0506593725a81065f13b94c7a94ba4e73660479 (diff) | |
Fixed disappearing messages bug
| -rw-r--r-- | src/site.clj | 15 | ||||
| -rw-r--r-- | static/tests/bugchat.html | 2 | ||||
| -rw-r--r-- | static/tests/bugchat.js | 8 |
3 files changed, 14 insertions, 11 deletions
diff --git a/src/site.clj b/src/site.clj index 18fe495..2197dd5 100644 --- a/src/site.clj +++ b/src/site.clj @@ -584,24 +584,25 @@ FROM users u ((first (do-select [qry user-id room-id content is-image])) :message_id)))) +(defn build-msg [nick content msg-id] + (struct message-struct nick content (new Date) msg-id)) + (defn msg [session params] (let [user-id (session :user_id) mute ((poll *active-mutes*) user-id) nick (session :nick) room-key (params :room) room (lookup-room room-key) - content (.trim (params :content)) - now (new Date)] + content (.trim (params :content))] (cond (not room) (resp-error "BAD_ROOM") (not nick) (resp-error "NOT_LOGGED_IN") mute (resp-error (format-mute mute)) :else - (let [msg-id (msg-db user-id (room :room_id) content) - msg (struct message-struct nick content now msg-id)] + (let [msg-id (msg-db user-id (room :room_id) content)] (dosync - (if (not (contains? (ensure (room :users)) nick)) - (login-user (user-struct-from-session session) room)) - (add-message msg room)) + (if (not (contains? (ensure (room :users)) nick)) + (login-user (user-struct-from-session session) room)) + (add-message (build-msg nick content msg-id) room)) (resp-success msg-id))))) (defn validated-msg [session params] diff --git a/static/tests/bugchat.html b/static/tests/bugchat.html index 548eb6d..bcfacc4 100644 --- a/static/tests/bugchat.html +++ b/static/tests/bugchat.html @@ -2,7 +2,7 @@ <head> <title>BUG CHAT</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> - <script type="text/javascript" src="/static/test/bugchat.js"></script> + <script type="text/javascript" src="/static/tests/bugchat.js"></script> <script> $(initClient); </script> diff --git a/static/tests/bugchat.js b/static/tests/bugchat.js index 5d9a7b5..eba3177 100644 --- a/static/tests/bugchat.js +++ b/static/tests/bugchat.js @@ -56,7 +56,7 @@ function showError(err) { }; -function handleMessages(msgs) { +function handleMessages(msgs, oldTime, newTime) { $.map(msgs, function(m) { var split = m.content.split("-"); if (split.length != 2) { @@ -71,7 +71,9 @@ function handleMessages(msgs) { var p = ClientMap[client]; if (i - p != 1) { showError("[" + Key + "] Error for client " + client - + "! Expected " + (p+1) + ", got " + i); + + "! Expected " + (p+1) + ", got " + i + + " (" + oldTime + " -> " + newTime + ")" + ); } } ClientMap[client] = i; @@ -81,8 +83,8 @@ function handleMessages(msgs) { function refresh() { var onSuccess = function(json) { try { + handleMessages(json.messages, Timestamp, json.timestamp); Timestamp = json.timestamp; - handleMessages(json.messages); } catch(e) { console.error(e); $('#msgs').append($('<div>').css('color', 'red').text(e)); |
