From 2b1e185469c06ad7ccb0f1638cd951a2e87e9fc2 Mon Sep 17 00:00:00 2001 From: fang Date: Fri, 14 Jul 2023 18:06:57 +0200 Subject: [PATCH] lib: dumb summarization utilities for groups Helps us retrieve simple numerical summaries of groups (in)activity, such as number of messages sent, amount of unreads, most active group, etc. --- desk/lib/summarize.hoon | 93 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 desk/lib/summarize.hoon diff --git a/desk/lib/summarize.hoon b/desk/lib/summarize.hoon new file mode 100644 index 0000000..453b9a0 --- /dev/null +++ b/desk/lib/summarize.hoon @@ -0,0 +1,93 @@ +:: summarize: utilities for summarizing groups/chat state in various ways +:: +/- chat, hark, groups +:: +|_ [our=@p now=@da] +++ scry-path + |= [=term =spur] + [(scot %p our) term (scot %da now) spur] +:: +++ summarize-activity + ^- $: sent=@ud + received=@ud + most-sent-group=@t + == + =- :+ s r + =/ g=flag:chat + =< - + ::TODO crashes if no groups + %+ snag 0 + %+ sort ~(tap by g) + |=([[* a=@ud] [* b=@ud]] (gth a b)) + =< title.meta + .^ group:groups + %gx + (scry-path %groups /groups/(scot %p p.g)/[q.g]/group) + == + %+ roll + %~ tap in + .^ (map flag:chat chat:chat) + %gx + (scry-path %chat /chats/chats) + == + =* onn ((on time writ:chat) lte) + |= [[c=flag:chat chat:chat] g=(map flag:chat @ud) s=@ud r=@ud] + =+ .^ log=((mop time writ:chat) lte) + %gx + %+ scry-path %chat + /chat/(scot %p p.c)/[q.c]/writs/newer/(scot %ud (sub now ~d7))/(scot %ud 9.999)/chat-writs + == + :- %+ ~(put by g) group.perm + (add (~(gut by g) group.perm 0) (wyt:onn log)) + %+ roll (tap:onn log) + |= [[time writ:chat] s=_s r=_r] + ?:(=(our author) [+(s) r] [s +(r)]) +:: +++ summarize-inactivity + ^- $: unread-dms=@ud :: unread dm count + unread-etc=@ud :: unread chats count + top-group=@t :: most active group + top-channel=@t :: most active channel + == + =+ .^ =briefs:chat + %gx + (scry-path %chat /briefs/chat-briefs) + == + :: accumulate unread counts + :: + =/ [dum=@ud duc=@ud] + %- ~(rep by briefs) + |= [[w=whom:chat brief:briefs:chat] n=@ud m=@ud] + ?: ?=(%flag -.w) [n (add m count)] + [(add n count) m] + :+ dum duc + :: gather all chat channels & their groups & unread counts + :: + =/ faz=(list [g=flag:chat c=flag:chat n=@ud]) + %+ turn + %~ tap in + .^ (map flag:chat chat:chat) + %gx + (scry-path %chat /chats/chats) + == + |= [c=flag:chat chat:chat] + :+ group.perm c + count:(~(gut by briefs) flag+c *brief:briefs:chat) + =. faz (sort faz |=([[* * a=@ud] [* * b=@ud]] (gth a b))) + :: get display titles of most active channel and its group + :: + ::NOTE in rare cases, we might not know of the existence of the associated + :: group. simply skip past it and try the next one... + =+ .^ =groups:groups + %gx + =- ~& [%scrying -] - + (scry-path %groups /groups/groups) + == + |- + ?~ faz ['???' '???'] ::TODO better copy + ?. (~(has by groups) g.i.faz) + $(faz t.faz) + =/ =group:^groups (~(got by groups) g.i.faz) + :- title.meta.group + title.meta:(~(got by channels.group) %chat c.i.faz) +-- \ No newline at end of file