undo like

This commit is contained in:
me 2024-12-17 10:47:00 +02:00
parent 50431a97dd
commit e7785e6ca0
3 changed files with 52 additions and 27 deletions

View File

@ -29,6 +29,7 @@ data DB
, getNote :: DB.Int64 -> IO (Maybe Note)
, insertNote :: NoteEntry -> IO (DB.Int64, Note)
, insertLike :: LikeEntry -> IO DB.Int64
, deleteLike :: LikeEntry -> IO (Maybe DB.Int64)
-- , deleteLike :: LikeEntry -> IO (Maybe DB.Int64)
, insertFollower
:: forall a
@ -102,6 +103,8 @@ mkDB connstr details = do
\note -> DB.withPool pool (insertNoteToDb (actorUrl details) note)
, insertLike =
\like -> DB.withPool pool (insertLikeToDb like)
, deleteLike =
\like -> DB.withPool pool (deleteLikeToDb like)
, insertFollower =
\follower handle -> DB.withPool pool $ DB.transaction do
id' <- insertFollowerToDb follower
@ -204,6 +207,11 @@ insertLikeToDb like = do
[n] <- map decodeIntRow <$> uncurry DB.runWith (insertLikeSQL like)
pure n
deleteLikeToDb :: LikeEntry -> DB.SQLite (Maybe DB.Int64)
deleteLikeToDb like = do
ns <- map decodeIntRow <$> uncurry DB.runWith (deleteLikeSQL like)
pure $ listToMaybe ns
insertFollowerToDb :: FollowerEntry -> DB.SQLite DB.Int64
insertFollowerToDb follower = do
[n] <- map decodeIntRow <$> uncurry DB.runWith (insertFollowerSQL follower)
@ -374,6 +382,22 @@ insertLikeSQL like =
]
)
deleteLikeSQL :: LikeEntry -> (DB.SQL, [DB.SQLData])
deleteLikeSQL like =
( [r|
DELETE FROM like
WHERE like_url = ?
AND actor_url = ?
AND note_url = ?
RETURNING
id as id
|]
, [ DB.SQLText (T.pack like.likeUrl)
, DB.SQLText (T.pack like.likeActorUrl.unwrap)
, DB.SQLText (T.pack like.likeNoteUrl.unwrap)
]
)
insertFollowerSQL :: FollowerEntry -> (DB.SQL, [DB.SQLData])
insertFollowerSQL follower =
( [r|

View File

@ -16,8 +16,6 @@ handleInbox db detailsFile activity = do
case activity of
Fedi.ActivityFollow follow ->
handleInboxFollow details db activity follow
Fedi.ActivityLike like ->
handleInboxLike db like
Fedi.ActivityUndo
( Fedi.Object
{ otype =
@ -30,6 +28,20 @@ handleInbox db detailsFile activity = do
}
) ->
handleInboxUnfollow details db activity follow
Fedi.ActivityLike like ->
handleInboxLike db like
Fedi.ActivityUndo
( Fedi.Object
{ otype =
Fedi.TypeActivity
{ atype =
Fedi.TypeUndo
{ object = Fedi.ActivityLike like
}
}
}
) ->
handleInboxUnlike db like
_ -> do
Log.logError $ "Unsupported activity: " <> Fedi.pShow activity
Twain.next

View File

@ -32,7 +32,7 @@ handleInboxLike db like = do
Nothing ->
Twain.next
{-
handleInboxUnlike
:: DB
-> Fedi.Like
@ -44,29 +44,18 @@ handleInboxUnlike db like = do
note = like.otype.atype.object
case id' of
Just id'' -> do
let
followerEntry =
( LikeEntry
{ likeUrl = fromString id''.unwrap
, likeActorUrl = actor
, likeNoteUrl = note
}
)
operation sendAccept = do
deleteFollower
db
LikeEntry
( \deletedId' -> do
let
deletedId = Fedi.fromMaybe 0 deletedId'
sendAccept deletedId
<* Log.logInfo ("Deleted follower: " <> Fedi.pShow deletedId)
)
liftIO $ acceptRequest details actor activity operation
pure $ Twain.text ""
let
likeEntry =
( LikeEntry
{ likeUrl = fromString id''.unwrap
, likeActorUrl = actor
, likeNoteUrl = note
}
)
operation = do
likeid <- db.deleteLike likeEntry
Log.logInfo ("Unlike: " <> Fedi.pShow (likeid, likeEntry))
liftIO operation
pure $ Twain.text ""
Nothing ->
Twain.next
-}