summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/datalayer.clj24
-rw-r--r--src/site.clj14
2 files changed, 20 insertions, 18 deletions
diff --git a/src/datalayer.clj b/src/datalayer.clj
index ecdc6dc..8590a7d 100644
--- a/src/datalayer.clj
+++ b/src/datalayer.clj
@@ -181,9 +181,10 @@ WHERE u.nick = ANY(?)"
[msg-id author-id (:user_id r)]))
[msg-id ts]))))
-(defn insert-recips-into-redis! [recips author-id dt content]
+(defn insert-recips-into-redis! [recips author-id dt content room-key]
(let [msg-json (json-str {"author_id" author-id
"recips" (map :nick recips)
+ "key" room-key
"content" content})
ts (.getTime dt)]
(redis/with-server redis-server
@@ -196,12 +197,13 @@ WHERE u.nick = ANY(?)"
(defn topic-key [topic]
(str "topic:" topic))
-(defn insert-topics-into-redis! [topics recips author-nick author-avatar dt msg-id content]
+(defn insert-topics-into-redis! [topics recips author-nick author-avatar dt msg-id content room-key]
(let [ts (.getTime dt)
msg-json (json-str {"nick" author-nick
"avatar" author-avatar
- "recips" (map :recips recips)
+ "recips" (map :nick recips)
"content" content
+ "key" room-key
"message_id" msg-id
"ts" ts})]
(redis/with-server redis-server
@@ -210,29 +212,29 @@ WHERE u.nick = ANY(?)"
(redis/lpush (topic-key t)
msg-json))))))
-(defn insert-message! [author-id author-nick author-avatar room-id content]
+(defn insert-message! [author-id author-nick author-avatar room content]
(let [msg-type (classify-msg content)
is-image (boolean (#{:image :mixed} msg-type))
is-text (boolean (#{:mixed :text} msg-type))
recips (get-recips content)
topics (get-topics content)
[msg-id dt] (insert-message-into-postgres! author-id
- room-id
+ (:room_id room)
content
is-image
is-text
recips)]
- (if-not (empty? recips)
- (insert-recips-into-redis! recips author-id dt content))
- (if-not (empty? topics)
- (insert-topics-into-redis! topics recips author-nick author-avatar dt msg-id content))
+ (when-not (:admin_only room)
+ (if-not (empty? recips)
+ (insert-recips-into-redis! recips author-id dt content (:key room)))
+ (if-not (empty? topics)
+ (insert-topics-into-redis! topics recips author-nick author-avatar dt msg-id content (:key room))))
{:author author-nick
:msg-id msg-id
- :room room-id
+ :room (:room_id room)
:db-ts dt
:content content
:recips (map :nick recips)
- :topics topics
}))
(defn fetch-direct-messages [user-id]
diff --git a/src/site.clj b/src/site.clj
index 6ebfb73..df5d9f7 100644
--- a/src/site.clj
+++ b/src/site.clj
@@ -71,9 +71,9 @@
(assoc d :created_on (.getTime (d :created_on))))
(defn message-room-link [m]
- (if (= (:key m) "dumpfm")
- "http://dump.fm/chat"
- (format "http://%s.dump.fm" (:key m))))
+ (if (default-room? (:key m *default-room*))
+ "http://dump.fm/"
+ (format "http://%s.dump.fm/" (:key m))))
(defn process-message-for-output [d]
(escape-html-deep
@@ -317,7 +317,7 @@ WHERE user_id IN
dumps))))))
(defn pull-recips [dumps]
- (set (apply concat (map #(get % "recips") dumps))))
+ (set (apply concat (map #(get % "recips" []) dumps))))
(defn profile
([session profile-nick] (profile session profile-nick "profile"))
@@ -642,7 +642,7 @@ WHERE user_id IN
mute (resp-error (format-mute mute))
:else
(let [content (validated-content content session)
- msg-info (insert-message! user-id nick (:avatar session) (:room_id room) content)
+ msg-info (insert-message! user-id nick (:avatar session) room content)
msg-id (:msg-id msg-info)]
(dosync
(let [msg-struct (build-msg nick content msg-id (:recips msg-info))]
@@ -686,7 +686,7 @@ WHERE user_id IN
process-message-for-output
(fetch-topic (:user_id session) topic))
recips (pull-recips msgs)
- st (fetch-template "topic" session)]
+ st (fetch-template "topic" session)]
(.setAttribute st "recips" (json-str recips))
(.setAttribute st "topic" topic)
(if-not (empty? msgs)
@@ -1092,7 +1092,7 @@ WHERE user_id IN
msg-info (insert-message! (:user_id session)
(:nick session)
(:avatar session)
- (:room_id room)
+ room
url)]
(copy (:tempfile image) dest)
(dosync