summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2026-04-26 18:23:35 -0300
committerEuAndreh <eu@euandre.org>2026-04-26 18:23:35 -0300
commitd6afa1a5dd79571d3b0d469493596adad081127c (patch)
treebaf75a08736dd37de8a3fd2c4fc418f9052da146 /src
parentMARKREAD: timestamp= prefix on output, return * for unknown (diff)
downloadpapod-d6afa1a5dd79571d3b0d469493596adad081127c.tar.gz
papod-d6afa1a5dd79571d3b0d469493596adad081127c.tar.xz
MARKREAD: monotonic timestamps and FAIL on missing params
- SET now compares the incoming timestamp against the stored value and refuses to roll back: a smaller timestamp echoes the existing newer value, matching the read-marker monotonic rule. - Empty MARKREAD now responds with FAIL MARKREAD NEED_MORE_PARAMS instead of 461 to align with the cap's bespoke error format.
Diffstat (limited to 'src')
-rw-r--r--src/papod.clj33
1 files changed, 24 insertions, 9 deletions
diff --git a/src/papod.clj b/src/papod.clj
index 1b6dcf5..27dfad0 100644
--- a/src/papod.clj
+++ b/src/papod.clj
@@ -2781,7 +2781,8 @@
nick (client-target client)]
(cond
(empty? params)
- [(numeric-reply client "461" "MARKREAD :Not enough parameters")]
+ [(str "FAIL MARKREAD NEED_MORE_PARAMS"
+ " :Missing parameters")]
:else
(let [handle (first params)
@@ -2795,15 +2796,29 @@
(re-matches ts-rgx timestamp))
(let [ts-only (second
(re-matches ts-rgx timestamp))
- _ (when (and conn chan-eid)
- @(d/transact conn
- [{:papod.read-marker/channel
- chan-eid
- :papod.read-marker/nick nick
- :papod.read-marker/timestamp
- ts-only}]))]
+ stored (when (and db chan-eid)
+ (ffirst
+ (d/q '{:find [?ts]
+ :in [$ ?ch ?nick]
+ :where
+ [[?r :papod.read-marker/channel
+ ?ch]
+ [?r :papod.read-marker/nick
+ ?nick]
+ [?r :papod.read-marker/timestamp
+ ?ts]]}
+ db chan-eid nick)))
+ advance? (or (nil? stored)
+ (pos? (compare ts-only stored)))]
+ (when (and advance? conn chan-eid)
+ @(d/transact conn
+ [{:papod.read-marker/channel chan-eid
+ :papod.read-marker/nick nick
+ :papod.read-marker/timestamp
+ ts-only}]))
[(str ":" +server-name+ " MARKREAD " handle
- " " timestamp)])
+ " timestamp="
+ (if advance? ts-only stored))])
;; SET with bad timestamp shape: reject
(and timestamp