diff --git a/src/Vervis/Actor/Person.hs b/src/Vervis/Actor/Person.hs index 01e14e0..aba6886 100644 --- a/src/Vervis/Actor/Person.hs +++ b/src/Vervis/Actor/Person.hs @@ -63,6 +63,7 @@ import Vervis.Data.Actor import Vervis.Data.Collab import Vervis.Data.Discussion import Vervis.Data.Follow +import Vervis.Data.Ticket import Vervis.FedURI import Vervis.Federation.Util import Vervis.Foundation @@ -74,6 +75,43 @@ import Vervis.Persist.Discussion import Vervis.Persist.Follow import Vervis.Ticket +-- Meaning: Someone is offering a ticket or dependency to a tracker +-- Behavior: +-- * Insert to my inbox +personOffer + :: UTCTime + -> PersonId + -> Verse + -> AP.Offer URIMode + -> ActE (Text, Act (), Next) +personOffer now recipPersonID (Verse authorIdMsig body) (AP.Offer object uTarget) = do + + -- Check input + ticket <- + case object of + AP.OfferTicket t -> pure t + _ -> throwE "Unsupported Offer.object type" + ObjURI hAuthor _ <- lift $ getActorURI authorIdMsig + let author = bimap (view _1) (remoteAuthorURI . view _1) authorIdMsig + WorkItemOffer {..} <- checkOfferTicket hAuthor ticket uTarget + unless (bimap LocalActorPerson id wioAuthor == author) $ + throwE "Offering a Ticket attributed to someone else" + + maybeNew <- withDBExcept $ do + + -- Grab me from DB + (personRecip, actorRecip) <- lift $ do + p <- getJust recipPersonID + (p,) <$> getJust (personActor p) + + maybeOfferDB <- lift $ insertToInbox now authorIdMsig body (actorInbox actorRecip) True + for maybeOfferDB $ \ _offerDB -> + return $ personActor personRecip + + case maybeNew of + Nothing -> done "I already have this activity in my inbox" + Just _actorID -> done "Inserted this Offer to my inbox" + ------------------------------------------------------------------------------ -- Following ------------------------------------------------------------------------------ @@ -684,6 +722,7 @@ personBehavior now personID (Left verse@(Verse _authorIdMsig body)) = AP.GrantActivity grant -> personGrant now personID verse grant AP.InviteActivity invite -> personInvite now personID verse invite AP.JoinActivity join -> personJoin now personID verse join + AP.OfferActivity offer -> personOffer now personID verse offer AP.RejectActivity reject -> personReject now personID verse reject AP.RemoveActivity remove -> personRemove now personID verse remove AP.RevokeActivity revoke -> personRevoke now personID verse revoke