diff --git a/app/DB.hs b/app/DB.hs index 0cf66b9..1f3acc4 100644 --- a/app/DB.hs +++ b/app/DB.hs @@ -356,7 +356,8 @@ insertNoteSQL actor note = content, name, inReplyTo, - url + url, + '[]' as likes |] , diff --git a/app/Html.hs b/app/Html.hs index 4136e8c..6507e6d 100644 --- a/app/Html.hs +++ b/app/Html.hs @@ -45,10 +45,17 @@ userHtml details = do H.a_ [H.href_ (T.pack $ "/" <> details.username)] $ H.img_ [H.class_ "avatar", H.src_ (T.pack details.icon)] H.div_ [H.class_ "user-details-details"] do - H.h2_ (fromString details.username) - H.a_ [H.href_ (T.pack $ Fedi.actorUrl details)] $ + H.h2_ + [H.class_ (checkDirection (fromString details.name))] + (fromString details.name) + H.a_ + [ H.class_ (checkDirection (fromString details.name)) + , H.href_ (T.pack $ Fedi.actorUrl details) + ] $ H.p_ (fromString $ Fedi.fullmention details) - H.p_ (fromString details.summary) + H.p_ + [H.class_ (checkDirection (fromString details.summary))] + (fromString details.summary) notesHtml :: [Fedi.Note] -> Html notesHtml notes = do diff --git a/src/Fedi/Types.hs b/src/Fedi/Types.hs index 853f223..147996c 100644 --- a/src/Fedi/Types.hs +++ b/src/Fedi/Types.hs @@ -17,7 +17,7 @@ data Object typ , otype :: typ , content :: Maybe Content , published :: Maybe UTCTime - , replies :: Maybe [Link] + , replies :: Maybe [Collection (CollectionPage Link)] , attachment :: Maybe [AnyMedia] , attributedTo :: Maybe (LinkOrObject Actor) , -- , audience :: Maybe String @@ -199,10 +199,10 @@ instance ToObject TypeNote where instance A.FromJSON TypeNote where parseJSON = A.withObject "TypeNote" \value -> do - likes <- value A..: "likes" - shares <- value A..: "shares" - replies <- value A..: "replies" - sensitive <- value A..: "sensitive" + likes <- fromMaybe emptyUnorderedCollection <$> value A..:? "likes" + shares <- fromMaybe emptyUnorderedCollection <$> value A..:? "shares" + replies <- fromMaybe emptyUnorderedCollection <$> value A..:? "replies" + sensitive <- fromMaybe False <$> value A..:? "sensitive" pure TypeNote {..} type Tag = Object TypeTag @@ -538,6 +538,8 @@ type Collection e = Object (CollectionType (Unordered e)) type OrderedCollection e = Object (CollectionType (Ordered e)) +type CollectionPage e = Object (CollectionType (UnorderedPage e)) + type OrderedCollectionPage e = Object (CollectionType (OrderedPage e)) type Outbox = OrderedCollection AnyActivity @@ -619,6 +621,37 @@ instance (A.FromJSON e) => A.FromJSON (Ordered e) where orderedItems <- fromMaybe [] <$> v A..:? "orderedItems" pure OrderedCollectionType {..} +data UnorderedPage e + = UnorderedCollectionPageType + { partOf :: Url + , prev :: Maybe Url + , next :: Maybe Url + , pitems :: [e] + } + deriving (Show, Eq) + +instance (A.ToJSON e) => ToObject (UnorderedPage e) where + toObject page = + [ "type" A..= ("CollectionPage" :: String) + , "totalItems" A..= length page.pitems + , "items" A..= page.pitems + , "partOf" A..= page.partOf + , "prev" A..= page.prev + , "next" A..= page.next + ] + +instance (A.FromJSON e) => A.FromJSON (UnorderedPage e) where + parseJSON = do + A.withObject "UnorderedPage" \v -> do + typ :: String <- v A..: "type" + guard (typ == "CollectionPage") + partOf <- v A..: "partOf" + prev <- v A..:? "prev" + next <- v A..:? "next" + pitems <- fromMaybe [] <$> v A..:? "items" + pure UnorderedCollectionPageType {..} + + data OrderedPage e = OrderedCollectionPageType { partOf :: Url @@ -648,3 +681,47 @@ instance (A.FromJSON e) => A.FromJSON (OrderedPage e) where next <- v A..:? "next" porderedItems <- fromMaybe [] <$> v A..:? "orderedItems" pure OrderedCollectionPageType {..} + + + +-- | An empty activitypub Object. +emptyObject :: Object () +emptyObject = + Object + { id = Nothing + , otype = () + , content = Nothing + , published = Nothing + , replies = Nothing + , attachment = Nothing + , attributedTo = Nothing + , tag = Nothing + , to = Nothing + , cc = Nothing + , inReplyTo = Nothing + , url = Nothing + , name = Nothing + , icon = Nothing + , image = Nothing + , preview = Nothing + , summary = Nothing + , updated = Nothing + , mediaType = Nothing + } + + +-- | An empty 'Collection'. +emptyUnorderedCollection :: Collection a +emptyUnorderedCollection = + emptyObject + { otype = + CollectionType + { ctype = + UnorderedCollectionType + { items = [] + } + , first = Nothing + , last = Nothing + , current = Nothing + } + } diff --git a/src/Fedi/Types/Helpers.hs b/src/Fedi/Types/Helpers.hs index d0c3476..5ded080 100644 --- a/src/Fedi/Types/Helpers.hs +++ b/src/Fedi/Types/Helpers.hs @@ -1,34 +1,13 @@ -module Fedi.Types.Helpers where +module Fedi.Types.Helpers + ( module Fedi.Types + , module Fedi.Types.Helpers + ) +where import Data.Text qualified as T import Fedi.Types import Fedi.UserDetails --- | An empty activitypub Object. -emptyObject :: Object () -emptyObject = - Object - { id = Nothing - , otype = () - , content = Nothing - , published = Nothing - , replies = Nothing - , attachment = Nothing - , attributedTo = Nothing - , tag = Nothing - , to = Nothing - , cc = Nothing - , inReplyTo = Nothing - , url = Nothing - , name = Nothing - , icon = Nothing - , image = Nothing - , preview = Nothing - , summary = Nothing - , updated = Nothing - , mediaType = Nothing - } - -- | Create an activitypub Actor. makeActor :: UserDetails -> Actor makeActor details = @@ -101,22 +80,6 @@ makeImage link = , url = Just link } --- | An empty 'Collection'. -emptyUnorderedCollection :: Collection a -emptyUnorderedCollection = - emptyObject - { otype = - CollectionType - { ctype = - UnorderedCollectionType - { items = [] - } - , first = Nothing - , last = Nothing - , current = Nothing - } - } - -- | An empty 'OrderedCollection'. emptyOrderedCollection :: OrderedCollection a emptyOrderedCollection =