From 92b092823c21af1339e0d42716dc856357f93e85 Mon Sep 17 00:00:00 2001 From: Scott Ostler Date: Tue, 4 Jan 2011 15:42:23 -0500 Subject: Added topics, refactored recipient handling --- template/topic.st | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 template/topic.st (limited to 'template/topic.st') diff --git a/template/topic.st b/template/topic.st new file mode 100644 index 0000000..71451b2 --- /dev/null +++ b/template/topic.st @@ -0,0 +1,39 @@ + + + #$topic$ - dump.fm + $head()$ + + + + $banner()$ +
+
+
+

#$topic$

+

+
+
+ $if(dumps)$ + + $dumps: { d | $log_dump(dump=d)$ }$ + + $else$ + Topic #$topic$ doesn't exist yet! + $endif$ +
+
+
+ $footer()$ +
+
+ + + + + + -- cgit v1.2.3-70-g09d2 From 457125462cd658b6660289a292c367a0d560a792 Mon Sep 17 00:00:00 2001 From: Scott Ostler Date: Tue, 4 Jan 2011 16:17:46 -0500 Subject: Second revision of topics --- src/datalayer.clj | 24 +++++++++++++----------- src/site.clj | 14 +++++++------- static/js/pichat.js | 1 - template/topic.st | 51 ++++++++++++++++++++++++++++++--------------------- 4 files changed, 50 insertions(+), 40 deletions(-) (limited to 'template/topic.st') 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 diff --git a/static/js/pichat.js b/static/js/pichat.js index 72f7d0d..cc51613 100644 --- a/static/js/pichat.js +++ b/static/js/pichat.js @@ -168,7 +168,6 @@ function recipientReplace(atText, recips) { } function linkify(text, recips) { - console.log(recips) LastMsgContainsImage = false; var recipWrapper = function(text) { return recipientReplace(text, recips); }; return text diff --git a/template/topic.st b/template/topic.st index 71451b2..1594364 100644 --- a/template/topic.st +++ b/template/topic.st @@ -3,37 +3,46 @@ #$topic$ - dump.fm $head()$ - + $banner()$ -
-
-
-

#$topic$

-

-
-
+
+
+
+

#$topic$

+

+
+
$if(dumps)$ - $dumps: { d | $log_dump(dump=d)$ }$ + $dumps: { d | $topic_dump(dump=d)$ }$ $else$ Topic #$topic$ doesn't exist yet! $endif$ -
-
-
- $footer()$ -
-
-
-
-
- + +
+
+ $if(prev)$ + + $else$ + + $endif$ + + $if(next)$ + + $else$ + + $endif$ +
+
+ $footer()$ +
+
+ -- cgit v1.2.3-70-g09d2