diff --git a/src/Vervis/Actor/Group.hs b/src/Vervis/Actor/Group.hs index 3a17068..6b5ac5f 100644 --- a/src/Vervis/Actor/Group.hs +++ b/src/Vervis/Actor/Group.hs @@ -873,53 +873,52 @@ groupAdd now groupID (Verse authorIdMsig body) add = do -- * To: Join sender -- * CC: Accept sender, Join sender's followers, my followers -- --- * Give me a new child active SourceOriginUs --- * Verify we haven't yet seen child's Accept +-- * Give me a new parent active SourceOriginUs +-- * Verify we haven't yet seen parent's Accept -- * Insert the Accept to my inbox --- * If sender is the child, record the Accept into the Source record +-- * If sender is the parent, record the Accept into the Source record -- * Prepare to send degelator-Grant -- * Otherwise nothing to do -- * Forward the Accept to my followers -- * Possibly send a Grant: --- * Child-active --- * If sender is the child +-- * If sender is the parent -- * delegator-Grant --- * To: Child +-- * To: Parent -- * CC: --- - Child's followers +-- - Parent's followers -- - My followers -- --- * Give me a new child passive SourceOriginThem --- * Option 1: We haven't seen child's Accept yet --- * Verify sender is the child +-- * Give me a new parent passive SourceOriginThem +-- * Option 1: We haven't seen parent's Accept yet +-- * Verify sender is the parent -- * Option 2: We saw it, but not my collaborator's Accept -- * Verify the Accept is authorized -- * Otherwise respond with error, no Accept is needed -- * Insert the Accept to my inbox --- * Option 1: Record child's Accept in Source record +-- * Option 1: Record parent's Accept in Source record -- * Option 2: Record my collaborator's Accept -- * Prepare to send delegator-Grant -- * Forward the Accept to my followers -- * Possibly send a Grant: -- * In option 2 -- * delegator-Grant --- * To: Child +-- * To: Parent -- * CC: --- - Child's followers +-- - Parent's followers -- - My followers -- - The Accept sender (my collaborator) -- --- * Give me a new parent active DestOriginUs +-- * Give me a new child active DestOriginUs -- * Respond with error, we aren't supposed to get any Accept -- --- * Give me a new parent passive DestOriginThem --- * Option 1: I haven't yet seen parent's Accept --- * Verify sender is the parent +-- * Give me a new child passive DestOriginThem +-- * Option 1: I haven't yet seen child's Accept +-- * Verify sender is the child -- * Option 2: I saw it, but not my collaborator's Accept -- * Verify the accept is authorized -- * Otherwise respond with error, no Accept is needed -- * Insert the Accept to my inbox --- * Option 1: Record parent's Accept in the Dest record +-- * Option 1: Record child's Accept in the Dest record -- * Option 2: Record my collaborator's Accept in the Dest record -- * Prepare to send my own Accept -- * Forward the Accept to my followers @@ -927,9 +926,9 @@ groupAdd now groupID (Verse authorIdMsig body) add = do -- * In option 2 -- * Object: The Add -- * Fulfills: My collaborator's Accept --- * To: Parent +-- * To: Child -- * CC: --- - Parent's followers +-- - Child's followers -- - My followers -- - The Accept sender (my collaborator) -- @@ -1289,43 +1288,41 @@ groupAccept now groupID (Verse authorIdMsig body) accept = do doneDB inboxItemID "[Collab mode] Forwarded the Accept and published a Grant" -- Add-a-parent mode - -- Comments below might refer to child, because code is ported from Project - -- But this is add-a-new-parent mode! addChildParent (Left (sourceID, topic, mode)) = do mode' <- bitraverse - -- Child-active mode - -- Verify we haven't yet seen child's Accept + -- Parent-active mode + -- Verify we haven't yet seen parent's Accept (\ () -> do - maybeChildAccept <- + maybeParentAccept <- lift $ withDB $ case bimap fst fst topic of Left localID -> (() <$) <$> getBy (UniqueSourceThemAcceptLocal localID) Right remoteID -> (() <$) <$> getBy (UniqueSourceThemAcceptRemote remoteID) - verifyNothingE maybeChildAccept "I already saw child's Accept" + verifyNothingE maybeParentAccept "I already saw parent's Accept" ) - -- Child-passive mode - -- Option 1: We haven't seen child's Accept yet - -- * Verify sender is the child + -- Parent-passive mode + -- Option 1: We haven't seen parent's Accept yet + -- * Verify sender is the parent -- Option 2: We saw it, but not my collaborator's Accept -- * Verify the Accept is authorized -- Otherwise respond with error, no Accept is needed (\ () -> do - (maybeChildAccept, maybeGrant) <- + (maybeParentAccept, maybeGrant) <- lift $ withDB $ liftA2 (,) (case bimap fst fst topic of Left localID -> (() <$) <$> getBy (UniqueSourceThemAcceptLocal localID) Right remoteID -> (() <$) <$> getBy (UniqueSourceThemAcceptRemote remoteID) ) (getBy $ UniqueSourceUsSendDelegator sourceID) - case (isJust maybeChildAccept, isJust maybeGrant) of - (False, True) -> error "Impossible/bug, didn't see child's Accept but sent a Grant" + case (isJust maybeParentAccept, isJust maybeGrant) of + (False, True) -> error "Impossible/bug, didn't see parent's Accept but sent a Grant" (False, False) -> do unless (theyIsAuthor topic) $ - throwE "The Accept I'm waiting for is from my new child" + throwE "The Accept I'm waiting for is from my new parent" return $ Left () (True, False) -> do let muCap = AP.activityCapability $ actbActivity body @@ -1336,7 +1333,7 @@ groupAccept now groupID (Verse authorIdMsig body) accept = do (LocalResourceGroup groupID) AP.RoleAdmin return $ Right () - (True, True) -> throwE "Child already enabled, not needing any further Accept" + (True, True) -> throwE "Parent already enabled, not needing any further Accept" ) mode @@ -1356,8 +1353,8 @@ groupAccept now groupID (Verse authorIdMsig body) accept = do lift $ bitraverse - -- Child-active mode - -- If sender is child, record the Accept into the + -- Parent-active mode + -- If sender is parent, record the Accept into the -- Source record & prepare to send degelator-Grant -- Othrerwise do nothing (\ () -> @@ -1375,11 +1372,11 @@ groupAccept now groupID (Verse authorIdMsig body) accept = do else pure Nothing ) - -- Child-passive mode + -- Parent-passive mode (\case - -- Getting an Accept from the child - -- Record child's Accept in Source record + -- Getting an Accept from the parent + -- Record parent's Accept in Source record Left () -> do case (topic, acceptDB) of (Left (localID, _), Left (_, _, acceptID)) -> @@ -1444,25 +1441,23 @@ groupAccept now groupID (Verse authorIdMsig body) accept = do doneDB inboxItemID "[Parent mode] Forwarded the Accept and maybe published a Grant/Accept" -- Add-a-child mode - -- Comments below might refer to parent, because code is ported from Project - -- But this is add-a-new-child mode! addChildParent (Right (destID, topic, mode)) = do (themID, mode') <- case mode of - -- Parent-active mode + -- Child-active mode -- Respond with error, we aren't supposed to get any Accept - Left () -> throwE "Parent-active (DestOriginUs) mode, I'm not expecting any Accept" + Left () -> throwE "Child-active (DestOriginUs) mode, I'm not expecting any Accept" - -- Parent-passive mode - -- Option 1: I haven't yet seen parent's Accept - -- * Verify sender is the parent + -- Child-passive mode + -- Option 1: I haven't yet seen child's Accept + -- * Verify sender is the child -- Option 2: I saw it, but not my collaborator's Accept -- * Verify the accept is authorized -- Otherwise respond with error, no Accept is needed Right themID -> (themID,) <$> do - (maybeParentAccept, maybeUsGesture) <- + (maybeChildAccept, maybeUsGesture) <- lift $ withDB $ liftA2 (,) (case bimap fst fst topic of Left localID -> (() <$) <$> getBy (UniqueDestThemAcceptLocalTopic localID) @@ -1476,11 +1471,11 @@ groupAccept now groupID (Verse authorIdMsig body) accept = do (True, False) -> pure $ Just () (True, True) -> error "Both DestUsGestureLocal and DestUsGestureRemote" ) - case (isJust maybeParentAccept, isJust maybeUsGesture) of - (False, True) -> error "Impossible/bug, didn't see parent's Accept but recorded my collaborator's Accept" + case (isJust maybeChildAccept, isJust maybeUsGesture) of + (False, True) -> error "Impossible/bug, didn't see child's Accept but recorded my collaborator's Accept" (False, False) -> do unless (theyIsAuthor topic) $ - throwE "The Accept I'm waiting for is from my new parent" + throwE "The Accept I'm waiting for is from my new child" return $ Left () (True, False) -> do let muCap = AP.activityCapability $ actbActivity body @@ -1491,7 +1486,7 @@ groupAccept now groupID (Verse authorIdMsig body) accept = do (LocalResourceGroup groupID) AP.RoleAdmin return $ Right () - (True, True) -> throwE "Just waiting for Grant from parent, or already have it, anyway not needing any further Accept" + (True, True) -> throwE "Just waiting for Grant from child, or already have it, anyway not needing any further Accept" maybeNew <- withDBExcept $ do @@ -1507,8 +1502,8 @@ groupAccept now groupID (Verse authorIdMsig body) accept = do idsForGrant <- lift $ case mode' of - -- Getting an Accept from the parent - -- Record parent's Accept in the Dest record + -- Getting an Accept from the child + -- Record child's Accept in the Dest record Left () -> do case (topic, acceptDB) of (Left (localID, _), Left (_, _, acceptID)) ->