diff options
| author | Scott Ostler <sostler@deathmachine.local> | 2010-01-19 23:25:29 -0500 |
|---|---|---|
| committer | Scott Ostler <sostler@deathmachine.local> | 2010-01-19 23:25:29 -0500 |
| commit | a91eb914edb95a5facd62b2eac00186b7b8c63c1 (patch) | |
| tree | 9e5a331303d148aec0c91287e44b210d442be072 /src | |
| parent | 7d447a321dedf2c767f8f0d0ac885d529dd387f9 (diff) | |
Getting ready for commit
Diffstat (limited to 'src')
| -rwxr-xr-x | src/site.clj | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/src/site.clj b/src/site.clj index 5868f94..b89215c 100755 --- a/src/site.clj +++ b/src/site.clj @@ -23,7 +23,7 @@ (.setRefreshInterval template-group 3) (defstruct user-struct :nick :user_id :avatar :last-seen) -(defstruct message-struct :nick :content :created_on) +(defstruct message-struct :nick :content :created_on :msg_id) (defn user-struct-from-session [session] (struct user-struct (session :nick) (session :user_id) (session :avatar) @@ -123,6 +123,7 @@ (defn process-message-for-output [d] {"nick" (encode-html-entities (d :nick)) + "msg_id" (d :message_id) "created_on" (.format formatter (d :created_on)) "content" (encode-html-entities (d :content))}) @@ -164,7 +165,7 @@ (defn fetch-messages-by-room ([room-id image-only] (fetch-messages-by-room room-id image-only 0)) ([room-id image-only offset] - (let [query (str "SELECT m.content, m.created_on, u.nick " + (let [query (str "SELECT m.content, m.message_id, m.created_on, u.nick " "FROM messages m, users u " "WHERE room_id = ? AND m.user_id = u.user_id " (if image-only "AND m.is_image = true " "") @@ -358,13 +359,13 @@ (re-find pic-regex (strip-params content))) true false)) -(defn msg-db [user-id room-id msg] - (let [content (.trim (msg :content)) - is-image (is-image? content)] +(defn msg-db [user-id room-id content] + (let [is-image (is-image? content) + qry (str "INSERT INTO messages (user_id, room_id, content, is_image) " + "VALUES (?, ?, ?, ?) RETURNING message_id")] (with-connection db - (insert-values :messages - [:user_id :room_id :content :is_image] - [user-id room-id content is-image])))) + ((first (do-select [qry user-id room-id content is-image])) + :message_id)))) (defn msg [session params] (let [user-id (session :user_id) @@ -372,18 +373,17 @@ room-key (params :room) room (@rooms room-key) content (.trim (params :content)) - now (new Date) - msg (struct message-struct nick content now)] + now (new Date)] (cond (not room) (resp-error "BAD_ROOM") (not nick) (resp-error "NOT_LOGGED_IN") :else - (do - (dosync - (if (not (contains? @(room :users) nick)) - (login-user (user-struct-from-session session) room)) - (add-message msg room)) - (msg-db user-id (room :room_id) msg) - (resp-success "OK"))))) + (let [msg-id (msg-db user-id (room :room_id) content) + msg (struct message-struct nick content now msg-id)] + (dosync + (if (not (contains? @(room :users) nick)) + (login-user (user-struct-from-session session) room)) + (add-message msg room)) + (resp-success msg-id))))) (defn validated-msg [session params] (let [room-key (params :room) |
