Skip to content

A peer-to-peer stack for code collaboration

Recent issues activity (#338)

James Haydonddad21399af8
diff --git a/rad/monadic/issues.rad b/rad/monadic/issues.rad
index 61ba14a..0e7d669 100644
--- a/rad/monadic/issues.rad
+++ b/rad/monadic/issues.rad
@@ -154,6 +154,31 @@
(def is (sort-by (fn [i] (- 0 (lookup :number i))) (values (list-issues chain))))
(take n is)))
+(def get-recent
+ "Returns the activity on the chain since a timestamp. This is a dict with two
+ keys: `:new-issues` and `:new-comments`. The comments are annotated with issue
+ numbers."
+ (fn [chain from]
+ (def u (unix-epoch from))
+ (def mod-at (fn [x] (unix-epoch (lookup :modified-at x))))
+ (def since
+ (fn [xs]
+ (sort-by (fn [x] (- 0 (mod-at x)))
+ (filter (fn [x] (< u (mod-at x))) xs))))
+ (def is (values (list-issues chain)))
+ (def cs
+ (foldr (fn [i acc]
+ (<> (map (fn [c]
+ (insert :issue-number
+ (lookup :number i)
+ c))
+ (lookup :comments i))
+ acc))
+ []
+ is))
+ {:new-issues (since is)
+ :new-comments (since cs)}))
+
(:test
"The monadic issues chain works."
[:setup
@@ -166,14 +191,24 @@
(simple-add-comment! chain 1 "comment1")
(simple-edit-issue! chain 0 {:state :closed})
(simple-edit-comment! chain 0 0 {:body "comment0-edit"})
+ (def t (now!))
+ (simple-create-issue! chain "new" "new")
+ (simple-create-issue! chain "newer" "newer")
+ (simple-add-comment! chain 0 "new")
(fetch! chain)
- (def is (list-issues chain)))]
- [ (length (seq is)) ==> 2 ]
+ (def is (list-issues chain))
+ (def new (get-recent chain t))
+ (def new-issues (map (fn [i] (lookup :title i)) (lookup :new-issues new)))
+ (def new-comments (map (fn [c] (lookup :body c)) (lookup :new-comments new)))
+ )]
+ [ (length (seq is)) ==> 4 ]
[ (view (.. (@ 0) (@ :title)) is) ==> "title0" ]
[ (view (.. (@ 1) (@ :title)) is) ==> "title1" ]
[ (view (... [(@ 1) (@ :comments) (@nth 0) (@ :body)]) is) ==> "comment1" ]
[ (view (... [(@ 0) (@ :comments) (@nth 0) (@ :body)]) is) ==> "comment0-edit" ]
[ (short (first (values is))) ==> "0: title0" ]
- [ (short (first (list-last chain 1))) ==> "1: title1" ]
+ [ (short (first (list-last chain 1))) ==> "3: newer" ]
[ (view (.. (@ 0) (@ :state)) is) ==> :closed ]
+ [ new-issues ==> ["newer" "new"] ]
+ [ new-comments ==> ["new"]]
)
diff --git a/test/spec/Radicle/Internal/TestCapabilities.hs b/test/spec/Radicle/Internal/TestCapabilities.hs
index 0b479fa..d03e1e1 100644
--- a/test/spec/Radicle/Internal/TestCapabilities.hs
+++ b/test/spec/Radicle/Internal/TestCapabilities.hs
@@ -180,7 +180,11 @@ instance Monad m => UUID.MonadUUID (StateT WorldState m) where
pad i = toS $ prefix <> replicate (12 - length i) '0' <> i
instance CurrentTime (StateT WorldState IO) where
- currentTime = gets worldStateCurrentTime
+ -- 10 seconds go by every time the current time is queried.
+ currentTime = do
+ t <- gets worldStateCurrentTime
+ modify $ \ws -> ws { worldStateCurrentTime = Time.addUTCTime 10 t }
+ pure t
instance System (StateT WorldState IO) where
systemS proc = lift $ systemS proc