From f4ab99f7bb3dba98c214c4de4be6fc2741357eba Mon Sep 17 00:00:00 2001 From: fr33domlover Date: Thu, 9 Apr 2020 20:04:21 +0000 Subject: [PATCH] C2S: In Follow handler, support following sharer-hosted tickets --- src/Vervis/API.hs | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/Vervis/API.hs b/src/Vervis/API.hs index 31acd6f..e928b86 100644 --- a/src/Vervis/API.hs +++ b/src/Vervis/API.hs @@ -719,8 +719,9 @@ createTicketC (Entity pidUser personUser) sharerUser summary audience ticket muT data Followee = FolloweeSharer ShrIdent + | FolloweeSharerTicket ShrIdent (KeyHashid TicketAuthorLocal) | FolloweeProject ShrIdent PrjIdent - | FolloweeTicket ShrIdent PrjIdent (KeyHashid LocalTicket) + | FolloweeProjectTicket ShrIdent PrjIdent (KeyHashid LocalTicket) | FolloweeRepo ShrIdent RpIdent followC @@ -781,15 +782,17 @@ followC shrUser summary audience follow@(AP.Follow uObject muContext hide) = run return obiidFollow where parseFollowee (SharerR shr) = Just $ FolloweeSharer shr + parseFollowee (SharerTicketR shr khid) = Just $ FolloweeSharerTicket shr khid parseFollowee (ProjectR shr prj) = Just $ FolloweeProject shr prj - parseFollowee (ProjectTicketR shr prj num) = Just $ FolloweeTicket shr prj num + parseFollowee (ProjectTicketR shr prj num) = Just $ FolloweeProjectTicket shr prj num parseFollowee (RepoR shr rp) = Just $ FolloweeRepo shr rp parseFollowee _ = Nothing - followeeActor (FolloweeSharer shr) = LocalActorSharer shr - followeeActor (FolloweeProject shr prj) = LocalActorProject shr prj - followeeActor (FolloweeTicket shr prj _) = LocalActorProject shr prj - followeeActor (FolloweeRepo shr rp) = LocalActorRepo shr rp + followeeActor (FolloweeSharer shr) = LocalActorSharer shr + followeeActor (FolloweeSharerTicket shr _) = LocalActorSharer shr + followeeActor (FolloweeProject shr prj) = LocalActorProject shr prj + followeeActor (FolloweeProjectTicket shr prj _) = LocalActorProject shr prj + followeeActor (FolloweeRepo shr rp) = LocalActorRepo shr rp getAuthor shr = do sid <- getKeyBy404 $ UniqueSharer shr @@ -807,13 +810,26 @@ followC shrUser summary audience follow@(AP.Follow uObject muContext hide) = run case val of Left person -> return (personFollowers person, personInbox person, True, personOutbox person) Right _group -> throwE "Follow object is a group" + getFollowee (FolloweeSharerTicket shr talkhid) = do + mfollowee <- lift $ runMaybeT $ do + sid <- MaybeT $ getKeyBy $ UniqueSharer shr + Entity pid p <- MaybeT $ getBy $ UniquePersonIdent sid + talid <- decodeKeyHashidM talkhid + tal <- MaybeT $ get talid + guard $ ticketAuthorLocalAuthor tal == pid + mtup <- lift $ getBy $ UniqueTicketUnderProjectAuthor talid + guard $ isNothing mtup + lt <- lift $ getJust $ ticketAuthorLocalTicket tal + return (lt, p) + (lt, p) <- fromMaybeE mfollowee "Follow object: No such sharer ticket in DB" + return (localTicketFollowers lt, personInbox p, True, personOutbox p) getFollowee (FolloweeProject shr prj) = do mproject <- lift $ runMaybeT $ do sid <- MaybeT $ getKeyBy $ UniqueSharer shr MaybeT $ getValBy $ UniqueProject prj sid project <- fromMaybeE mproject "Follow object: No such project in DB" return (projectFollowers project, projectInbox project, False, projectOutbox project) - getFollowee (FolloweeTicket shr prj ltkhid) = do + getFollowee (FolloweeProjectTicket shr prj ltkhid) = do mproject <- lift $ runMaybeT $ do sid <- MaybeT $ getKeyBy $ UniqueSharer shr Entity jid project <- MaybeT $ getBy $ UniqueProject prj sid @@ -824,7 +840,7 @@ followC shrUser summary audience follow@(AP.Follow uObject muContext hide) = run UniqueTicketProjectLocal $ localTicketTicket lticket guard $ ticketProjectLocalProject tpl == jid return (lticket, project) - (lticket, project) <- fromMaybeE mproject "Follow object: No such ticket in DB" + (lticket, project) <- fromMaybeE mproject "Follow object: No such project ticket in DB" return (localTicketFollowers lticket, projectInbox project, False, projectOutbox project) getFollowee (FolloweeRepo shr rp) = do mrepo <- lift $ runMaybeT $ do