summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/site.clj61
-rwxr-xr-xsrc/utils.clj8
-rw-r--r--static/js/pichat.js46
-rw-r--r--template/directory.st24
-rw-r--r--template/log.st14
5 files changed, 84 insertions, 69 deletions
diff --git a/src/site.clj b/src/site.clj
index 297f4a5..cebf62e 100644
--- a/src/site.clj
+++ b/src/site.clj
@@ -592,38 +592,55 @@ order by count desc limit ? offset ?")
"score_ent" (score-to-entity score)
"score" score)))
-(def recent-posts-query "
-SELECT u.user_id, u.nick, u.avatar,
- m.content, m.message_id
-FROM users u, messages m
-WHERE u.user_id = ANY(?)
- AND m.message_id =
+(defn recent-posts-query [user-id]
+ (format "
+SELECT u.user_id, u.nick, u.avatar,
+ m.content, m.message_id%s
+FROM users u
+LEFT JOIN messages m on m.message_id =
(SELECT message_id FROM messages
WHERE user_id = u.user_id
AND is_image
AND room_id IN (SELECT room_id from rooms where admin_only = false)
- ORDER BY created_on desc LIMIT 1);
-")
+ ORDER BY created_on desc LIMIT 1)
+WHERE u.user_id = ANY(?)"
+ (if user-id
+ (format
+ ",
+ EXISTS (SELECT 1 FROM tags
+ WHERE tag = 'favorite' AND user_id = %s AND message_id = m.message_id) AS favorited"
+ user-id)
+ ", false AS favorited")))
+
+(defn lookup-recent-posts [user-tag-id user-ids]
+ (do-select [(recent-posts-query user-tag-id)
+ (sql-array "int" user-ids)]))
+
+(defn lookup-recent-posts-tagless [user-tag-id user-ids]
+ (do-select [(recent-posts-query nil)
+ (sql-array "int" user-ids)]))
-(defn add-recent-posts [users]
+(def directory-cache-ttl (minutes 10))
+(def memoized-lookup-recent-posts-tagless
+ (ttl-memoize lookup-recent-posts-tagless directory-cache-ttl))
+
+
+(defn add-recent-posts [user-id users]
(if-not (empty? users)
- (let [ids (map :user_id users)
- res (do-select [recent-posts-query (sql-array "int" ids)])]
+ (let [f (if user-id lookup-recent-posts lookup-recent-posts-tagless)
+ res (f user-id (map :user_id users))]
(for [u users]
(merge u (find-first #(= (:user_id u) (:user_id %)) res))))))
-(defn get-directory-info [offset]
+(defn get-directory-info [user-id offset]
(map process-directory-entry
- (add-recent-posts
+ (add-recent-posts user-id
(get-user-ranking offset *per-directory-page*))))
-
-(def directory-cache-ttl (minutes 10))
-(def memoized-get-directory-info
- (ttl-memoize get-directory-info directory-cache-ttl))
(defn directory [session offset]
(let [st (fetch-template "directory" session)
- users (memoized-get-directory-info offset)]
+ users (get-directory-info (:user_id session) offset)]
+ (prn users)
(.setAttribute st "users" users)
(cond (= offset 0) (.setAttribute st "prev" false)
(= offset 1) (.setAttribute st "prev" "")
@@ -1360,6 +1377,8 @@ WHERE u.user_id = ANY(?)
(start-user-flusher!)
(start-session-pruner!)
(start! hall-results)
-(if (= *server-url* "http://dump.fm")
- (do (start! feed-downloader)
- (start! feed-inserter)))
+
+; Scott 2010/8/30: disable feeds to test impact on server load
+;(if (= *server-url* "http://dump.fm")
+; (do (start! feed-downloader)
+; (start! feed-inserter)))
diff --git a/src/utils.clj b/src/utils.clj
index 7f56f61..dd5530a 100755
--- a/src/utils.clj
+++ b/src/utils.clj
@@ -58,10 +58,10 @@
(declare stringify-and-escape)
(defn escape-html-deep [o]
(if (map? o)
- (stringify-and-escape o)
- (if (seq? o)
- (map escape-html-deep o)
- (escape-html o))))
+ (stringify-and-escape o)
+ (cond (seq? o) (map escape-html-deep o)
+ (or (true? o) (false? o)) o
+ :else (escape-html o))))
(defn stringify-and-escape [m]
(zipmap (map str* (keys m)) (map escape-html-deep (vals m))))
diff --git a/static/js/pichat.js b/static/js/pichat.js
index 9287cc1..13e0036 100644
--- a/static/js/pichat.js
+++ b/static/js/pichat.js
@@ -501,7 +501,7 @@ function initChat() {
messageList = $("#messageList")[0]
- initChatThumb()
+ initChatThumb();
scrollToEnd()
scrollWatcher()
@@ -583,14 +583,13 @@ function initLog() {
var t = $(this);
t.html(buildMsgContent(t.text()));
});
- initLogThumb();
+ initLogThumb(".logged-dump .thumb", '.dump');
}
-// jesus this logic is ugly
-function initLogThumb(){
- $(".logged-dump .thumb").bind('mouseover mouseout',
+function initLogThumb(selector, parentSelector) {
+ $(selector).bind('mouseover mouseout',
function(e) {
- var favorited = $(this).parents(".dump").hasClass("favorite") ? true : false;
+ var favorited = $(this).parents(parentSelector).hasClass("favorite") ? true : false;
if (e.type == "mouseover") {
if (favorited) {
$(this).attr("src", Imgs.logThumbOff);
@@ -602,17 +601,16 @@ function initLogThumb(){
if (favorited) {
$(this).attr("src", Imgs.logThumb);
$(this).stop().animate(Anim.logThumb, 'fast');
- } else {
+ } else {
$(this).attr("src", Imgs.logThumbOff);
$(this).stop().animate(Anim.logThumb, 'fast');
}
}
})
-}
+ }
-function initChatThumb(){
-
- $(".chat-thumb").live('mouseover mouseout',
+function initChatThumb() {
+ $(".chat-thumb").live('mouseover mouseout',
function(e) {
var favorited = $(this).parents(".dump").hasClass("favorite") ? true : false;
if (e.type == "mouseover") {
@@ -625,18 +623,27 @@ function initChatThumb(){
} else { // mouseout
if (favorited) {
$(this).attr("src", Imgs.chatThumb);
+ var favorited = $(this).parents(".dump").hasClass("favorite") ? true : false;
+ if (e.type == "mouseover") {
+ if (favorited) {
+ $(this).attr("src", Imgs.chatThumbOff);
+ } else {
+ $(this).attr("src", Imgs.chatThumbBig);
+ $(this).stop().animate(Anim.chatThumbBig, 'fast')
+ }
+ } else { // mouseout
+ if (favorited) {
+ $(this).attr("src", Imgs.chatThumb);
$(this).stop().animate(Anim.chatThumb, 'fast');
- } else {
- $(this).stop().animate(Anim.chatThumbTiny, 'fast', 'swing',
+ } else {
+ $(this).stop().animate(Anim.chatThumbTiny, 'fast', 'swing',
function(){
$(this).attr("src", Imgs.chatThumbDot)
- $(this).animate(Anim.chatThumb, 0)
+ $(this).animate(Anim.chatThumb, 0)
})
+ }}
}
- }
- })
-}
-
+ }})}
function paletteToChat(img){
var chatText = $("#msgInput").val()
@@ -986,7 +993,8 @@ function initDirectory() {
var t = $(this);
t.html(buildMsgContent(t.text()));
});
- Search.init()
+ Search.init()
+ initLogThumb('.dlogged-dump .thumb', '.dlogged-dump');
}
//big hand stuff
diff --git a/template/directory.st b/template/directory.st
index 0611697..e3b3df0 100644
--- a/template/directory.st
+++ b/template/directory.st
@@ -9,33 +9,25 @@
<script>
jQuery(document).ready(initDirectory);
</script>
-
-
</head>
<body class="profile">
$banner()$
<div id="chatrap">
<div id="log">
<br>
- <div id="dprofile">
- <h2> Directory </h2><br><h3>Ordered by fav count<br>
-
-
-
- </h3>
-
-
- </div>
+ <div id="dprofile">
+ <h2> Directory </h2><br>
+ <h3>Ordered by fav count</h3><br>
+ </div>
<div id="dposts">
<br>
$if(users)$
- $users:{ dump |
- <div class="dlogged-dump" id="message-$dump.message_id$" style="position: relative">
+ $users:{ dump |
+ <div class="dlogged-dump dump $if(dump.favorited)$favorite$endif$" id="message-$dump.message_id$" style="position: relative">
<div id="usernicks"> <a href="/$dump.nick$"> <b>$dump.nick$'s</b>
$if(dump.score_ent)$
-
- fav score: $dump.score$
+ fav score: $dump.score$
<h9>$dump.score_ent$</h9>
</a></div>
$endif$
@@ -53,7 +45,7 @@
<div id="infotxt"><b>last post</b></div>
<span class="linkify">$dump.content$</span>
<hr />
- $share_buttons()$
+ $share_buttons(dump=dump)$
</div>
}$
$else$
diff --git a/template/log.st b/template/log.st
index 5a36611..92a0f75 100644
--- a/template/log.st
+++ b/template/log.st
@@ -9,15 +9,11 @@
<body>
$banner()$
<div id="content">
-
-
- <div id="messagePanep">
-
- <div id="userListp">
- <h2> $roomkey$ log </h2><br><h3></h3>
- </div>
-
-<div id="messageList">
+ <div id="messagePanep">
+ <div id="userListp">
+ <h2> $roomkey$ log </h2><br><h3></h3>
+ </div>
+ <div id="messageList">
$if(dumps)$
<span class="content">