-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathchat.hoon
1419 lines (1417 loc) · 35.5 KB
/
chat.hoon
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/- c=chat, g=groups
/- meta
/- ha=hark
/+ default-agent, verb, dbug
/+ chat-json
/+ pac=dm
/+ ch=chat-hark
/+ gra=graph-store
/+ mig=chat-graph
/+ e=epic
/* desk-bill %bill /desk/bill
^- agent:gall
=>
|%
+$ card card:agent:gall
++ def-flag `flag:c`[~zod %test]
++ club-eq 2 :: reverb control: max number of forwards for clubs
++ okay `epic:e`0
+$ current-state
$: %1
chats=(map flag:c chat:c)
dms=(map ship dm:c)
clubs=(map id:club:c club:c)
drafts=(map whom:c story:c)
pins=(list whom:c)
bad=(set ship)
inv=(set ship)
voc=(map [flag:c id:c] (unit said:c))
==
--
=| current-state
=* state -
=<
%+ verb &
%- agent:dbug
|_ =bowl:gall
+* this .
def ~(. (default-agent this %|) bowl)
cor ~(. +> [bowl ~])
++ on-init
^- (quip card _this)
=^ cards state
abet:init:cor
[cards this]
::
++ on-save !>([state okay])
++ on-load
|= =vase
^- (quip card _this)
=^ cards state
abet:(load:cor vase)
[cards this]
::
++ on-poke
|= [=mark =vase]
^- (quip card _this)
=^ cards state
abet:(poke:cor mark vase)
[cards this]
++ on-watch
|= =path
^- (quip card _this)
=^ cards state
abet:(watch:cor path)
[cards this]
::
++ on-peek peek:cor
::
++ on-leave on-leave:def
++ on-fail on-fail:def
::
++ on-agent
|= [=wire =sign:agent:gall]
^- (quip card _this)
=^ cards state
abet:(agent:cor wire sign)
[cards this]
++ on-arvo
|= [=wire sign=sign-arvo]
^- (quip card _this)
=^ cards state
abet:(arvo:cor wire sign)
[cards this]
--
|_ [=bowl:gall cards=(list card)]
++ abet [(flop cards) state]
++ cor .
++ emit |=(=card cor(cards [card cards]))
++ emil |=(caz=(list card) cor(cards (welp (flop caz) cards)))
++ give |=(=gift:agent:gall (emit %give gift))
++ now-id `id:c`[our now]:bowl
++ init
^+ cor
watch-groups
:: +load: load next state
++ load
|= =vase
|^ ^+ cor
=/ maybe-old=(each [versioned-state epic:e] tang)
(mule |.(!<([versioned-state epic:e] vase)))
=/ [old=versioned-state cool=epic:e]
?. ?=(%| -.maybe-old) p.maybe-old
[!<(versioned-state vase) okay]
|-
?- -.old
%0
%= $
old (state-0-to-1 old)
==
%1
=. state old
?: =(okay cool) cor
=- (give %fact ~(tap in -) epic+!>(okay))
%- ~(gas in *(set path))
%+ murn ~(val by sup.bowl)
|= [=ship =path]
^- (unit _path)
?. |(=(/epic path) ?=([%chat @ @ %updates *] path)) ~
`path
==
+$ versioned-state
$% state-0
state-1
==
+$ state-0
$: %0
chats=(map flag:zero chat:zero)
dms=(map ship dm:zero)
clubs=(map id:club:zero club:zero)
drafts=(map whom:zero story:zero)
pins=(list whom:zero)
bad=(set ship)
inv=(set ship)
voc=(map [flag:zero id:zero] (unit said:zero))
==
++ zero zero:old:c
+$ state-1 current-state
++ one c
++ state-0-to-1
|= s=state-0
^- state-1
%* . *state-1
dms dms.s
clubs clubs.s
drafts drafts.s
pins pins.s
bad bad.s
inv inv.s
voc voc.s
chats (chats-0-to-1 chats.s)
==
++ chats-0-to-1
|= chats=(map flag:zero chat:zero)
^- (map flag:one chat:one)
%- ~(run by chats)
|= =chat:zero
%* . *chat:one
remark remark.chat
log log.chat
perm perm.chat
pact pact.chat
::
net
?- -.net.chat
?(%load %pub) net.chat
%sub [%sub p.net.chat *saga:e]
==
==
--
::
++ watch-groups
^+ cor
(emit %pass /groups %agent [our.bowl %groups] %watch /groups)
::
++ watch-epic
|= her=ship
^+ cor
=/ =wire /epic
=/ =dock [her dap.bowl]
?: (~(has by wex.bowl) [wire dock])
cor
(emit %pass wire %agent [her dap.bowl] %watch /epic)
::
++ poke
|= [=mark =vase]
|^ ^+ cor
?+ mark ~|(bad-poke/mark !!)
%holt (holt |)
%graph-import
(import-graph !<([flag:g flag:g graph:gra] vase))
::
%dm-rsvp
=+ !<(=rsvp:dm:c vase)
di-abet:(di-rsvp:(di-abed:di-core ship.rsvp) ok.rsvp)
%chat-pins
=+ !<(ps=(list whom:c) vase)
(pin ps)
::
?(%flag %channel-join)
=+ !<(=flag:c vase)
?< =(our.bowl p.flag)
(join flag)
::
%chat-leave
=+ !<(=leave:c vase)
?< =(our.bowl p.leave) :: cannot leave chat we host
ca-abet:ca-leave:(ca-abed:ca-core leave)
::
%chat-draft
=+ !<(=draft:c vase)
?> =(src.bowl our.bowl)
%_ cor
drafts
(~(put by drafts) p.draft q.draft)
==
::
%chat-create
=+ !<(req=create:c vase)
(create req)
::
?(%chat-action-0 %chat-action)
=+ !<(=action:c vase)
=. p.q.action now.bowl
=/ chat-core (ca-abed:ca-core p.action)
?: =(p.p.action our.bowl)
ca-abet:(ca-update:chat-core q.action)
ca-abet:(ca-proxy:chat-core q.action)
::
%chat-remark-action
=+ !<(act=remark-action:c vase)
?- -.p.act
%ship di-abet:(di-remark-diff:(di-abed:di-core p.p.act) q.act)
%flag ca-abet:(ca-remark-diff:(ca-abed:ca-core p.p.act) q.act)
%club cor :: TODO
==
::
%dm-action
=+ !<(=action:dm:c vase)
di-abet:(di-proxy:(di-abed-soft:di-core p.action) q.action)
::
%dm-diff
=+ !<(=diff:dm:c vase)
di-abet:(di-take-counter:(di-abed-soft:di-core src.bowl) diff)
::
%club-create
cu-abet:(cu-create:cu-core !<(=create:club:c vase))
::
%club-action
=+ !<(=action:club:c vase)
=/ cu (cu-abed p.action)
cu-abet:(cu-diff:cu q.action)
::
%dm-archive di-abet:di-archive:(di-abed:di-core !<(ship vase))
==
++ join
|= =flag:c
^+ cor
=. chats (~(put by chats) flag *chat:c)
ca-abet:(ca-join:ca-core flag)
::
++ create
|= req=create:c
|^ ^+ cor
~_ leaf+"Create failed: check group permissions"
?> can-nest
?> ((sane %tas) name.req)
=/ =flag:c [our.bowl name.req]
=| =chat:c
=/ =perm:c [writers.req group.req]
=. perm.chat perm
=. net.chat [%pub ~]
=. chats (~(put by chats) flag chat)
ca-abet:(ca-init:(ca-abed:ca-core flag) req)
++ can-nest
^- ?
=/ gop (~(got by groups) group.req)
%- ~(any in bloc.gop)
~(has in sects:(~(got by fleet.gop) our.bowl))
::
++ groups
.^ groups:g
%gx
/(scot %p our.bowl)/groups/(scot %da now.bowl)/groups/noun
==
--
++ pin
|= ps=(list whom:c)
=. pins ps
cor
::
++ import-graph
|= [grp=flag:g =flag:g =graph:gra]
^+ cor
=/ =pact:c (convert:mig graph)
=/ =net:c pub/~
=| =remark:c
=/ =perm:c `grp
=/ =diff:c create/[perm `pact]
=| =log:c
=. log (put:log-on:c log now.bowl diff)
=/ =chat:c
[net remark log perm pact]
=. chats (~(put by chats) flag chat)
cor :: TODO: initialise?
--
++ watch
|= =(pole knot)
^+ cor
?+ pole ~|(bad-watch-path/path !!)
[%club %new ~] ?>(from-self cor)
[%briefs ~] ?>(from-self cor)
[%ui ~] ?>(from-self cor)
[%dm %invited ~] ?>(from-self cor)
::
[%epic ~]
(give %fact ~ epic+!>(okay))
::
[%said host=@ name=@ %msg sender=@ time=@ ~]
=/ host=ship (slav %p host.pole)
=/ =flag:c [host name.pole]
=/ sender=ship (slav %p sender.pole)
=/ =id:c [sender (slav %ud time.pole)]
(watch-said flag id)
::
[%chat ship=@ name=@ rest=*]
=/ =ship (slav %p ship.pole)
ca-abet:(ca-watch:(ca-abed:ca-core ship name.pole) rest.pole)
::
[%dm ship=@ rest=*]
=/ =ship (slav %p ship.pole)
di-abet:(di-watch:(di-abed:di-core ship) rest.pole)
::
[%club id=@ rest=*]
=/ =id:club:c (slav %uv id.pole)
cu-abet:(cu-watch:(cu-abed id) rest.pole)
==
::
++ agent
|= [=(pole knot) =sign:agent:gall]
^+ cor
?+ pole ~|(bad-agent-wire/pole !!)
~ cor
::
[%epic ~]
(take-epic sign)
::
[%said host=@ name=@ %msg sender=@ time=@ ~]
=/ host=ship (slav %p host.pole)
=/ =flag:c [host name.pole]
=/ sender=ship (slav %p sender.pole)
=/ =id:c [sender (slav %ud time.pole)]
(take-said flag id sign)
::
[%dm ship=@ rest=*]
=/ =ship (slav %p ship.pole)
di-abet:(di-agent:(di-abed:di-core ship) rest.pole sign)
::
[%club id=@ rest=*]
=/ =id:club:c (slav %uv id.pole)
cu-abet:(cu-agent:(cu-abed id) rest.pole sign)
[%chat ship=@ name=@ rest=*]
=/ =ship (slav %p ship.pole)
ca-abet:(ca-agent:(ca-abed:ca-core ship name.pole) rest.pole sign)
::
[%hark ~]
?> ?=(%poke-ack -.sign)
?~ p.sign cor
%- (slog leaf/"Failed to hark" u.p.sign)
cor
::
[%groups ~]
?+ -.sign !!
%kick watch-groups
::
%watch-ack
%. cor
?~ p.sign same
=/ =tank
leaf/"Failed groups subscription in {<dap.bowl>}, unexpected"
(slog tank u.p.sign)
::
%fact
?. =(%group-action p.cage.sign) cor
(take-groups !<(=action:g q.cage.sign))
==
==
++ watch-said
|= [=flag:c =id:c]
?. (~(has by chats) flag)
(proxy-said flag id)
ca-abet:(ca-said:(ca-abed:ca-core flag) id)
++ said-wire
|= [=flag:c =id:c]
^- wire
/said/(scot %p p.flag)/[q.flag]/msg/(scot %p p.id)/(scot %ud q.id)
::
++ take-said
|= [=flag:c =id:c =sign:agent:gall]
^+ cor
?+ -.sign !!
%watch-ack
%. cor
?~ p.sign same
(slog leaf/"Preview failed" u.p.sign)
::
%kick
?: (~(has by voc) [flag id])
cor :: subscription ended politely
(proxy-said flag id)
::
%fact
=. cor
(give %fact ~[(said-wire flag id)] cage.sign)
?+ p.cage.sign ~|(funny-mark/p.cage.sign !!)
%chat-said
=+ !<(=said:c q.cage.sign)
=. voc (~(put by voc) [flag id] `said)
cor
::
%chat-denied
=. voc (~(put by voc) [flag id] ~)
cor
==
==
::
++ proxy-said
|= [=flag:c =id:c]
=/ =dock [p.flag dap.bowl]
=/ wire (said-wire flag id)
=/ =card [%pass wire %agent dock %watch wire]
(emit card)
::
++ take-epic
|= =sign:agent:gall
^+ cor
?+ -.sign cor
%kick
~& 'todo: check that sub is removed before ingesting kick'^wex.bowl
(watch-epic src.bowl)
::
%fact
?: =(%epic p.cage.sign)
~& '!!! weird fact on /epic'
cor
=+ !<(=epic:e q.cage.sign)
?. =(epic okay) :: is now our guy
cor
%+ roll ~(tap by chats)
|= [[=flag:g =chat:c] out=_cor]
ca-abet:ca-sub:(ca-abed:ca-core:out flag)
::
%watch-ack
%. cor
?~ p.sign same
(slog leaf/"weird watch nack" u.p.sign)
==
:: TODO: more efficient?
:: perhaps a cached index of (jug group=flag chat=flag)
++ take-groups
|= =action:g
=/ affected=(list flag:c)
%+ murn ~(tap by chats)
|= [=flag:c =chat:c]
?. =(p.action group.perm.chat) ~
`flag
?+ q.q.action cor
[%fleet * %del ~]
~& 'revoke perms for'
%+ roll affected
|= [=flag:c co=_cor]
^+ cor
%+ roll ~(tap in p.q.q.action)
|= [=ship ci=_cor]
^+ cor
=/ ca (ca-abed:ca-core:ci flag)
ca-abet:(ca-revoke:ca ship)
::
[%fleet * %del-sects *]
~& 'recheck permissions'
%+ roll affected
|= [=flag:c co=_cor]
=/ ca (ca-abed:ca-core:co flag)
ca-abet:ca-recheck:ca
::
[%channel * %del-sects *]
~& 'recheck permissions'
%+ roll affected
|= [=flag:c co=_cor]
=/ ca (ca-abed:ca-core:co flag)
ca-abet:ca-recheck:ca
==
::
++ arvo
|= [=wire sign=sign-arvo]
^+ cor
~& arvo/wire
cor
++ peek
|= =path
^- (unit (unit cage))
?+ path [~ ~]
::
[%x %chat ~] ``flags+!>(~(key by chats))
::
[%x %chats ~] ``chats+!>(chats)
::
[%x %pins ~] ``chat-pins+!>(pins)
::
[%x %chat @ @ *]
=/ =ship (slav %p i.t.t.path)
=* name i.t.t.t.path
(ca-peek:(ca-abed:ca-core ship name) t.t.t.t.path)
::
[%x %dm ~]
``ships+!>(~(key by accepted-dms))
::
[%x %dm %invited ~]
``ships+!>(~(key by pending-dms))
::
[%x %dm %archive ~]
``ships+!>(~(key by archived-dms))
::
[%x %dm @ *]
=/ =ship (slav %p i.t.t.path)
(di-peek:(di-abed:di-core ship) t.t.t.path)
::
[%x %club @ *]
(cu-peek:(cu-abed (slav %uv i.t.t.path)) t.t.t.path)
::
[%x %draft @ $@(~ [@ ~])]
=/ =whom:c
?^ t.t.t.path
flag+[(slav %p i.t.t.path) i.t.t.t.path]
%+ rash
i.t.t.path
;~ pose
(stag %ship ;~(pfix sig fed:ag))
(stag %club club-id-rule:dejs:chat-json)
==
=- ``chat-draft+!>(-)
`draft:c`[whom (~(gut by drafts) whom *story:c)]
::
[%x %briefs ~]
=- ``chat-briefs+!>(-)
^- briefs:c
%- ~(gas by *briefs:c)
%+ welp
%+ turn ~(tap in ~(key by clubs))
|= =id:club:c
=/ cu (cu-abed id)
[club/id cu-brief:cu]
%+ welp
%+ murn ~(tap in ~(key by dms))
|= =ship
=/ di (di-abed:di-core ship)
?: ?=(?(%invited %archive) net.dm.di) ~
?: =([~ ~] pact.dm.di) ~
`[ship/ship di-brief:di]
%+ turn ~(tap in ~(key by chats))
|= =flag:c
:- flag/flag
ca-brief:(ca-abed:ca-core flag)
==
::
++ holt
|= tell=?
^+ cor
=. state *current-state
=. cor
%- emil
%+ turn ~(tap in ~(key by wex.bowl))
|= [=wire =ship =term]
^- card
[%pass wire %agent [ship term] %leave ~]
=. cor init
?. tell cor
%- emil
%+ murn `(list dude:gall)`desk-bill
|= =dude:gall
^- (unit card)
?: =(dude dap.bowl) ~
`[%pass / %agent [our.bowl dude] %poke holt+!>(~)]
::
++ give-brief
|= [=whom:c =brief:briefs:c]
(give %fact ~[/briefs] chat-brief-update+!>([whom brief]))
::
++ pass-hark
|= [all=? desk=? =yarn:ha]
^- card
=/ =wire /hark
=/ =dock [our.bowl %hark]
=/ =cage hark-action+!>([%add-yarn all desk yarn])
[%pass wire %agent dock %poke cage]
++ spin
|= [=rope:ha con=(list content:ha) wer=path but=(unit button:ha)]
^- yarn:ha
=/ id (end [7 1] (shax eny.bowl))
[id rope now.bowl con wer but]
++ flatten
|= content=(list inline:c)
^- cord
%- crip
%- zing
%+ turn
content
|= c=inline:c
^- tape
?@ c (trip c)
?- -.c
%break ""
%tag (trip p.c)
%block (trip q.c)
%link (trip q.c)
%ship (scow %p p.c)
?(%code %inline-code) ""
?(%italics %bold %strike %blockquote) (trip (flatten p.c))
==
::
++ mentioned
|= [content=(list inline:c) =ship]
^- ?
|-
?~ content %.n
=/ head i.content
=/ tail t.content
?@ head
$(content tail)
?- -.head
?(%break %tag %block %link %code %inline-code) $(content tail)
::
?(%italics %bold %strike %blockquote)
?: (mentioned p.head ship) %.y
$(content tail)
::
%ship
?: =(ship p.head) %.y
$(content tail)
==
::
++ from-self =(our src):bowl
++ cu-abed cu-abed:cu-core
::
++ cu-core
|_ [=id:club:c =club:c gone=_|]
+* cu-pact ~(. pac pact.club)
++ cu-core .
++ cu-abet
=. clubs
?: gone
(~(del by clubs) id)
(~(put by clubs) id club)
cor
++ cu-abed
|= i=id:club:c
~| no-club/i
cu-core(id i, club (~(gut by clubs) i *club:c))
++ cu-out (~(del in cu-circle) our.bowl)
++ cu-circle
(~(uni in team.club) hive.club)
::
++ cu-area `wire`/club/(scot %uv id)
::
++ cu-spin
|= [con=(list content:ha) but=(unit button:ha)]
:: hard coded desk because these shouldn't appear in groups
=/ rope [~ ~ %talk /club/(scot %uv id)]
=/ link /dm/(scot %uv id)
(spin rope con link but)
::
++ cu-pass
|%
++ act
|= [=ship =diff:club:c]
^- card
=/ =wire (snoc cu-area %gossip)
=/ =dock [ship dap.bowl]
=/ =cage club-action+!>(`action:club:c`[id diff])
[%pass wire %agent dock %poke cage]
::
++ gossip
|= =diff:club:c
^- (list card)
%+ turn ~(tap in cu-out)
|= =ship
(act ship diff)
--
::
++ cu-init
|= [=net:club:c =create:club:c]
=/ clab=club:c
[*pact:c (silt our.bowl ~) hive.create *data:meta net |]
cu-core(id id.create, club clab)
::
++ cu-brief (brief:cu-pact [our now]:bowl)
::
++ cu-create
|= =create:club:c
~& id/id.create
=. cu-core (cu-init %done create)
=. cu-core (cu-diff 0 [%init team hive met]:club)
=/ =notice:c
:- ''
(rap 3 ' started a group chat with ' (scot %ud ~(wyt in hive.create)) ' other members' ~)
=. cor (give-brief club/id cu-brief)
=. cu-core
(cu-diff 0 [%writ now-id %add ~ our.bowl now.bowl notice/notice])
cu-core
::
:: NB: need to be careful not to forward automatically generated
:: messages like this, each node should generate its own notice
:: messages, and never forward. XX: defend against?
++ cu-post-notice
|= [=ship =notice:c]
=/ =id:c
[ship now.bowl]
=/ w-d=diff:writs:c [id %add ~ ship now.bowl notice/notice]
=. pact.club (reduce:cu-pact now.bowl w-d)
(cu-give-writs-diff w-d)
::
++ cu-give-delta
|= =delta:club:c
=. cor
=/ =cage club-delta+!>(delta)
(emit %give %fact ~[(snoc cu-area %ui)] cage)
cu-core
::
++ cu-give-writs-diff
|= =diff:writs:c
=. cor
=/ =cage writ-diff+!>(diff)
~& diff
~& cu-area
(emit %give %fact ~[(welp cu-area /ui/writs)] cage)
cu-core
::
++ cu-diff
|= [=echo:club:c =delta:club:c]
:: ?> (~(has in cu-circle) src.bowl) :: TODO: signatures?? probably overkill
=? cor (lth echo club-eq)
(emil (gossip:cu-pass +(echo) delta))
?- -.delta
::
%init
=: hive.club hive.delta
team.club team.delta
met.club met.delta
==
=/ cage club-invite+!>([id (tail delta)])
=. cor (emit %give %fact ~[`wire`/club/new] cage)
cu-core
::
%meta
=. met.club meta.delta
=. cu-core (cu-give-delta delta)
cu-core
::
%writ
=. pact.club (reduce:cu-pact now.bowl diff.delta)
=. cu-core (cu-give-writs-diff diff.delta)
?- -.q.diff.delta
?(%del %add-feel %del-feel) cu-core
%add
=/ memo=memo:c p.q.diff.delta
?: =(our.bowl author.memo) cu-core
?- -.content.memo
%notice cu-core
%story
=/ yarn
%+ cu-spin
:~ [%ship author.memo]
': '
(flatten q.p.content.memo)
==
~
=. cor (emit (pass-hark & & yarn))
cu-core
==
==
::
%team
=* ship ship.delta
=. cu-core (cu-give-delta delta)
?: &(!ok.delta (~(has in team.club) ship))
?. =(our src):bowl
cu-core
cu-core(gone &)
?. (~(has in hive.club) ship)
cu-core
=. hive.club (~(del in hive.club) ship)
?. ok.delta
(cu-post-notice ship '' ' declined the invite')
=. cor (give-brief club/id cu-brief)
=. team.club (~(put in team.club) ship)
(cu-post-notice ship '' ' joined the chat')
::
%hive
=. cu-core (cu-give-delta delta)
?: add.delta
?: (~(has in hive.club) for.delta)
cu-core
=. hive.club (~(put in hive.club) for.delta)
=. cor
(emit (act:cu-pass for.delta club-eq %init [team hive met]:club))
:: TODO include inviter's name in message? requires rework of
:: notice messages though :(
(cu-post-notice for.delta '' ' was invited to the chat')
?. (~(has in hive.club) for.delta)
cu-core
=. hive.club (~(del in hive.club) for.delta)
(cu-post-notice for.delta '' ' was uninvited from the chat')
==
::
++ cu-peek
|= =path
^- (unit (unit cage))
?+ path [~ ~]
[%writs *] (peek:cu-pact t.path)
[%crew ~] ``club-crew+!>(+.club)
==
::
++ cu-watch
|= =path
^+ cu-core
?> =(src our):bowl
?+ path !!
[%ui ~] cu-core
[%ui %writs ~] cu-core
==
::
++ cu-agent
|= [=wire =sign:agent:gall]
^+ cu-core
?+ wire ~|(bad-club-take/wire !!)
[%gossip ~]
?> ?=(%poke-ack -.sign)
?~ p.sign cu-core
:: TODO: handle?
%- (slog leaf/"Failed to gossip {<src.bowl>} {<id>}" u.p.sign)
cu-core
==
::
--
::
++ ca-core
|_ [=flag:c =chat:c gone=_|]
+* ca-pact ~(. pac pact.chat)
++ ca-core .
:: TODO: archive??
++ ca-abet
%_ cor
chats
?:(gone (~(del by chats) flag) (~(put by chats) flag chat))
==
++ ca-abed
|= f=flag:c
ca-core(flag f, chat (~(got by chats) f))
++ ca-area `path`/chat/(scot %p p.flag)/[q.flag]
++ ca-spin
|= [rest=path con=(list content:ha) but=(unit button:ha)]
=* group group.perm.chat
=/ =nest:g [dap.bowl flag]
=/ rope [`group `nest q.byk.bowl (welp /(scot %p p.flag)/[q.flag] rest)]
=/ link
(welp /groups/(scot %p p.group)/[q.group]/channels/chat/(scot %p p.flag)/[q.flag] rest)
(spin rope con link but)
::
++ ca-watch
|= =(pole knot)
^+ ca-core
?+ pole !!
[%updates rest=*] (ca-pub rest.pole)
[%ui ~] ?>(from-self ca-core)
[%ui %writs ~] ?>(from-self ca-core)
::
[%said ship=@ time=@ *]
=/ =ship (slav %p ship.pole)
=/ =time (slav %ud time.pole)
(ca-said ship time)
::
==
::
++ ca-said
|= =id:c
|^ ^+ ca-core
?. (ca-can-read src.bowl)
(give-kick chat-denied+!>(~))
=/ [=time =writ:c] (got:ca-pact id)
%+ give-kick %chat-said
!> ^- said:c
[flag writ]
++ give-kick
|= =cage
=. cor (give %fact ~ cage)
=. cor (give %kick ~ ~)
ca-core
--
++ ca-pass
|%
++ add-channel
|= req=create:c
=/ =dock [p.group.req %groups]
=/ =nest:g [dap.bowl flag]
=/ =channel:g
=,(req [[title description '' ''] now.bowl %default | readers])
=/ =action:g [group.req now.bowl %channel nest %add channel]
=/ =cage group-action+!>(action)
=/ =wire (snoc ca-area %create)
=/ =card
[%pass ca-area %agent dock %poke cage]
=. cor
(emit card)
ca-core
::
--
++ ca-init
|= req=create:c
=/ =perm:c [writers.req group.req]
=. cor
(give-brief flag/flag ca-brief)
=. ca-core (ca-update now.bowl %create perm ~)
(add-channel:ca-pass req)
::
++ ca-agent
|= [=(pole knot) =sign:agent:gall]
^+ ca-core
?+ pole !!
~ :: noop wire, should only send pokes
ca-core
::
[%updates ~]
(ca-take-update sign)
::
[%create ~]
?> ?=(%poke-ack -.sign)
%. ca-core :: TODO rollback creation if poke fails?
?~ p.sign same
(slog leaf/"poke failed" u.p.sign)
::
==
::
++ ca-brief (brief:ca-pact our.bowl last-read.remark.chat)
::
++ ca-peek
|= =(pole knot)
^- (unit (unit cage))
?+ pole [~ ~]
[%writs rest=*] (peek:ca-pact rest.pole)
[%perm ~] ``chat-perm+!>(perm.chat)
==
::
++ ca-revoke
|= her=ship
%+ roll ~(tap in ca-subscriptions)
|= [[=ship =path] ca=_ca-core]
?. =(ship her) ca
ca(cor (emit %give %kick ~[path] `ship))
::
++ ca-recheck
%+ roll ~(tap in ca-subscriptions)
|= [[=ship =path] ca=_ca-core]
?: (ca-can-read:ca ship) ca
ca(cor (emit %give %kick ~[path] `ship))
::
++ ca-take-update
|= =sign:agent:gall
^+ ca-core
?+ -.sign ca-core
%kick
?> ?=(%sub -.net.chat)
?- -.saga.net.chat
%chi ca-sub
%dex ca-core
%lev ca-core
==
::
%watch-ack
=. net.chat [%sub src.bowl %chi ~]
?~ p.sign ca-core
%- (slog leaf/"Failed subscription" u.p.sign)
=. gone &
ca-core
::
%fact
=* cage cage.sign
?+ p.cage ca-core
%epic (ca-take-epic !<(epic:e q.cage))
?(%chat-logs %chat-logs-0) (ca-apply-logs !<(logs:c q.cage))
?(%chat-update %chat-update-0) (ca-update !<(update:c q.cage))
==
==
::
++ ca-take-epic
|= her=epic:e
^+ ca-core
?> ?=(%sub -.net.chat)
?: =(her okay)
ca-core
?: (gth her okay)