diff options
| -rw-r--r-- | src/datalayer.clj | 24 | ||||
| -rw-r--r-- | src/site.clj | 14 | ||||
| -rw-r--r-- | static/js/pichat.js | 1 | ||||
| -rw-r--r-- | template/topic.st | 51 |
4 files changed, 50 insertions, 40 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 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 @@ <title>#$topic$ - dump.fm</title> $head()$ <script> - var Recips = $recips$; jQuery(function() { - initLog(Recips) + initLog($recips$); }); </script> </head> - <body> + <body> $banner()$ - <div id="content"> - <div id="messagePanep"> - <div id="userListp"> - <h2><a href="/t/$topic$">#$topic$</a></h2> - <br><h3></h3> - </div> - <div id="messageList"> + <div id="content"> + <div id="messagePanep"> + <div id="userListp"> + <h2><a href="/t/$topic$">#$topic$</a></h2> + <br><h3></h3> + </div> + <div id="messageList"> $if(dumps)$ <span class="content"> - $dumps: { d | $log_dump(dump=d)$ }$ + $dumps: { d | $topic_dump(dump=d)$ }$ </span> $else$ <span>Topic #$topic$ doesn't exist yet!</span> $endif$ - </div> - </div> - <div id="footerc"> - $footer()$ - </div> - </div> -</div> -</div> -</div> - + </div> + <div id="msgInputDiv"> + <div id="msginputrapper"> + $if(prev)$ + <a href="/$nick$/whofaved/$prev$"><input id="prevbutton" value="<- Prev" readonly="true"></a> + $else$ + <input id="prevbutton" readonly="true"> + $endif$ + + $if(next)$ + <a href="/$nick$/whofaved/$next$"> <input id="nextbutton" value="Next ->" readonly="true"></a> + $else$ + <input id="nextbutton" value="nomodumps" readonly="true"> + $endif$ + </div> + <div id="footerc"> + $footer()$ + </div> + </div> + </div> </body> </html> |
