1
0
Fork 0
mirror of https://code.sup39.dev/repos/Wqawg synced 2024-12-27 15:14:50 +09:00

C2S: Support following a sharer-patch and repo-patch

This commit is contained in:
fr33domlover 2020-05-28 07:48:39 +00:00
parent 3fb529325d
commit 854d35fd9b

View file

@ -787,9 +787,11 @@ createTicketC (Entity pidUser personUser) sharerUser summary audience ticket muT
data Followee data Followee
= FolloweeSharer ShrIdent = FolloweeSharer ShrIdent
| FolloweeSharerTicket ShrIdent (KeyHashid TicketAuthorLocal) | FolloweeSharerTicket ShrIdent (KeyHashid TicketAuthorLocal)
| FolloweeSharerPatch ShrIdent (KeyHashid TicketAuthorLocal)
| FolloweeProject ShrIdent PrjIdent | FolloweeProject ShrIdent PrjIdent
| FolloweeProjectTicket ShrIdent PrjIdent (KeyHashid LocalTicket) | FolloweeProjectTicket ShrIdent PrjIdent (KeyHashid LocalTicket)
| FolloweeRepo ShrIdent RpIdent | FolloweeRepo ShrIdent RpIdent
| FolloweeRepoPatch ShrIdent RpIdent (KeyHashid LocalTicket)
followC followC
:: ShrIdent :: ShrIdent
@ -849,16 +851,20 @@ followC shrUser summary audience follow@(AP.Follow uObject muContext hide) = run
where where
parseFollowee (SharerR shr) = Just $ FolloweeSharer shr parseFollowee (SharerR shr) = Just $ FolloweeSharer shr
parseFollowee (SharerTicketR shr khid) = Just $ FolloweeSharerTicket shr khid parseFollowee (SharerTicketR shr khid) = Just $ FolloweeSharerTicket shr khid
parseFollowee (SharerPatchR shr khid) = Just $ FolloweeSharerPatch shr khid
parseFollowee (ProjectR shr prj) = Just $ FolloweeProject shr prj parseFollowee (ProjectR shr prj) = Just $ FolloweeProject shr prj
parseFollowee (ProjectTicketR shr prj num) = Just $ FolloweeProjectTicket shr prj num parseFollowee (ProjectTicketR shr prj num) = Just $ FolloweeProjectTicket shr prj num
parseFollowee (RepoR shr rp) = Just $ FolloweeRepo shr rp parseFollowee (RepoR shr rp) = Just $ FolloweeRepo shr rp
parseFollowee (RepoPatchR shr rp khid) = Just $ FolloweeRepoPatch shr rp khid
parseFollowee _ = Nothing parseFollowee _ = Nothing
followeeActor (FolloweeSharer shr) = LocalActorSharer shr followeeActor (FolloweeSharer shr) = LocalActorSharer shr
followeeActor (FolloweeSharerTicket shr _) = LocalActorSharer shr followeeActor (FolloweeSharerTicket shr _) = LocalActorSharer shr
followeeActor (FolloweeSharerPatch shr _) = LocalActorSharer shr
followeeActor (FolloweeProject shr prj) = LocalActorProject shr prj followeeActor (FolloweeProject shr prj) = LocalActorProject shr prj
followeeActor (FolloweeProjectTicket shr prj _) = LocalActorProject shr prj followeeActor (FolloweeProjectTicket shr prj _) = LocalActorProject shr prj
followeeActor (FolloweeRepo shr rp) = LocalActorRepo shr rp followeeActor (FolloweeRepo shr rp) = LocalActorRepo shr rp
followeeActor (FolloweeRepoPatch shr rp _) = LocalActorRepo shr rp
getAuthor shr = do getAuthor shr = do
sid <- getKeyBy404 $ UniqueSharer shr sid <- getKeyBy404 $ UniqueSharer shr
@ -877,17 +883,20 @@ followC shrUser summary audience follow@(AP.Follow uObject muContext hide) = run
Left person -> return (personFollowers person, personInbox person, True, personOutbox person) Left person -> return (personFollowers person, personInbox person, True, personOutbox person)
Right _group -> throwE "Follow object is a group" Right _group -> throwE "Follow object is a group"
getFollowee (FolloweeSharerTicket shr talkhid) = do getFollowee (FolloweeSharerTicket shr talkhid) = do
mfollowee <- lift $ runMaybeT $ do (Entity _ tal, Entity _ lt, _, _) <- do
sid <- MaybeT $ getKeyBy $ UniqueSharer shr mticket <- lift $ runMaybeT $ do
Entity pid p <- MaybeT $ getBy $ UniquePersonIdent sid talid <- decodeKeyHashidM talkhid
talid <- decodeKeyHashidM talkhid MaybeT $ getSharerTicket shr talid
tal <- MaybeT $ get talid fromMaybeE mticket "Follow object: No such sharer-ticket in DB"
guard $ ticketAuthorLocalAuthor tal == pid p <- lift $ getJust $ ticketAuthorLocalAuthor tal
mtup <- lift $ getBy $ UniqueTicketUnderProjectAuthor talid return (localTicketFollowers lt, personInbox p, True, personOutbox p)
guard $ isNothing mtup getFollowee (FolloweeSharerPatch shr talkhid) = do
lt <- lift $ getJust $ ticketAuthorLocalTicket tal (Entity _ tal, Entity _ lt, _, _, _) <- do
return (lt, p) mticket <- lift $ runMaybeT $ do
(lt, p) <- fromMaybeE mfollowee "Follow object: No such sharer ticket in DB" talid <- decodeKeyHashidM talkhid
MaybeT $ getSharerPatch shr talid
fromMaybeE mticket "Follow object: No such sharer-patch in DB"
p <- lift $ getJust $ ticketAuthorLocalAuthor tal
return (localTicketFollowers lt, personInbox p, True, personOutbox p) return (localTicketFollowers lt, personInbox p, True, personOutbox p)
getFollowee (FolloweeProject shr prj) = do getFollowee (FolloweeProject shr prj) = do
mproject <- lift $ runMaybeT $ do mproject <- lift $ runMaybeT $ do
@ -896,25 +905,25 @@ followC shrUser summary audience follow@(AP.Follow uObject muContext hide) = run
project <- fromMaybeE mproject "Follow object: No such project in DB" project <- fromMaybeE mproject "Follow object: No such project in DB"
return (projectFollowers project, projectInbox project, False, projectOutbox project) return (projectFollowers project, projectInbox project, False, projectOutbox project)
getFollowee (FolloweeProjectTicket shr prj ltkhid) = do getFollowee (FolloweeProjectTicket shr prj ltkhid) = do
mproject <- lift $ runMaybeT $ do (_, Entity _ j, _, Entity _ lt, _, _, _) <- do
sid <- MaybeT $ getKeyBy $ UniqueSharer shr mticket <- lift $ runMaybeT $ do
Entity jid project <- MaybeT $ getBy $ UniqueProject prj sid ltid <- decodeKeyHashidM ltkhid
ltid <- decodeKeyHashidM ltkhid MaybeT $ getProjectTicket shr prj ltid
lticket <- MaybeT $ get ltid fromMaybeE mticket "Follow object: No such project-ticket in DB"
tclid <- return (localTicketFollowers lt, projectInbox j, False, projectOutbox j)
MaybeT $ getKeyBy $
UniqueTicketContextLocal $ localTicketTicket lticket
tpl <- MaybeT $ getValBy $ UniqueTicketProjectLocal tclid
guard $ ticketProjectLocalProject tpl == jid
return (lticket, project)
(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 getFollowee (FolloweeRepo shr rp) = do
mrepo <- lift $ runMaybeT $ do mrepo <- lift $ runMaybeT $ do
sid <- MaybeT $ getKeyBy $ UniqueSharer shr sid <- MaybeT $ getKeyBy $ UniqueSharer shr
MaybeT $ getValBy $ UniqueRepo rp sid MaybeT $ getValBy $ UniqueRepo rp sid
repo <- fromMaybeE mrepo "Follow object: No such repo in DB" repo <- fromMaybeE mrepo "Follow object: No such repo in DB"
return (repoFollowers repo, repoInbox repo, False, repoOutbox repo) return (repoFollowers repo, repoInbox repo, False, repoOutbox repo)
getFollowee (FolloweeRepoPatch shr rp ltkhid) = do
(_, Entity _ r, _, Entity _ lt, _, _, _, _) <- do
mticket <- lift $ runMaybeT $ do
ltid <- decodeKeyHashidM ltkhid
MaybeT $ getRepoPatch shr rp ltid
fromMaybeE mticket "Follow object: No such repo-patch in DB"
return (localTicketFollowers lt, repoInbox r, False, repoOutbox r)
insertFollowToOutbox obid = do insertFollowToOutbox obid = do
hLocal <- asksSite siteInstanceHost hLocal <- asksSite siteInstanceHost