From f296dc173cd7cd64981b8c150906d7d50413a428 Mon Sep 17 00:00:00 2001
From: fr33domlover <fr33domlover@riseup.net>
Date: Wed, 13 May 2020 13:29:39 +0000
Subject: [PATCH] C2S: In followC, return friendly message if already following
 the target object

---
 src/Vervis/API.hs | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/Vervis/API.hs b/src/Vervis/API.hs
index 76c6d27..88e92f0 100644
--- a/src/Vervis/API.hs
+++ b/src/Vervis/API.hs
@@ -774,10 +774,9 @@ followC shrUser summary audience follow@(AP.Follow uObject muContext hide) = run
             Nothing -> lift $ insert_ $ FollowRemoteRequest pidAuthor uObject muContext (not hide) obiidFollow
             Just (followee, actorRecip) -> do
                 (fsid, ibidRecip, unread, obidRecip) <- getFollowee followee
-                lift $ do
-                    obiidAccept <- insertAcceptToOutbox luFollow actorRecip obidRecip
-                    deliverFollowLocal pidAuthor fsid unread obiidFollow obiidAccept ibidRecip
-                    deliverAcceptLocal obiidAccept ibidAuthor
+                obiidAccept <- lift $ insertAcceptToOutbox luFollow actorRecip obidRecip
+                deliverFollowLocal pidAuthor fsid unread obiidFollow obiidAccept ibidRecip
+                lift $ deliverAcceptLocal obiidAccept ibidAuthor
         remotesHttp <- lift $ deliverRemoteDB' dont obiidFollow remoteRecips []
         return (obiidFollow, doc, remotesHttp)
     lift $ forkWorker "Outbox POST handler: async HTTP delivery" $ deliverRemoteHttp dont obiidFollow doc remotesHttp
@@ -875,9 +874,10 @@ followC shrUser summary audience follow@(AP.Follow uObject muContext hide) = run
         return (obiid, doc, luAct)
 
     deliverFollowLocal pidAuthor fsid unread obiidF obiidA ibidRecip = do
-        insert_ $ Follow pidAuthor fsid (not hide) obiidF obiidA
-        ibiid <- insert $ InboxItem unread
-        insert_ $ InboxItemLocal ibidRecip obiidF ibiid
+        mfid <- lift $ insertUnique $ Follow pidAuthor fsid (not hide) obiidF obiidA
+        _ <- fromMaybeE mfid "Already following this object"
+        ibiid <- lift $ insert $ InboxItem unread
+        lift $ insert_ $ InboxItemLocal ibidRecip obiidF ibiid
 
     insertAcceptToOutbox luFollow actorRecip obidRecip = do
         now <- liftIO getCurrentTime