fix some stuff
This commit is contained in:
parent
bbba33925c
commit
62fc176091
4 changed files with 99 additions and 51 deletions
|
@ -356,7 +356,8 @@ insertNoteSQL actor note =
|
||||||
content,
|
content,
|
||||||
name,
|
name,
|
||||||
inReplyTo,
|
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.a_ [H.href_ (T.pack $ "/" <> details.username)] $
|
||||||
H.img_ [H.class_ "avatar", H.src_ (T.pack details.icon)]
|
H.img_ [H.class_ "avatar", H.src_ (T.pack details.icon)]
|
||||||
H.div_ [H.class_ "user-details-details"] do
|
H.div_ [H.class_ "user-details-details"] do
|
||||||
H.h2_ (fromString details.username)
|
H.h2_
|
||||||
H.a_ [H.href_ (T.pack $ Fedi.actorUrl details)] $
|
[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 $ Fedi.fullmention details)
|
||||||
H.p_ (fromString details.summary)
|
H.p_
|
||||||
|
[H.class_ (checkDirection (fromString details.summary))]
|
||||||
|
(fromString details.summary)
|
||||||
|
|
||||||
notesHtml :: [Fedi.Note] -> Html
|
notesHtml :: [Fedi.Note] -> Html
|
||||||
notesHtml notes = do
|
notesHtml notes = do
|
||||||
|
|
|
@ -17,7 +17,7 @@ data Object typ
|
||||||
, otype :: typ
|
, otype :: typ
|
||||||
, content :: Maybe Content
|
, content :: Maybe Content
|
||||||
, published :: Maybe UTCTime
|
, published :: Maybe UTCTime
|
||||||
, replies :: Maybe [Link]
|
, replies :: Maybe [Collection (CollectionPage Link)]
|
||||||
, attachment :: Maybe [AnyMedia]
|
, attachment :: Maybe [AnyMedia]
|
||||||
, attributedTo :: Maybe (LinkOrObject Actor)
|
, attributedTo :: Maybe (LinkOrObject Actor)
|
||||||
, -- , audience :: Maybe String
|
, -- , audience :: Maybe String
|
||||||
|
@ -199,10 +199,10 @@ instance ToObject TypeNote where
|
||||||
instance A.FromJSON TypeNote where
|
instance A.FromJSON TypeNote where
|
||||||
parseJSON =
|
parseJSON =
|
||||||
A.withObject "TypeNote" \value -> do
|
A.withObject "TypeNote" \value -> do
|
||||||
likes <- value A..: "likes"
|
likes <- fromMaybe emptyUnorderedCollection <$> value A..:? "likes"
|
||||||
shares <- value A..: "shares"
|
shares <- fromMaybe emptyUnorderedCollection <$> value A..:? "shares"
|
||||||
replies <- value A..: "replies"
|
replies <- fromMaybe emptyUnorderedCollection <$> value A..:? "replies"
|
||||||
sensitive <- value A..: "sensitive"
|
sensitive <- fromMaybe False <$> value A..:? "sensitive"
|
||||||
pure TypeNote {..}
|
pure TypeNote {..}
|
||||||
|
|
||||||
type Tag = Object TypeTag
|
type Tag = Object TypeTag
|
||||||
|
@ -538,6 +538,8 @@ type Collection e = Object (CollectionType (Unordered e))
|
||||||
|
|
||||||
type OrderedCollection e = Object (CollectionType (Ordered e))
|
type OrderedCollection e = Object (CollectionType (Ordered e))
|
||||||
|
|
||||||
|
type CollectionPage e = Object (CollectionType (UnorderedPage e))
|
||||||
|
|
||||||
type OrderedCollectionPage e = Object (CollectionType (OrderedPage e))
|
type OrderedCollectionPage e = Object (CollectionType (OrderedPage e))
|
||||||
|
|
||||||
type Outbox = OrderedCollection AnyActivity
|
type Outbox = OrderedCollection AnyActivity
|
||||||
|
@ -619,6 +621,37 @@ instance (A.FromJSON e) => A.FromJSON (Ordered e) where
|
||||||
orderedItems <- fromMaybe [] <$> v A..:? "orderedItems"
|
orderedItems <- fromMaybe [] <$> v A..:? "orderedItems"
|
||||||
pure OrderedCollectionType {..}
|
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
|
data OrderedPage e
|
||||||
= OrderedCollectionPageType
|
= OrderedCollectionPageType
|
||||||
{ partOf :: Url
|
{ partOf :: Url
|
||||||
|
@ -648,3 +681,47 @@ instance (A.FromJSON e) => A.FromJSON (OrderedPage e) where
|
||||||
next <- v A..:? "next"
|
next <- v A..:? "next"
|
||||||
porderedItems <- fromMaybe [] <$> v A..:? "orderedItems"
|
porderedItems <- fromMaybe [] <$> v A..:? "orderedItems"
|
||||||
pure OrderedCollectionPageType {..}
|
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 Data.Text qualified as T
|
||||||
import Fedi.Types
|
import Fedi.Types
|
||||||
import Fedi.UserDetails
|
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.
|
-- | Create an activitypub Actor.
|
||||||
makeActor :: UserDetails -> Actor
|
makeActor :: UserDetails -> Actor
|
||||||
makeActor details =
|
makeActor details =
|
||||||
|
@ -101,22 +80,6 @@ makeImage link =
|
||||||
, url = Just 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'.
|
-- | An empty 'OrderedCollection'.
|
||||||
emptyOrderedCollection :: OrderedCollection a
|
emptyOrderedCollection :: OrderedCollection a
|
||||||
emptyOrderedCollection =
|
emptyOrderedCollection =
|
||||||
|
|
Loading…
Add table
Reference in a new issue