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 --- static/js/pichat.js | 58 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 18 deletions(-) (limited to 'static/js/pichat.js') diff --git a/static/js/pichat.js b/static/js/pichat.js index a33209b..72f7d0d 100644 --- a/static/js/pichat.js +++ b/static/js/pichat.js @@ -120,6 +120,7 @@ Log.initialize(); URLRegex = /((\b(http\:\/\/|https\:\/\/|ftp\:\/\/)|(www\.))+(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi; PicRegex = /\.(jpg|jpeg|png|gif|bmp|svg|fid)$/i; RecipRegex = /(^|\s)@\w+/g; +TopicRegex = /(^|\s)#\w+/g; function getImagesAsArray(text) { @@ -135,24 +136,45 @@ function getImagesAsArray(text) { return imgs } -function linkify(text, recips) { - LastMsgContainsImage = false; - var recipWrapper = function(text) { return recipientReplace(text, recips); }; - return text.replace(URLRegex, linkReplace).replace(RecipRegex, recipWrapper); +function topicReplace(text) { + text = $.trim(text).toLowerCase(); + var topicLabel = text.substring(1); + return ' ' + text + ' '; } function recipientReplace(atText, recips) { + recips = recips || []; + + var space = ''; if (atText[0] == ' ') { atText = atText.slice(1); - var space = ' '; - } else { - var space = ''; + space = ' '; } - var nick = atText.slice(1); - if (!recips || recips.indexOf(nick.toLowerCase()) == -1) { + + var nick = atText.slice(1).toLowerCase(); + var matchedRecip; + for (var i = 0; i < recips.length; i++) { + if (recips[i].toLowerCase() == nick) { + matchedRecip = recips[i]; + break; + } + } + + if (matchedRecip) { + return space + '@' + matchedRecip + ''; + } else { return space + atText; - } else - return space + '' + atText + ''; + } +} + +function linkify(text, recips) { + console.log(recips) + LastMsgContainsImage = false; + var recipWrapper = function(text) { return recipientReplace(text, recips); }; + return text + .replace(URLRegex, linkReplace) + .replace(RecipRegex, recipWrapper) + .replace(TopicRegex, topicReplace); } // use this in escapeHtml to turn everyone's text lIkE tHiS @@ -330,7 +352,7 @@ function setImgsEnable() { function buildMsgContent(content, recips) { if (content.substr(0,6) == "") - return content.substr(6,content.length - 13) + return content.substr(6,content.length - 13); else return linkify(escapeHtml(content), recips); } @@ -712,7 +734,7 @@ function enableProfileEdit() { activateProfileEditable(); } -function initProfile() { +function initProfile(recips) { Search.initInpage(); $(".linkify-text").each(function() { var text = jQuery(this).text(); @@ -720,7 +742,7 @@ function initProfile() { }); $(".linkify-full").each(function() { - $(this).html(buildMsgContent($(this).text(), Recips)); + $(this).html(buildMsgContent($(this).text(), recips)); }); $('#edit-toggle').click(enableProfileEdit); @@ -732,11 +754,11 @@ function initProfile() { }); }; -function initLog() { - Search.initInpage() +function initLog(recips) { + Search.initInpage(); $('.logged-dump .content').each(function() { var t = $(this); - t.html(buildMsgContent(t.text())); + t.html(buildMsgContent(t.text(), recips)); }); initLogThumb(".logged-dump .thumb", '.dump'); } @@ -797,7 +819,7 @@ function paletteToChat(img){ chatText += " " chatText += $(img).attr("src") + " " $("#msgInput").val(chatText) - $("#msgInput").focus().val($("#msgInput").val()) //http://stackoverflow.com/questions/1056359/ + $("#msgInput").focus().val($("#msgInput").val()) // http://stackoverflow.com/questions/1056359/ paletteHide() } -- 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 'static/js/pichat.js') 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 From f46044e56199750c9fbda3dec3edd1336ada98ad Mon Sep 17 00:00:00 2001 From: Scott Ostler Date: Tue, 4 Jan 2011 16:27:39 -0500 Subject: Fixed pichat.js urls --- static/js/pichat.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'static/js/pichat.js') diff --git a/static/js/pichat.js b/static/js/pichat.js index cc51613..7c7dd0a 100644 --- a/static/js/pichat.js +++ b/static/js/pichat.js @@ -139,7 +139,7 @@ function getImagesAsArray(text) { function topicReplace(text) { text = $.trim(text).toLowerCase(); var topicLabel = text.substring(1); - return ' ' + text + ' '; + return ' ' + text + ' '; } function recipientReplace(atText, recips) { @@ -161,7 +161,7 @@ function recipientReplace(atText, recips) { } if (matchedRecip) { - return space + '@' + matchedRecip + ''; + return space + '@' + matchedRecip + ''; } else { return space + atText; } @@ -384,7 +384,7 @@ function buildUserDiv(user) { + escapeHtml(user.nick) + ''; } else { return ''; } @@ -394,7 +394,7 @@ function buildUserDiv(user) { function buildFav(f) { var h = '
' - + '' + + '' + '' + f.from + '' + ' just faved you!' + '
'; -- cgit v1.2.3-70-g09d2 From 034acfa61c9f5667f11f43659c02eb9bae7e94f5 Mon Sep 17 00:00:00 2001 From: Scott Ostler Date: Tue, 4 Jan 2011 16:29:41 -0500 Subject: topic links open in new window --- static/js/pichat.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'static/js/pichat.js') diff --git a/static/js/pichat.js b/static/js/pichat.js index 7c7dd0a..884e01f 100644 --- a/static/js/pichat.js +++ b/static/js/pichat.js @@ -139,7 +139,7 @@ function getImagesAsArray(text) { function topicReplace(text) { text = $.trim(text).toLowerCase(); var topicLabel = text.substring(1); - return ' ' + text + ' '; + return ' ' + text + ' '; } function recipientReplace(atText, recips) { -- cgit v1.2.3-70-g09d2