diff options
| author | EuAndreh <eu@euandre.org> | 2026-04-26 18:21:31 -0300 |
|---|---|---|
| committer | EuAndreh <eu@euandre.org> | 2026-04-26 18:21:31 -0300 |
| commit | bb7afc4bbd5298c568cec3dd58359201b0369f77 (patch) | |
| tree | e73143eff832ce7a5bcee83f97cf0d33eace4f3c /src/papod.clj | |
| parent | Normalize channel handles to lowercase in JOIN (diff) | |
| download | papod-bb7afc4bbd5298c568cec3dd58359201b0369f77.tar.gz papod-bb7afc4bbd5298c568cec3dd58359201b0369f77.tar.xz | |
MARKREAD: timestamp= prefix on output, return * for unknown
- GET on a target with no stored marker now returns '*' regardless
of whether the channel exists, matching the read-marker spec.
- SET only persists the bare ISO-8601 timestamp portion (avoiding
the 'timestamp=timestamp=...' echo on subsequent GETs).
- Reject malformed SET payloads with FAIL MARKREAD INVALID_PARAMS.
Diffstat (limited to 'src/papod.clj')
| -rw-r--r-- | src/papod.clj | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/src/papod.clj b/src/papod.clj index d0c49cc..1b6dcf5 100644 --- a/src/papod.clj +++ b/src/papod.clj @@ -2787,23 +2787,34 @@ (let [handle (first params) timestamp (second params) db (when conn (d/db conn)) - chan-eid (when db (resolve-channel db handle))] + chan-eid (when db (resolve-channel db handle)) + ts-rgx #"timestamp=(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z)"] (cond - (nil? chan-eid) - [(str "FAIL MARKREAD INVALID_TARGET " handle " :No such channel")] + ;; SET with valid timestamp=... + (and timestamp + (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}]))] + [(str ":" +server-name+ " MARKREAD " handle + " " timestamp)]) - ;; SET: MARKREAD #channel timestamp=... - timestamp - (do (when conn - @(d/transact conn - [{:papod.read-marker/channel chan-eid - :papod.read-marker/nick nick - :papod.read-marker/timestamp timestamp}])) - [(str ":" +server-name+ " MARKREAD " handle " " timestamp)]) + ;; SET with bad timestamp shape: reject + (and timestamp + (not (re-matches ts-rgx timestamp))) + [(str "FAIL MARKREAD INVALID_PARAMS " handle + " " timestamp + " :Invalid timestamp")] ;; GET: MARKREAD #channel :else - (let [stored (when db + (let [stored (when (and db chan-eid) (ffirst (d/q '{:find [?ts] :in [$ ?ch ?nick] @@ -2812,7 +2823,9 @@ [?r :papod.read-marker/timestamp ?ts]]} db chan-eid nick)))] [(str ":" +server-name+ " MARKREAD " handle " " - (or stored "*"))])))))) + (if stored + (str "timestamp=" stored) + "*"))])))))) (defn- handle-topic [params client components] |
