diff --git a/src/Vervis/Federation/Ticket.hs b/src/Vervis/Federation/Ticket.hs index a168a59..026c501 100644 --- a/src/Vervis/Federation/Ticket.hs +++ b/src/Vervis/Federation/Ticket.hs @@ -454,13 +454,16 @@ sharerCreateTicketF -> ExceptT Text Handler Text sharerCreateTicketF now shrRecip author body mfwd luCreate ticket muTarget = do (targetAndContext, _, _) <- checkCreateTicket author ticket muTarget - runDBExcept $ do + mractid <- runDBExcept $ do ibidRecip <- lift $ do sid <- getKeyBy404 $ UniqueSharer shrRecip - p <- getValBy404 $ UniquePersonIdent sid - return $ personInbox p + personInbox <$> getValBy404 (UniquePersonIdent sid) checkTargetAndContextDB targetAndContext - lift $ insertToInbox luCreate ibidRecip + lift $ insertToInbox now author body ibidRecip luCreate True + return $ + case mractid of + Nothing -> "Activity already exists in my inbox" + Just _ -> "Activity inserted to my inbox" where checkTargetAndContextDB (Left (_, shr, prj)) = do mj <- lift $ runMaybeT $ do @@ -469,22 +472,6 @@ sharerCreateTicketF now shrRecip author body mfwd luCreate ticket muTarget = do unless (isJust mj) $ throwE "Local context: No such project" checkTargetAndContextDB (Right _) = return () - insertToInbox luAct ibidRecip = do - let iidAuthor = remoteAuthorInstance author - roid <- - either entityKey id <$> insertBy' (RemoteObject iidAuthor luAct) - let jsonObj = persistJSONFromBL $ actbBL body - ract = RemoteActivity roid jsonObj now - ractid <- either entityKey id <$> insertBy' ract - ibiid <- insert $ InboxItem True - mibrid <- insertUnique $ InboxItemRemote ibidRecip ractid ibiid - let recip = shr2text shrRecip - case mibrid of - Nothing -> do - delete ibiid - return $ "Activity already exists in inbox of /s/" <> recip - Just _ -> return $ "Activity inserted to inbox of /s/" <> recip - projectCreateTicketF :: UTCTime -> ShrIdent