aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchristoph <christoph@debian.uxul.homelinux.org>2009-02-20 01:08:48 +0100
committerchristoph <christoph@debian.uxul.homelinux.org>2009-02-20 01:08:48 +0100
commitda44c7246490e3e3afc9c4e3607d6ea2813b0fbb (patch)
treefc3d600a9d48e1940c13bb5fd005a5376ed0679c
parentafc7cf1f7788153d8eec561717523b90d12e7725 (diff)
Added a function "subscribe-feed"
Unfortunately it is not working yet in all cases (see code)
-rw-r--r--cljssss-g.clj26
1 files changed, 26 insertions, 0 deletions
diff --git a/cljssss-g.clj b/cljssss-g.clj
index 8313968..bdb8c17 100644
--- a/cljssss-g.clj
+++ b/cljssss-g.clj
@@ -91,6 +91,32 @@
{:feed id
:entry entry-id}))))))))
+;; system-wide subscription
+;; ******* FIXME: Doesnt work when no feed was subscribed yet
+(defn subscribe-to-feed [url]
+ (let [maybe-ret
+ (with-dbt
+ (if (sql/with-query-results
+ [exi]
+ ["SELECT id FROM feed WHERE uri=?" url]
+ (if exi
+ (second (first exi))
+ nil))
+ nil ;; do nothing, return nil
+ (let [free-id
+ (sql/with-query-results
+ [max-id]
+ ["SELECT MAX(id) FROM feed"]
+ (if max-id (+ (second (first max-id)) 1) 0))]
+ (sql/update-or-insert-values :feed
+ ["id = ?" free-id]
+ {:id free-id
+ :uri url})
+ free-id)))]
+ (if maybe-ret
+ (fetch-feed maybe-ret))
+ maybe-ret))
+
(run-server {:port 8080}
"/*" cljssss-g)