augment notes json a bit
This commit is contained in:
parent
054b6ff49f
commit
e02b8a5d1c
2 changed files with 36 additions and 1 deletions
|
@ -68,13 +68,37 @@ data Collection order a
|
|||
instance A.ToJSON Note where
|
||||
toJSON note =
|
||||
A.object $
|
||||
[ "type" A..= ("Note" :: String)
|
||||
[ "@context" A..=
|
||||
( "https://www.w3.org/ns/activitystreams" :: String
|
||||
)
|
||||
, "id" A..= note.id
|
||||
, "type" A..= ("Note" :: String)
|
||||
, "summary" A..= (Nothing :: Maybe String)
|
||||
, "inReplyTo" A..= (Nothing :: Maybe String)
|
||||
, "published" A..= note.published
|
||||
, "attributedTo" A..= note.actor
|
||||
, "content" A..= note.content
|
||||
, "name" A..= note.name
|
||||
, "replies" A..= note.replies
|
||||
, "sensitive" A..= False
|
||||
, "tag" A..= ([] :: [String])
|
||||
|
||||
, "to" A..= [
|
||||
"https://www.w3.org/ns/activitystreams#Public" :: String
|
||||
]
|
||||
, "cc" A..= [
|
||||
note.actor <> "/followers" :: String
|
||||
]
|
||||
, "likes" A..=
|
||||
( Collection
|
||||
{ id = note.id <> "/likes"
|
||||
, summary = "likes"
|
||||
, items = []
|
||||
, first = Nothing
|
||||
, last = Nothing
|
||||
} :: Collection Unordered Activity
|
||||
)
|
||||
, "shares" A..= (Nothing :: Maybe String)
|
||||
]
|
||||
<> [ "name" A..= name | Just name <- [note.name] ]
|
||||
<> [ "url" A..= url | Just url <- [note.url] ]
|
||||
|
|
|
@ -5,6 +5,7 @@ import Web.Twain qualified as Twain
|
|||
import Web.Twain.Types qualified as Twain
|
||||
import Data.String (fromString)
|
||||
import Data.Aeson qualified as A
|
||||
import Data.ByteString qualified as BS
|
||||
import Data.ByteString.Lazy qualified as BSL
|
||||
import Fedi.Types
|
||||
import Fedi.Activity
|
||||
|
@ -147,3 +148,13 @@ handleOutbox details items = do
|
|||
}
|
||||
in A.encode content
|
||||
Twain.send $ jsonLD response
|
||||
|
||||
checkContentTypeAccept :: Twain.Request -> Bool
|
||||
checkContentTypeAccept request =
|
||||
case lookup Twain.hAccept request.requestHeaders of
|
||||
Just bs ->
|
||||
("application/activity+json" `BS.isInfixOf` bs)
|
||||
|| ( ("application/activity+json" `BS.isInfixOf` bs)
|
||||
&& ("profile=\"https://www.w3.org/ns/activitystreams\"" `BS.isInfixOf` bs)
|
||||
)
|
||||
Nothing -> False
|
||||
|
|
Loading…
Add table
Reference in a new issue