mirror of
https://code.sup39.dev/repos/Wqawg
synced 2024-12-27 03:54:51 +09:00
Person: Port Reject{Follow} handler
This commit is contained in:
parent
9b0622cd7a
commit
552ef760e6
2 changed files with 63 additions and 1 deletions
|
@ -230,7 +230,7 @@ personAccept
|
|||
-> LocalURI
|
||||
-> AP.Accept URIMode
|
||||
-> ActE (Text, Act (), Next)
|
||||
personAccept now recipPersonID author body mfwd luAccept accept = do
|
||||
personAccept now recipPersonID author body _mfwd luAccept accept = do
|
||||
|
||||
-- Check input
|
||||
acceptee <- parseAccept accept
|
||||
|
@ -280,6 +280,61 @@ personAccept now recipPersonID author body mfwd luAccept accept = do
|
|||
}
|
||||
tryFollow _ (Right _) _ = mzero
|
||||
|
||||
-- Meaning: A remote actor rejected something
|
||||
-- Behavior:
|
||||
-- * Insert to my inbox
|
||||
-- * If it's a Follow I sent to them, remove record from my DB
|
||||
personReject
|
||||
:: UTCTime
|
||||
-> PersonId
|
||||
-> RemoteAuthor
|
||||
-> ActivityBody
|
||||
-> Maybe (RecipientRoutes, ByteString)
|
||||
-> LocalURI
|
||||
-> AP.Reject URIMode
|
||||
-> ActE (Text, Act (), Next)
|
||||
personReject now recipPersonID author body _mfwd luReject reject = do
|
||||
|
||||
-- Check input
|
||||
rejectee <- parseReject reject
|
||||
|
||||
maybeReject <- withDBExcept $ do
|
||||
|
||||
-- Grab recipient person from DB
|
||||
(personRecip, actorRecip) <- lift $ do
|
||||
p <- getJust recipPersonID
|
||||
(p,) <$> getJust (personActor p)
|
||||
|
||||
mractid <- lift $ insertToInbox now author body (actorInbox actorRecip) luReject True
|
||||
for mractid $ \ rejectID -> runMaybeT $ do
|
||||
|
||||
-- Find the rejected activity in our DB
|
||||
rejecteeDB <- MaybeT $ getActivity rejectee
|
||||
|
||||
tryFollow rejecteeDB
|
||||
|
||||
case maybeReject of
|
||||
Nothing -> done "I already have this activity in my inbox"
|
||||
Just Nothing -> done "Not my Follow; Just inserted to my inbox"
|
||||
Just (Just ()) ->
|
||||
done "Recorded this Reject on the Follow request I sent"
|
||||
|
||||
where
|
||||
|
||||
tryFollow (Left (_, _, outboxItemID)) = do
|
||||
Entity key val <-
|
||||
MaybeT $ lift $
|
||||
getBy $ UniqueFollowRemoteRequestActivity outboxItemID
|
||||
guard $ followRemoteRequestPerson val == recipPersonID
|
||||
let uRecip =
|
||||
fromMaybe
|
||||
(followRemoteRequestTarget val)
|
||||
(followRemoteRequestRecip val)
|
||||
unless (remoteAuthorURI author == uRecip) $
|
||||
lift $ throwE "You're Rejecting a Follow I sent to someone else"
|
||||
lift $ lift $ delete key
|
||||
tryFollow (Right _) = mzero
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- Commenting
|
||||
------------------------------------------------------------------------------
|
||||
|
@ -569,4 +624,6 @@ personBehavior now personID (Right (VerseRemote author body mfwd luActivity)) =
|
|||
AP.UndoActivity undo ->
|
||||
(,Nothing) <$> personUndoA now personID author body mfwd luActivity undo
|
||||
-}
|
||||
AP.RejectActivity reject ->
|
||||
personReject now personID author body mfwd luActivity reject
|
||||
_ -> throwE "Unsupported activity type for Person"
|
||||
|
|
|
@ -25,6 +25,7 @@ module Vervis.Data.Collab
|
|||
, parseJoin
|
||||
, parseGrant
|
||||
, parseAccept
|
||||
, parseReject
|
||||
|
||||
, grantResourceActorID
|
||||
)
|
||||
|
@ -236,6 +237,10 @@ parseAccept (AP.Accept object mresult) = do
|
|||
first (\ (actor, _, item) -> (actor, item)) <$>
|
||||
nameExceptT "Accept object" (parseActivityURI' object)
|
||||
|
||||
parseReject (AP.Reject object) =
|
||||
first (\ (actor, _, item) -> (actor, item)) <$>
|
||||
nameExceptT "Reject object" (parseActivityURI' object)
|
||||
|
||||
grantResourceActorID :: GrantResourceBy Identity -> ActorId
|
||||
grantResourceActorID (GrantResourceRepo (Identity r)) = repoActor r
|
||||
grantResourceActorID (GrantResourceDeck (Identity d)) = deckActor d
|
||||
|
|
Loading…
Reference in a new issue