fix some stuff
This commit is contained in:
parent
e7785e6ca0
commit
a4c779a1de
@ -356,7 +356,8 @@ insertNoteSQL actor note =
|
||||
content,
|
||||
name,
|
||||
inReplyTo,
|
||||
url
|
||||
url,
|
||||
'[]' as likes
|
||||
|
||||
|]
|
||||
,
|
||||
|
13
app/Html.hs
13
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
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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 =
|
||||
|
Loading…
Reference in New Issue
Block a user