undo like
This commit is contained in:
parent
50431a97dd
commit
e7785e6ca0
3 changed files with 52 additions and 27 deletions
24
app/DB.hs
24
app/DB.hs
|
@ -29,6 +29,7 @@ data DB
|
||||||
, getNote :: DB.Int64 -> IO (Maybe Note)
|
, getNote :: DB.Int64 -> IO (Maybe Note)
|
||||||
, insertNote :: NoteEntry -> IO (DB.Int64, Note)
|
, insertNote :: NoteEntry -> IO (DB.Int64, Note)
|
||||||
, insertLike :: LikeEntry -> IO DB.Int64
|
, insertLike :: LikeEntry -> IO DB.Int64
|
||||||
|
, deleteLike :: LikeEntry -> IO (Maybe DB.Int64)
|
||||||
-- , deleteLike :: LikeEntry -> IO (Maybe DB.Int64)
|
-- , deleteLike :: LikeEntry -> IO (Maybe DB.Int64)
|
||||||
, insertFollower
|
, insertFollower
|
||||||
:: forall a
|
:: forall a
|
||||||
|
@ -102,6 +103,8 @@ mkDB connstr details = do
|
||||||
\note -> DB.withPool pool (insertNoteToDb (actorUrl details) note)
|
\note -> DB.withPool pool (insertNoteToDb (actorUrl details) note)
|
||||||
, insertLike =
|
, insertLike =
|
||||||
\like -> DB.withPool pool (insertLikeToDb like)
|
\like -> DB.withPool pool (insertLikeToDb like)
|
||||||
|
, deleteLike =
|
||||||
|
\like -> DB.withPool pool (deleteLikeToDb like)
|
||||||
, insertFollower =
|
, insertFollower =
|
||||||
\follower handle -> DB.withPool pool $ DB.transaction do
|
\follower handle -> DB.withPool pool $ DB.transaction do
|
||||||
id' <- insertFollowerToDb follower
|
id' <- insertFollowerToDb follower
|
||||||
|
@ -204,6 +207,11 @@ insertLikeToDb like = do
|
||||||
[n] <- map decodeIntRow <$> uncurry DB.runWith (insertLikeSQL like)
|
[n] <- map decodeIntRow <$> uncurry DB.runWith (insertLikeSQL like)
|
||||||
pure n
|
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 :: FollowerEntry -> DB.SQLite DB.Int64
|
||||||
insertFollowerToDb follower = do
|
insertFollowerToDb follower = do
|
||||||
[n] <- map decodeIntRow <$> uncurry DB.runWith (insertFollowerSQL follower)
|
[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 :: FollowerEntry -> (DB.SQL, [DB.SQLData])
|
||||||
insertFollowerSQL follower =
|
insertFollowerSQL follower =
|
||||||
( [r|
|
( [r|
|
||||||
|
|
|
@ -16,8 +16,6 @@ handleInbox db detailsFile activity = do
|
||||||
case activity of
|
case activity of
|
||||||
Fedi.ActivityFollow follow ->
|
Fedi.ActivityFollow follow ->
|
||||||
handleInboxFollow details db activity follow
|
handleInboxFollow details db activity follow
|
||||||
Fedi.ActivityLike like ->
|
|
||||||
handleInboxLike db like
|
|
||||||
Fedi.ActivityUndo
|
Fedi.ActivityUndo
|
||||||
( Fedi.Object
|
( Fedi.Object
|
||||||
{ otype =
|
{ otype =
|
||||||
|
@ -30,6 +28,20 @@ handleInbox db detailsFile activity = do
|
||||||
}
|
}
|
||||||
) ->
|
) ->
|
||||||
handleInboxUnfollow details db activity follow
|
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
|
_ -> do
|
||||||
Log.logError $ "Unsupported activity: " <> Fedi.pShow activity
|
Log.logError $ "Unsupported activity: " <> Fedi.pShow activity
|
||||||
Twain.next
|
Twain.next
|
||||||
|
|
|
@ -32,7 +32,7 @@ handleInboxLike db like = do
|
||||||
Nothing ->
|
Nothing ->
|
||||||
Twain.next
|
Twain.next
|
||||||
|
|
||||||
{-
|
|
||||||
handleInboxUnlike
|
handleInboxUnlike
|
||||||
:: DB
|
:: DB
|
||||||
-> Fedi.Like
|
-> Fedi.Like
|
||||||
|
@ -44,29 +44,18 @@ handleInboxUnlike db like = do
|
||||||
note = like.otype.atype.object
|
note = like.otype.atype.object
|
||||||
case id' of
|
case id' of
|
||||||
Just id'' -> do
|
Just id'' -> do
|
||||||
let
|
let
|
||||||
followerEntry =
|
likeEntry =
|
||||||
( LikeEntry
|
( LikeEntry
|
||||||
{ likeUrl = fromString id''.unwrap
|
{ likeUrl = fromString id''.unwrap
|
||||||
, likeActorUrl = actor
|
, likeActorUrl = actor
|
||||||
, likeNoteUrl = note
|
, likeNoteUrl = note
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
operation sendAccept = do
|
operation = do
|
||||||
deleteFollower
|
likeid <- db.deleteLike likeEntry
|
||||||
db
|
Log.logInfo ("Unlike: " <> Fedi.pShow (likeid, likeEntry))
|
||||||
LikeEntry
|
liftIO operation
|
||||||
( \deletedId' -> do
|
pure $ Twain.text ""
|
||||||
let
|
|
||||||
deletedId = Fedi.fromMaybe 0 deletedId'
|
|
||||||
sendAccept deletedId
|
|
||||||
<* Log.logInfo ("Deleted follower: " <> Fedi.pShow deletedId)
|
|
||||||
)
|
|
||||||
|
|
||||||
liftIO $ acceptRequest details actor activity operation
|
|
||||||
|
|
||||||
pure $ Twain.text ""
|
|
||||||
Nothing ->
|
Nothing ->
|
||||||
Twain.next
|
Twain.next
|
||||||
|
|
||||||
-}
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue