summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsrc/site.clj31
-rwxr-xr-xstatic/js/pichat.js7
-rw-r--r--template/directory.st38
3 files changed, 72 insertions, 4 deletions
diff --git a/src/site.clj b/src/site.clj
index 9460187..be19830 100755
--- a/src/site.clj
+++ b/src/site.clj
@@ -145,6 +145,15 @@
"avatar" (escape-html (u :avatar))}
{"nick" (u :nick)}))
+(defn process-directory-listing [d]
+ (let [base {"nick" (escape-html (d :nick))
+ "content" (escape-html (d :content))
+ "count" (d :count)}
+ avatar (d :avatar)]
+ (if (non-empty-string? avatar)
+ (assoc base "avatar" avatar)
+ base)))
+
(defn prepare-user-list [room]
(map process-user (sort-by #(% :nick)
(vals @(room :users)))))
@@ -364,10 +373,27 @@
;; Directory
(def *per-directory-page* 25)
+(def *update-directory* true)
+(def *update-directory-ms* (* 60 60 1000))
+
+(defn directory-search [offset]
+ (let [qry (str "SELECT u.nick, u.avatar, m.content "
+ "FROM users u, messages m "
+ "WHERE m.message_id = "
+ " (SELECT n.message_id FROM messages n "
+ " WHERE n.user_id = u.user_id ORDER BY n.created_on DESC LIMIT 1) "
+ "ORDER BY (SELECT COUNT(*) FROM messages where user_id = u.user_id) "
+ "LIMIT ? OFFSET ?")]
+ (do-select [qry *per-directory-page* (* offset *per-directory-page*)])))
(defn directory [session offset]
- (let [st (fetch-template "directory" session)]
-
+ (let [st (fetch-template "directory" session)
+ users (to-array (map process-directory-listing (directory-search offset)))]
+ (.setAttribute st "users" users)
+ (cond (= offset 0) (.setAttribute st "prev" false)
+ (= offset 1) (.setAttribute st "prev" "")
+ :else (.setAttribute st "prev" (str "/" (- offset 1))))
+ (.setAttribute st "next" (str "/" (+ offset 1)))
(.toString st)))
;; Topics
@@ -669,7 +695,6 @@
(-> request :route-params :room)
(-> request :route-params :offset)
params))
- (GET "/stats" (validated-stats session params))
;; TODO: validate POST Referrer headers for POSTs
(POST "/msg" (validated-msg session params))
(POST "/submit-registration" (register session params))
diff --git a/static/js/pichat.js b/static/js/pichat.js
index b322ae9..fd33729 100755
--- a/static/js/pichat.js
+++ b/static/js/pichat.js
@@ -456,4 +456,11 @@ function blinkStart(){
function blinkStop(){
clearInterval(blinkTimer);
+}
+
+function initDirectory() {
+ $(".linkify").each(function() {
+ var text = jQuery(this).text();
+ jQuery(this).html(linkify(text));
+ });
} \ No newline at end of file
diff --git a/template/directory.st b/template/directory.st
index 23960f0..c57c333 100644
--- a/template/directory.st
+++ b/template/directory.st
@@ -16,7 +16,15 @@
top: 57px;
padding: 2em;
}
+ .linkify img {
+ max-height: 300px;
+ max-width: 200px;
+ }
</style>
+ <script>
+ jQuery(document).ready(initDirectory);
+ </script>
+
</head>
<body>
$banner()$
@@ -24,7 +32,35 @@
<div id="headerbar"></div>
<div id="main">
<h3>DUMP STARS</h3>
- </div>
+ <br />
+
+ $if(users)$
+ $users:{ u |
+ <div>
+ <a href="/u/$u.nick$">
+ <h2>$u.nick$</h2>
+ $if(u.avatar)$
+ <img height="50" width="50" src="$u.avatar$"></img>
+ $endif$
+ </a>
+ <div>
+ <span>Last post:</span>
+ <span class="linkify">$u.content$</span>
+ </div>
+ <hr />
+ }$
+ $else$
+ <span>No more users!</span>
+ $endif$
+
+ $if(prev)$
+ <a href="/directory$prev$">BACK</a>
+ $endif$
+ $if(users)$
+ <a href="/directory$next$">MORE</a>
+ $endif$
+
+ </div>
<div id="footer">
$footer()$
</div>