summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Ostler <scottbot9000@gmail.com>2010-06-23 15:57:14 -0400
committerScott Ostler <scottbot9000@gmail.com>2010-06-23 15:57:14 -0400
commit15f5a8ed8e981486697790fe9613b1c26dceda42 (patch)
tree172b66b346bb4d8d90ec255125a02576b182280d
parentc4041b4766f8afa0c462fbea2963b61bc43f0e08 (diff)
Added faving to hall of fame
-rw-r--r--src/fame.clj2
-rw-r--r--src/site.clj7
-rw-r--r--src/tags.clj20
-rw-r--r--template/fame.st2
-rw-r--r--template/fame_dump.st14
5 files changed, 38 insertions, 7 deletions
diff --git a/src/fame.clj b/src/fame.clj
index 8f0ae4f..cd28e05 100644
--- a/src/fame.clj
+++ b/src/fame.clj
@@ -3,7 +3,7 @@
utils))
; should probably cache this to disk somewhere
-(def hall-of-fame-update-frequency (* 4 60 60))
+(def hall-of-fame-update-frequency (* 3 60 60))
(def hall-of-fame-query "
select m.created_on, m.message_id, m.content, u.nick, u.avatar, r.key, count(*)
diff --git a/src/site.clj b/src/site.clj
index 6a011c6..0967431 100644
--- a/src/site.clj
+++ b/src/site.clj
@@ -1047,8 +1047,11 @@ FROM users u
(unknown-page)))
(defn hall-of-fame [session]
- (let [st (fetch-template "fame" session)]
- (.setAttribute st "dumps" (map process-message-for-output (poll hall-results)))
+ (let [st (fetch-template "fame" session)
+ msgs (add-user-favs-to-msgs (poll hall-results)
+ (session :user_id))]
+ (println "hall msgs:" msgs)
+ (.setAttribute st "dumps" (map process-message-for-output msgs))
(.toString st)))
;; Compojure Routes
diff --git a/src/tags.clj b/src/tags.clj
index 4d1dda0..de0b476 100644
--- a/src/tags.clj
+++ b/src/tags.clj
@@ -63,6 +63,26 @@
(assoc row :favorited true)
row))
+(def user-fav-query "
+SELECT v
+FROM UNNEST(?) as v
+WHERE EXISTS
+ (SELECT 1 FROM tags
+ WHERE user_id = ?
+ AND message_id = v
+ AND tag = 'favorite')
+")
+
+(defn add-user-favs-to-msgs [msgs user-id]
+ (let [faved-ids (set
+ (map :v
+ (do-select [user-fav-query
+ (sql-array "int" (map :message_id msgs))
+ user-id])))]
+ (for [m msgs]
+ (if (contains? faved-ids (:message_id m))
+ (assoc m :favorited true)
+ m))))
(defn explain-query [query] (str "EXPLAIN ANALYZE " query))
diff --git a/template/fame.st b/template/fame.st
index 9742362..0fa5b03 100644
--- a/template/fame.st
+++ b/template/fame.st
@@ -16,7 +16,7 @@
<div id="messagePanep">
<div id="userListp">
- <h2>Hall Of Fame </h2><br><h3></h3>
+ <h2>Hall Of Fame </h2><br><h3>Updated every few hours</h3>
</div>
<div id="messageList">
diff --git a/template/fame_dump.st b/template/fame_dump.st
index c0fb2a2..8ebce02 100644
--- a/template/fame_dump.st
+++ b/template/fame_dump.st
@@ -1,4 +1,8 @@
-<div class="logged-dump dump" id="message-$dump.message_id$" nick="$dump.nick$">
+$if(dump.ztags)$
+ <div class="logged-dump dump" id="message-$dump.message_id$" nick="$dump.nick$" tags="$dump.tags: { tag | $tag.nick$:$tag.tag$ }$">
+$else$
+ <div class="logged-dump dump $if(dump.favorited)$favorite$endif$" id="message-$dump.message_id$" nick="$dump.nick$">
+$endif$
$dump.created_on$ -- by <a href="/$dump.nick$"><b>$dump.nick$</b>
<div id="logavatar">
@@ -7,8 +11,12 @@ $if(dump.avatar)$
$else$
<img height="50" width="50" src="/static/noinfo.png">
$endif$
-
- </div></a> &nbsp;&nbsp;&nbsp;<img height="16px" width="16px" src="http://dump.fm/static/img/thumbs/heartfaved.gif">$dump.count$
+ </div></a>&nbsp;&nbsp;&nbsp;<img height="16px" width="16px" src="http://dump.fm/static/img/thumbs/heartfaved.gif">$dump.count$
+$if(dump.favorited)$
+ <img src="/static/img/thumbs/heartfaved.gif" class="thumb favorite" onclick="Tag.favorite(this)">
+$else$
+ <img src="/static/img/thumbs/heart.gif" class="thumb" onclick="Tag.favorite(this)">
+$endif$
<div class="content">$dump.content$</div>
<hr />
$share_buttons()$