From 9cf887d1f1e0f10b6740c880b50219b0c172e7a2 Mon Sep 17 00:00:00 2001
From: ~midsum-salrux <nathan@tlon.io>
Date: Fri, 10 Feb 2023 15:19:08 -0500
Subject: [PATCH] Working migration

---
 pkg/landscape/app/group-store.hoon |  3 +-
 pkg/landscape/lib/gladio.hoon      | 67 ++++++++++++++++--------------
 2 files changed, 37 insertions(+), 33 deletions(-)

diff --git a/pkg/landscape/app/group-store.hoon b/pkg/landscape/app/group-store.hoon
index f19089dc0..ae1cbb49c 100644
--- a/pkg/landscape/app/group-store.hoon
+++ b/pkg/landscape/app/group-store.hoon
@@ -305,7 +305,8 @@
   [cards state(wait wait)]
 ++  poke-migrate-my-channels
   ^-  (quip card _state)
-  [~(migrate-my-channels gladio bol) state]
+  =/  [cards=(list card) *]  (~(migrate-my-channels gladio bol) ~)
+  [cards state]
 ::
 ++  watch-init-migrate
   |=  =ship
diff --git a/pkg/landscape/lib/gladio.hoon b/pkg/landscape/lib/gladio.hoon
index 45d81529f..42787c440 100644
--- a/pkg/landscape/lib/gladio.hoon
+++ b/pkg/landscape/lib/gladio.hoon
@@ -55,8 +55,6 @@
   ?~  group=(~(get by groups) group.u.assoc)
     ~&  missing-group/[flag group.u.assoc]
     ~
-  ?:  hidden.u.group
-    ~
   =/  writers=(set ship)  
     (~(get ju tags.u.group) %graph flag %writers)
   ?~  log=(~(get by update-logs.network) flag)
@@ -176,70 +174,75 @@
     (welp setup (zing (turn ~(tap in (~(del in ships) our.bowl)) migrate-ship)))
   [setup (~(uni in ships) wait)]
 ++  migrate-my-channels
+  |=  wait=(set ship)
+  ^-  (quip card (set ship))
   =+  network
   =+  groups
-  =/  associations  my-channels-associations
-  =/  ships   (peers network)
-  =/  dms  (~(get by graphs:network) [our.bowl %dm-inbox])
-  =/  import  (import-for-mark `our.bowl groups associations network)
-  =/  clubs  (import-club groups associations network)
+  =+  associations
+  =/  =flag:i  [our.bowl %my-channels]
+  =/  ships  (peers network)
+  =/  import  (import-for-mark `our.bowl groups my-channels-associations network)
   =/  chats=imports:graph:i
     (import %graph-validator-chat)
   =/  diarys=imports:graph:i
     (import %graph-validator-publish)
   =/  links=imports:graph:i
     (import %graph-validator-link)
-  =/  =imports:groups:i
+  =|  assoc=association:met
+  =/  hoops=imports:groups:i
     %-  ~(gas by *imports:groups:i)
     %+  murn  ~(tap by groups)
     |=  [=flag:i =group]
     ^-  (unit [_flag import:groups:i])
-    ?:  hidden.group
-      ~
-    ?~  assoc=(~(get by associations) [%groups flag])
-      ~&  missing-group-assoc/flag
-      ~
+    =/  nass=(unit association:met)
+      ?^  (~(get by associations) [%groups flag])  ~
+      `assoc(hidden.metadatum |, title.metadatum 'My Channels', creator.metadatum p.flag, group [our.bowl %my-channels])
+    ?~  nass  ~
     =/  chans=(map flag:i association:met)
       %-  ~(gas by *(map flag:i association:met))
       %+  murn  ~(tap by associations)
       |=  [res=md-resource:met ass=association:met]
       ^-  (unit [flag:i association:met])
       ?.  =(group.ass flag)  ~
+      ?.  =(entity.group.ass our.bowl)  ~
       `[resource.res ass]
     =/  roles=(set flag:i)
       %-  ~(gas in *(set flag:i))
       %+  murn  ~(tap by chans)
       |=  [=flag:i =association:met]
       ^-  (unit flag:i)
+      ?.  =(group.association flag)  ~
+      ?.  =(entity.group.association our.bowl)  ~
       ?^  link=(~(get by links) flag)
         ?:  =(writers.u.link ~)  ~
         `flag
-      ?^  diary=(~(get by diarys) flag)
+      ?^  diary=(~(get by links) flag)
         ?:  =(writers.u.diary ~)  ~
         `flag
       ?^  chat=(~(get by chats) flag)
         ?:  =(writers.u.chat ~)  ~
         `flag
       ~
-    `[flag u.assoc chans roles group]
-  =/  dms  (~(get by graphs:network) [our.bowl %dm-inbox])
-  =/  flag-importer  (import-flags our.bowl groups associations network)
-  =+  :*  chat-flags=(flag-importer %graph-validator-chat)
-          heap-flags=(flag-importer %graph-validator-link)
-          diary-flags=(flag-importer %graph-validator-publish)
-      ==
-  =/  setup=(list card)
-    %+  welp  (migrate-ship our.bowl)
-    :*  (poke-our %groups group-import+!>(imports))
-        (poke-our %chat import-flags+!>(chat-flags))
-        (poke-our %heap import-flags+!>(heap-flags))
-        (poke-our %diary import-flags+!>(diary-flags))
-        (poke-our %chat club-imports+!>(clubs))
-        ?~  dms  ~
-        (poke-our %chat dm-imports+!>(p.u.dms))^~
+    ?~  chans  ~
+    `[flag u.nass chans roles group]
+  =/  bigport=import:groups:i
+    %+  roll  ~(val by hoops)
+    |=  [port=import:groups:i newport=import:groups:i]
+    ^-  import:groups:i
+    ::  they should have the same association and group already
+    :*  association.port
+        (~(uni by chans.port) chans.newport)
+        (~(uni by roles.port) roles.newport)
+        group.port
     ==
-  setup
-::
+  =/  mychan-import=imports:groups:i
+    (~(put by *imports:groups:i) [our.bowl %my-channels] bigport)
+  :_  ~
+  :~  (poke-our %groups group-import+!>(mychan-import))
+      (poke-our %chat graph-imports+!>(chats))
+      (poke-our %heap graph-imports+!>(links))
+      (poke-our %diary graph-imports+!>(diarys))
+  ==
 ++  migrate-ship
   |=  her=ship
   ^-  (list card)