summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Ostler <scottbot9000@gmail.com>2010-07-02 12:46:11 -0400
committerScott Ostler <scottbot9000@gmail.com>2010-07-02 12:46:11 -0400
commit72f6b199b229f2247e72f2316d346cc3d7398896 (patch)
tree57625bf1d0ea41c152a30d8bfd7904119e5ccdb3
parent5b2139d5a747f37264160b43b4c776846b54cb74 (diff)
add favorited attribute to get-popular-dumps
-rw-r--r--src/site.clj31
1 files changed, 17 insertions, 14 deletions
diff --git a/src/site.clj b/src/site.clj
index 5a3b485..770c331 100644
--- a/src/site.clj
+++ b/src/site.clj
@@ -542,33 +542,36 @@ FROM users u
select u.nick, u.avatar, r.key, m.message_id, m.content, m.created_on, count(*) as count,
array_agg(u2.nick) as user_nicks,
array_agg(u2.avatar) as user_avs,
- array_agg(t.created_on) as favtime
+ array_agg(t.created_on) as favtime,
+ (select exists (select 1 from tags
+ where tag = 'favorite' and user_id = ? and message_id = m.message_id)) as favorited
from users u, messages m, rooms r, tags t, users u2
where lower(u.nick) = lower(?)
and u.user_id = m.user_id and m.message_id = t.message_id
and m.room_id = r.room_id and m.is_image = true and r.admin_only = false
-and lower(t.tag) = 'favorite' and t.user_id != u.user_id
+and t.tag = 'favorite' and t.user_id != u.user_id
and t.user_id = u2.user_id
group by u.nick, u.avatar, r.key, m.message_id, m.content, m.created_on
order by count desc limit 20 offset 0")
-(defn get-popular-dumps [nick]
- (for [d (do-select [popular-dumps-qry nick])]
- (assoc d
- :favers (sort-by :t (comp #(* -1 %) compare)
- (map (fn [n a t] (if (non-empty-string? a)
- {:nick n :avatar a :t t}
- {:nick n :t t}))
- (.getArray (:user_nicks d))
- (.getArray (:user_avs d))
- (.getArray (:favtime d))))
- :user_nicks nil :user_avs nil :favtime nil)))
+(defn get-popular-dumps [nick user-id]
+ (for [d (do-select [popular-dumps-qry user-id nick])]
+ (let [fav-nicks (.getArray (:user_nicks d))]
+ (assoc d
+ :favers (sort-by :t (comp #(* -1 %) compare)
+ (map (fn [n a t] (if (non-empty-string? a)
+ {:nick n :avatar a :t t}
+ {:nick n :t t}))
+ fav-nicks
+ (.getArray (:user_avs d))
+ (.getArray (:favtime d))))
+ :user_nicks nil :user_avs nil :favtime nil))))
(defn popular [session profile-nick]
(if-let [user-info (fetch-nick profile-nick)]
(let [st (fetch-template "popular" session)
profile-nick (:nick user-info)
- raw-dumps (get-popular-dumps profile-nick)
+ raw-dumps (get-popular-dumps profile-nick (or (:user_id session) -1))
dumps (map process-message-for-output raw-dumps)]
(println raw-dumps)
(.setAttribute st "nick" profile-nick)