diff options
author | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2012-04-09 16:43:53 +0200 |
---|---|---|
committer | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2012-04-09 16:43:53 +0200 |
commit | f7eb36d782508cbf3cc73e1f05630776d4a207bd (patch) | |
tree | 7a56c51baa4e220ec4db1bdf5a0c169a0ec830be | |
parent | a315bdaf6dea23da17c09d279f374421c6d88549 (diff) |
Lafargue: Add Atom feed.
-rw-r--r-- | src/mulk/benki/lazychat.clj | 72 | ||||
-rw-r--r-- | src/mulk/benki/util.clj | 2 | ||||
-rw-r--r-- | static/style/lafargue.css | 4 |
3 files changed, 62 insertions, 16 deletions
diff --git a/src/mulk/benki/lazychat.clj b/src/mulk/benki/lazychat.clj index 7546f45..189b562 100644 --- a/src/mulk/benki/lazychat.clj +++ b/src/mulk/benki/lazychat.clj @@ -18,6 +18,8 @@ (:import [org.apache.abdera Abdera])) +(defonce abdera (Abdera.)) + (defn create-lazychat-message! [{content :content, visibility :visibility format :format, targets :targets, referees :referees, id :id}] @@ -74,6 +76,23 @@ :href (resolve-uri "/style/lafargue.css") :type "text/css"}])}) +(defmacro with-messages-visible-by-user [[messages user] & body] + `(sql/with-query-results ~messages + ["SELECT m.id, m.author, m.date, m.content, m.format, u.first_name, u.last_name + FROM lazychat_messages m + JOIN users u ON (author = u.id) + WHERE (visibility = 'public' + OR (visibility = 'protected' AND (?::INTEGER) IS NOT NULL) + OR (visibility = 'personal' + AND EXISTS (SELECT * + FROM lazychat_targets t + WHERE t.target = (?::INTEGER) + AND message = m.id))) + ORDER BY m.date DESC" + ~user ~user] + ~@body)) + + (defpage "/lafargue" {} (with-dbt (layout lafargue-list-page "Lafargue Lazy Chat" @@ -90,19 +109,7 @@ [:input {:type "radio", :name "visibility", :value "public"} "Public"]] [:div [:input {:type "submit"}]]]] [:ul {:class "lafargue-list"} - (sql/with-query-results messages - ["SELECT m.id, m.author, m.date, m.content, m.format, u.first_name, u.last_name - FROM lazychat_messages m - JOIN users u ON (author = u.id) - WHERE (visibility = 'public' - OR (visibility = 'protected' AND (?::INTEGER) IS NOT NULL) - OR (visibility = 'personal' - AND EXISTS (SELECT * - FROM lazychat_targets t - WHERE t.target = (?::INTEGER) - AND message = m.id))) - ORDER BY m.date DESC" - *user* *user*] + (with-messages-visible-by-user [messages *user*] (doall (for [message messages] [:li {:class "lafargue-message"} @@ -113,8 +120,45 @@ [:span {:class "lafargue-message-owner"} " by " (escape-html (:first_name message))]] [:div {:class "lafargue-message-body"} - (sanitize-html (markdown->html (:content message)))]])))]]))) + (sanitize-html (markdown->html (:content message)))]]))) + [:div {:id "lafargue-footer"} + (let [feed-link (linkrel :lafargue :feed)] + [:span {:id "lafargue-footer-text"} + "[" [:a {:href (resolve-uri feed-link)} "Atom"] "]" + (when *user* + (list + " [" [:a {:href (resolve-uri (authlink feed-link))} "Atom auth"] "]" + " [" [:a {:href (authlink (:uri (request/ring-request)))} "authlink"] "]"))])]]]))) + + +(defn lazychat-feed-for-user [user] + (with-dbt + (with-messages-visible-by-user [messages user] + (let [last-updated (sql/with-query-results results + ["SELECT MAX(date) AS maxdate FROM lazychat_messages"] + (:maxdate (first results))) + feed (doto (.newFeed abdera) + (.setId (fmt nil "tag:~A,2012:/lafargue" + (:tag-base @benki-config))) + (.setTitle "Lafargue Lazy Chat") + (.setUpdated last-updated) + (.addLink (link :lafargue)))] + (doseq [item messages] + (doto (.addEntry feed) + (.setId (fmt nil "tag:~A,2012:/lafargue/~D" + (:tag-base benki-config) + (:id item))) + (.setSummaryAsHtml (sanitize-html (markdown->html (:content item)))) + (.setPublished (:date item)) + ;;(.setAuthor (fmt nil "~A ~A" (:first_name item) (:last_name item))) + ;;(.addLink (link :lafargue (:id item))) + )) + (.toString feed))))) + +(defpage "/lafargue/feed" {} + (response/content-type "application/atom+xml; charset=UTF-8" + (lazychat-feed-for-user *user*))) (defpage [:any "/lafargue/post"] {content :content, visibility :visibility format :format, targets :targets, diff --git a/src/mulk/benki/util.clj b/src/mulk/benki/util.clj index cb0ffde..478fac3 100644 --- a/src/mulk/benki/util.clj +++ b/src/mulk/benki/util.clj @@ -62,6 +62,8 @@ [[:marx :submit]] (fmt nil "/marx/submit") [[:marx :feed]] (fmt nil "/marx/feed") [[:marx id]] (fmt nil "/marx/~a" id) + [[:lafargue]] (fmt nil "/lafargue") + [[:lafargue :feed]] (fmt nil "/lafargue/feed") [[:lafargue :post]] (fmt nil "/lafargue/post") [[:wiki title & xs]] (fmt nil "/wiki/~a~@[~a~]" title (first xs)) )) diff --git a/static/style/lafargue.css b/static/style/lafargue.css index 31b6a30..9b54b43 100644 --- a/static/style/lafargue.css +++ b/static/style/lafargue.css @@ -10,7 +10,7 @@ margin-bottom: 1em; } -#lafargue-message-footer { +#lafargue-footer { text-align: right; position: relative; padding: 0.5em 0.5em 0.5em 0.5em; @@ -19,7 +19,7 @@ font-style: oblique; } -#lafargue-message-footer-text { +#lafargue-footer-text { padding: 0.5em 1em 0.5em 1em; border: solid 1px #000; background-color: orange; |