1
0
Fork 0
mirror of https://code.sup39.dev/repos/Wqawg synced 2024-12-28 23:24:53 +09:00

Make noteId optional, to support taking a Note in postOutboxR

This commit is contained in:
fr33domlover 2019-03-23 02:05:30 +00:00
parent 88d4c976ee
commit 58a56b6743
4 changed files with 24 additions and 17 deletions

View file

@ -146,7 +146,8 @@ handleActivity raw hActor iidActor rsidActor (Activity _id _luActor audience spe
rm E.^. RemoteMessageLostParent E.==. E.just (E.val uNote) E.&&. rm E.^. RemoteMessageLostParent E.==. E.just (E.val uNote) E.&&.
m E.^. MessageRoot `op` E.val did m E.^. MessageRoot `op` E.val did
return (rm E.^. RemoteMessageId, m E.^. MessageId) return (rm E.^. RemoteMessageId, m E.^. MessageId)
handleCreate iidActor hActor rsidActor raw audience (Note luNote _luAttrib muParent muContext mpublished content) = do handleCreate iidActor hActor rsidActor raw audience (Note mluNote _luAttrib muParent muContext mpublished content) = do
luNote <- fromMaybeE mluNote "Got Create Note without note id"
(shr, prj) <- do (shr, prj) <- do
uRecip <- parseAudience audience uRecip <- parseAudience audience
parseProject uRecip parseProject uRecip

View file

@ -141,7 +141,7 @@ getDiscussionMessage shr lmid = selectRep $ provideAP $ runDB $ do
route2local <- getEncodeRouteLocal route2local <- getEncodeRouteLocal
let lmhid = encodeHid $ fromSqlKey lmid let lmhid = encodeHid $ fromSqlKey lmid
return $ Doc host Note return $ Doc host Note
{ noteId = route2local $ MessageR shr lmhid { noteId = Just $ route2local $ MessageR shr lmhid
, noteAttrib = route2local $ SharerR shr , noteAttrib = route2local $ SharerR shr
, noteReplyTo = Just $ fromMaybe uContext muParent , noteReplyTo = Just $ fromMaybe uContext muParent
, noteContext = Just uContext , noteContext = Just uContext

View file

@ -85,6 +85,7 @@ import Database.Persist.Local
import Network.FedURI import Network.FedURI
import Web.ActivityPub import Web.ActivityPub
import Yesod.Auth.Unverified import Yesod.Auth.Unverified
import Yesod.FedURI
import Vervis.ActorKey import Vervis.ActorKey
import Vervis.Federation import Vervis.Federation
@ -228,12 +229,6 @@ getPublishR = do
getOutboxR :: Handler TypedContent getOutboxR :: Handler TypedContent
getOutboxR = error "Not implemented yet" getOutboxR = error "Not implemented yet"
route2uri' :: (Route App -> Text) -> Route App -> FedURI
route2uri' renderUrl r =
case parseFedURI $ renderUrl r of
Left e -> error e
Right u -> u
postOutboxR :: Handler Html postOutboxR :: Handler Html
postOutboxR = do postOutboxR = do
((result, widget), enctype) <- runFormPost activityForm ((result, widget), enctype) <- runFormPost activityForm
@ -247,9 +242,9 @@ postOutboxR = do
sharer <- runDB $ get404 $ personIdent person sharer <- runDB $ get404 $ personIdent person
return $ sharerIdent sharer return $ sharerIdent sharer
renderUrl <- getUrlRender renderUrl <- getUrlRender
route2uri <- getEncodeRouteFed
now <- liftIO getCurrentTime now <- liftIO getCurrentTime
let route2uri = route2uri' renderUrl let (h, actor) = f2l $ route2uri $ SharerR shr
(h, actor) = f2l $ route2uri $ SharerR shr
actorID = renderUrl $ SharerR shr actorID = renderUrl $ SharerR shr
appendPath u t = u { luriPath = luriPath u <> t } appendPath u t = u { luriPath = luriPath u <> t }
activity = Activity activity = Activity
@ -264,7 +259,8 @@ postOutboxR = do
} }
, activitySpecific = CreateActivity Create , activitySpecific = CreateActivity Create
{ createObject = Note { createObject = Note
{ noteId = appendPath actor "/fake-note" { noteId = Just $ appendPath actor "/fake-note"
, noteAttrib = actor
, noteReplyTo = mparent , noteReplyTo = mparent
, noteContext = mcontext , noteContext = mcontext
, notePublished = Just now , notePublished = Just now
@ -328,7 +324,7 @@ getActorKey choose route = selectRep $ provideAP $ do
actorKey <- actorKey <-
liftIO . fmap (actorKeyPublicBin . choose) . readTVarIO =<< liftIO . fmap (actorKeyPublicBin . choose) . readTVarIO =<<
getsYesod appActorKeys getsYesod appActorKeys
route2uri <- route2uri' <$> getUrlRender route2uri <- getEncodeRouteFed
let (host, id_) = f2l $ route2uri route let (host, id_) = f2l $ route2uri route
return $ Doc host PublicKey return $ Doc host PublicKey
{ publicKeyId = id_ { publicKeyId = id_

View file

@ -81,6 +81,7 @@ import Data.Semigroup (Endo, First (..))
import Data.Text (Text) import Data.Text (Text)
import Data.Text.Encoding (encodeUtf8, decodeUtf8) import Data.Text.Encoding (encodeUtf8, decodeUtf8)
import Data.Time.Clock (UTCTime) import Data.Time.Clock (UTCTime)
import Data.Traversable
import Data.Vector (Vector) import Data.Vector (Vector)
import Network.HTTP.Client hiding (Proxy, proxy) import Network.HTTP.Client hiding (Proxy, proxy)
import Network.HTTP.Client.Conduit.ActivityPub (httpAPEither) import Network.HTTP.Client.Conduit.ActivityPub (httpAPEither)
@ -316,7 +317,7 @@ instance ActivityPub Actor where
<> "publicKey" `pair` encodePublicKeySet host pkeys <> "publicKey" `pair` encodePublicKeySet host pkeys
data Note = Note data Note = Note
{ noteId :: LocalURI { noteId :: Maybe LocalURI
, noteAttrib :: LocalURI , noteAttrib :: LocalURI
--, noteTo :: FedURI --, noteTo :: FedURI
, noteReplyTo :: Maybe FedURI , noteReplyTo :: Maybe FedURI
@ -331,22 +332,31 @@ withHost h a = do
then return v then return v
else fail "URI host mismatch" else fail "URI host mismatch"
withHostM h a = do
mp <- a
for mp $ \ (h', v) ->
if h == h'
then return v
else fail "URI host mismatch"
instance ActivityPub Note where instance ActivityPub Note where
jsonldContext _ = ContextAS2 jsonldContext _ = ContextAS2
parseObject o = do parseObject o = do
typ <- o .: "type" typ <- o .: "type"
unless (typ == ("Note" :: Text)) $ fail "type isn't Note" unless (typ == ("Note" :: Text)) $ fail "type isn't Note"
(h, attrib) <- f2l <$> o .: "attributedTo"
(h, id_) <- f2l <$> o .: "id" (h, id_) <- f2l <$> o .: "id"
fmap (h,) $ fmap (h,) $
Note id_ Note
<$> withHost h (f2l <$> o .: "attributedTo") <$> withHostM h (fmap f2l <$> o .:? "id")
<*> pure attrib
<*> o .:? "inReplyTo" <*> o .:? "inReplyTo"
<*> o .:? "context" <*> o .:? "context"
<*> o .:? "published" <*> o .:? "published"
<*> o .: "content" <*> o .: "content"
toSeries host (Note id_ attrib mreply mcontext mpublished content) toSeries host (Note mid attrib mreply mcontext mpublished content)
= "type" .= ("Note" :: Text) = "type" .= ("Note" :: Text)
<> "id" .= l2f host id_ <> "id" .=? (l2f host <$> mid)
<> "attributedTo" .= l2f host attrib <> "attributedTo" .= l2f host attrib
<> "inReplyTo" .=? mreply <> "inReplyTo" .=? mreply
<> "context" .=? mcontext <> "context" .=? mcontext