mirror of
https://code.sup39.dev/repos/Wqawg
synced 2024-12-27 15:54:51 +09:00
DB: Switch RemoteMessage to use RemoteObject
This commit is contained in:
parent
c03dacdb11
commit
00e0f7c14f
9 changed files with 94 additions and 22 deletions
|
@ -1,6 +1,6 @@
|
||||||
-- This file is part of Vervis.
|
-- This file is part of Vervis.
|
||||||
--
|
--
|
||||||
-- Written in 2016, 2018, 2019 by fr33domlover <fr33domlover@riseup.net>.
|
-- Written in 2016, 2018, 2019, 2020 by fr33domlover <fr33domlover@riseup.net>.
|
||||||
--
|
--
|
||||||
-- ♡ Copying is an act of love. Please copy, reuse and share.
|
-- ♡ Copying is an act of love. Please copy, reuse and share.
|
||||||
--
|
--
|
||||||
|
@ -439,13 +439,12 @@ LocalMessage
|
||||||
|
|
||||||
RemoteMessage
|
RemoteMessage
|
||||||
author RemoteActorId
|
author RemoteActorId
|
||||||
instance InstanceId
|
ident RemoteObjectId
|
||||||
ident LocalURI
|
|
||||||
rest MessageId
|
rest MessageId
|
||||||
create RemoteActivityId
|
create RemoteActivityId
|
||||||
lostParent FedURI Maybe
|
lostParent FedURI Maybe
|
||||||
|
|
||||||
UniqueRemoteMessageIdent instance ident
|
UniqueRemoteMessageIdent ident
|
||||||
UniqueRemoteMessage rest
|
UniqueRemoteMessage rest
|
||||||
UniqueRemoteMessageCreate create
|
UniqueRemoteMessageCreate create
|
||||||
|
|
||||||
|
|
23
migrations/2020_02_10_rm_point_to_ro.model
Normal file
23
migrations/2020_02_10_rm_point_to_ro.model
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
Instance
|
||||||
|
host Host
|
||||||
|
|
||||||
|
UniqueInstance host
|
||||||
|
|
||||||
|
RemoteObject
|
||||||
|
instance InstanceId
|
||||||
|
ident LocalURI
|
||||||
|
|
||||||
|
UniqueRemoteObject instance ident
|
||||||
|
|
||||||
|
RemoteMessage
|
||||||
|
author Int64
|
||||||
|
instance InstanceId
|
||||||
|
ident LocalURI
|
||||||
|
identNew RemoteObjectId
|
||||||
|
rest Int64
|
||||||
|
create Int64
|
||||||
|
lostParent FedURI Maybe
|
||||||
|
|
||||||
|
UniqueRemoteMessageIdent instance ident
|
||||||
|
UniqueRemoteMessage rest
|
||||||
|
UniqueRemoteMessageCreate create
|
|
@ -181,7 +181,8 @@ createNoteC host (Note mluNote luAttrib aud muParent muContext mpublished source
|
||||||
Right (ObjURI hParent luParent) -> do
|
Right (ObjURI hParent luParent) -> do
|
||||||
mrm <- lift $ runMaybeT $ do
|
mrm <- lift $ runMaybeT $ do
|
||||||
iid <- MaybeT $ getKeyBy $ UniqueInstance hParent
|
iid <- MaybeT $ getKeyBy $ UniqueInstance hParent
|
||||||
MaybeT $ getValBy $ UniqueRemoteMessageIdent iid luParent
|
roid <- MaybeT $ getKeyBy $ UniqueRemoteObject iid luParent
|
||||||
|
MaybeT $ getValBy $ UniqueRemoteMessageIdent roid
|
||||||
rm <- fromMaybeE mrm "Remote parent unknown locally"
|
rm <- fromMaybeE mrm "Remote parent unknown locally"
|
||||||
let mid = remoteMessageRest rm
|
let mid = remoteMessageRest rm
|
||||||
m <- lift $ getJust mid
|
m <- lift $ getJust mid
|
||||||
|
@ -216,7 +217,8 @@ createNoteC host (Note mluNote luAttrib aud muParent muContext mpublished source
|
||||||
Right p@(ObjURI hParent luParent) -> do
|
Right p@(ObjURI hParent luParent) -> do
|
||||||
mrm <- lift $ runMaybeT $ do
|
mrm <- lift $ runMaybeT $ do
|
||||||
iid <- MaybeT $ getKeyBy $ UniqueInstance hParent
|
iid <- MaybeT $ getKeyBy $ UniqueInstance hParent
|
||||||
MaybeT $ getValBy $ UniqueRemoteMessageIdent iid luParent
|
roid <- MaybeT $ getKeyBy $ UniqueRemoteObject iid luParent
|
||||||
|
MaybeT $ getValBy $ UniqueRemoteMessageIdent roid
|
||||||
case mrm of
|
case mrm of
|
||||||
Nothing -> return $ Right p
|
Nothing -> return $ Right p
|
||||||
Just rm -> Left <$> do
|
Just rm -> Left <$> do
|
||||||
|
|
|
@ -123,8 +123,9 @@ createReply shrAuthor (TextPandocMarkdown msg) hDest recipsA recipsC context mid
|
||||||
lmkhid <- encodeKeyHashid lmidParent
|
lmkhid <- encodeKeyHashid lmidParent
|
||||||
return $ encodeRouteHome $ MessageR (sharerIdent s) lmkhid
|
return $ encodeRouteHome $ MessageR (sharerIdent s) lmkhid
|
||||||
(Nothing, Just rm) -> do
|
(Nothing, Just rm) -> do
|
||||||
i <- getJust $ remoteMessageInstance rm
|
ro <- getJust $ remoteMessageIdent rm
|
||||||
return $ ObjURI (instanceHost i) (remoteMessageIdent rm)
|
i <- getJust $ remoteObjectInstance ro
|
||||||
|
return $ ObjURI (instanceHost i) (remoteObjectIdent ro)
|
||||||
contentHtml <- ExceptT . pure $ renderPandocMarkdown msg
|
contentHtml <- ExceptT . pure $ renderPandocMarkdown msg
|
||||||
let uContext = encodeRecipRoute context
|
let uContext = encodeRecipRoute context
|
||||||
recips = recipsA ++ recipsC
|
recips = recipsA ++ recipsC
|
||||||
|
|
|
@ -58,7 +58,8 @@ getMessages getdid = runDB $ do
|
||||||
on $ lm ^. LocalMessageRest ==. m ^. MessageId
|
on $ lm ^. LocalMessageRest ==. m ^. MessageId
|
||||||
where_ $ m ^. MessageRoot ==. val did
|
where_ $ m ^. MessageRoot ==. val did
|
||||||
return (m, lm ^. LocalMessageId, s)
|
return (m, lm ^. LocalMessageId, s)
|
||||||
r <- select $ from $ \ (rm `InnerJoin` m `InnerJoin` ra `InnerJoin` ro `InnerJoin` i) -> do
|
r <- select $ from $ \ (rm `InnerJoin` m `InnerJoin` ra `InnerJoin` ro `InnerJoin` i `InnerJoin` ro2) -> do
|
||||||
|
on $ rm ^. RemoteMessageIdent ==. ro2 ^. RemoteObjectId
|
||||||
on $ ro ^. RemoteObjectInstance ==. i ^. InstanceId
|
on $ ro ^. RemoteObjectInstance ==. i ^. InstanceId
|
||||||
on $ ra ^. RemoteActorIdent ==. ro ^. RemoteObjectId
|
on $ ra ^. RemoteActorIdent ==. ro ^. RemoteObjectId
|
||||||
on $ rm ^. RemoteMessageAuthor ==. ra ^. RemoteActorId
|
on $ rm ^. RemoteMessageAuthor ==. ra ^. RemoteActorId
|
||||||
|
@ -67,7 +68,7 @@ getMessages getdid = runDB $ do
|
||||||
return
|
return
|
||||||
( m
|
( m
|
||||||
, i ^. InstanceHost
|
, i ^. InstanceHost
|
||||||
, rm ^. RemoteMessageIdent
|
, ro2 ^. RemoteObjectIdent
|
||||||
, ro ^. RemoteObjectIdent
|
, ro ^. RemoteObjectIdent
|
||||||
, ra ^. RemoteActorName
|
, ra ^. RemoteActorName
|
||||||
)
|
)
|
||||||
|
|
|
@ -122,7 +122,8 @@ sharerCreateNoteF now shrRecip author body (Note mluNote _ _ muParent muContext
|
||||||
Right (ObjURI hParent luParent) -> do
|
Right (ObjURI hParent luParent) -> do
|
||||||
mrm <- lift $ runMaybeT $ do
|
mrm <- lift $ runMaybeT $ do
|
||||||
iid <- MaybeT $ getKeyBy $ UniqueInstance hParent
|
iid <- MaybeT $ getKeyBy $ UniqueInstance hParent
|
||||||
MaybeT $ getValBy $ UniqueRemoteMessageIdent iid luParent
|
roid <- MaybeT $ getKeyBy $ UniqueRemoteObject iid luParent
|
||||||
|
MaybeT $ getValBy $ UniqueRemoteMessageIdent roid
|
||||||
for_ mrm $ \ rm -> do
|
for_ mrm $ \ rm -> do
|
||||||
let mid = remoteMessageRest rm
|
let mid = remoteMessageRest rm
|
||||||
m <- lift $ getJust mid
|
m <- lift $ getJust mid
|
||||||
|
@ -142,7 +143,8 @@ sharerCreateNoteF now shrRecip author body (Note mluNote _ _ muParent muContext
|
||||||
Right (ObjURI hParent luParent) -> do
|
Right (ObjURI hParent luParent) -> do
|
||||||
mrm <- lift $ runMaybeT $ do
|
mrm <- lift $ runMaybeT $ do
|
||||||
iid <- MaybeT $ getKeyBy $ UniqueInstance hParent
|
iid <- MaybeT $ getKeyBy $ UniqueInstance hParent
|
||||||
MaybeT $ getValBy $ UniqueRemoteMessageIdent iid luParent
|
roid <- MaybeT $ getKeyBy $ UniqueRemoteObject iid luParent
|
||||||
|
MaybeT $ getValBy $ UniqueRemoteMessageIdent roid
|
||||||
for_ mrm $ \ rm -> do
|
for_ mrm $ \ rm -> do
|
||||||
let mid = remoteMessageRest rm
|
let mid = remoteMessageRest rm
|
||||||
m <- lift $ getJust mid
|
m <- lift $ getJust mid
|
||||||
|
@ -257,7 +259,8 @@ projectCreateNoteF now shrRecip prjRecip author body (Note mluNote _ _ muParent
|
||||||
Right p@(ObjURI hParent luParent) -> do
|
Right p@(ObjURI hParent luParent) -> do
|
||||||
mrm <- lift $ runMaybeT $ do
|
mrm <- lift $ runMaybeT $ do
|
||||||
iid <- MaybeT $ getKeyBy $ UniqueInstance hParent
|
iid <- MaybeT $ getKeyBy $ UniqueInstance hParent
|
||||||
MaybeT $ getValBy $ UniqueRemoteMessageIdent iid luParent
|
roid <- MaybeT $ getKeyBy $ UniqueRemoteObject iid luParent
|
||||||
|
MaybeT $ getValBy $ UniqueRemoteMessageIdent roid
|
||||||
case mrm of
|
case mrm of
|
||||||
Just rm -> Left <$> do
|
Just rm -> Left <$> do
|
||||||
let mid = remoteMessageRest rm
|
let mid = remoteMessageRest rm
|
||||||
|
@ -287,10 +290,11 @@ projectCreateNoteF now shrRecip prjRecip author body (Note mluNote _ _ muParent
|
||||||
_ -> Nothing
|
_ -> Nothing
|
||||||
, messageRoot = did
|
, messageRoot = did
|
||||||
}
|
}
|
||||||
|
roid2 <-
|
||||||
|
either entityKey id <$> insertBy' (RemoteObject iidAuthor luNote)
|
||||||
mrmid <- insertUnique RemoteMessage
|
mrmid <- insertUnique RemoteMessage
|
||||||
{ remoteMessageAuthor = raidAuthor
|
{ remoteMessageAuthor = raidAuthor
|
||||||
, remoteMessageInstance = iidAuthor
|
, remoteMessageIdent = roid2
|
||||||
, remoteMessageIdent = luNote
|
|
||||||
, remoteMessageRest = mid
|
, remoteMessageRest = mid
|
||||||
, remoteMessageCreate = ractid
|
, remoteMessageCreate = ractid
|
||||||
, remoteMessageLostParent =
|
, remoteMessageLostParent =
|
||||||
|
|
|
@ -93,15 +93,16 @@ getNode getdid mid = do
|
||||||
s <- getJust $ personIdent p
|
s <- getJust $ personIdent p
|
||||||
return $ MessageTreeNodeLocal lmid s
|
return $ MessageTreeNodeLocal lmid s
|
||||||
(Nothing, Just (Entity _rmid rm)) -> do
|
(Nothing, Just (Entity _rmid rm)) -> do
|
||||||
rs <- getJust $ remoteMessageAuthor rm
|
ra <- getJust $ remoteMessageAuthor rm
|
||||||
ro <- getJust $ remoteActorIdent rs
|
roA <- getJust $ remoteActorIdent ra
|
||||||
i <- getJust $ remoteObjectInstance ro
|
roM <- getJust $ remoteMessageIdent rm
|
||||||
|
i <- getJust $ remoteObjectInstance roA
|
||||||
return $
|
return $
|
||||||
MessageTreeNodeRemote
|
MessageTreeNodeRemote
|
||||||
(instanceHost i)
|
(instanceHost i)
|
||||||
(remoteMessageIdent rm)
|
(remoteObjectIdent roM)
|
||||||
(remoteObjectIdent ro)
|
(remoteObjectIdent roA)
|
||||||
(remoteActorName rs)
|
(remoteActorName ra)
|
||||||
return $ MessageTreeNode mid m author
|
return $ MessageTreeNode mid m author
|
||||||
|
|
||||||
{-
|
{-
|
||||||
|
|
|
@ -1472,6 +1472,40 @@ changes hLocal ctx =
|
||||||
Unique "UniqueTicketUnderProjectAuthor" ["author"]
|
Unique "UniqueTicketUnderProjectAuthor" ["author"]
|
||||||
-- 226
|
-- 226
|
||||||
, removeUnique "TicketUnderProject" "UniqueTicketUnderProject"
|
, removeUnique "TicketUnderProject" "UniqueTicketUnderProject"
|
||||||
|
-- 227
|
||||||
|
, addFieldRefRequired''
|
||||||
|
"RemoteMessage"
|
||||||
|
(do iid <- insert $ Instance227 $ Authority "227.fake.fake" Nothing
|
||||||
|
insertEntity $ RemoteObject227 iid $ LocalURI "/fake/227"
|
||||||
|
)
|
||||||
|
(Just $ \ (Entity roidTemp roTemp) -> do
|
||||||
|
rmids <- selectList ([] :: [Filter RemoteMessage227]) []
|
||||||
|
for_ rmids $ \ (Entity rmid rm) -> do
|
||||||
|
let iid = remoteMessage227Instance rm
|
||||||
|
lu = remoteMessage227Ident rm
|
||||||
|
roid <- insert $ RemoteObject227 iid lu
|
||||||
|
update rmid [RemoteMessage227IdentNew =. roid]
|
||||||
|
delete roidTemp
|
||||||
|
delete $ remoteObject227Instance roTemp
|
||||||
|
)
|
||||||
|
"identNew"
|
||||||
|
"RemoteObject"
|
||||||
|
-- 228
|
||||||
|
, addUnique "RemoteMessage" $
|
||||||
|
Unique "UniqueRemoteMessageIdentNew" ["identNew"]
|
||||||
|
-- 229
|
||||||
|
, removeUnique "RemoteMessage" "UniqueRemoteMessageIdent"
|
||||||
|
-- 230
|
||||||
|
, renameUnique
|
||||||
|
"RemoteMessage"
|
||||||
|
"UniqueRemoteMessageIdentNew"
|
||||||
|
"UniqueRemoteMessageIdent"
|
||||||
|
-- 231
|
||||||
|
, removeField "RemoteMessage" "instance"
|
||||||
|
-- 232
|
||||||
|
, removeField "RemoteMessage" "ident"
|
||||||
|
-- 233
|
||||||
|
, renameField "RemoteMessage" "identNew" "ident"
|
||||||
]
|
]
|
||||||
|
|
||||||
migrateDB
|
migrateDB
|
||||||
|
|
|
@ -176,6 +176,10 @@ module Vervis.Migration.Model
|
||||||
, RemoteDiscussion215Generic (..)
|
, RemoteDiscussion215Generic (..)
|
||||||
, model_2020_02_09
|
, model_2020_02_09
|
||||||
, TicketUnderProject223Generic (..)
|
, TicketUnderProject223Generic (..)
|
||||||
|
, Instance227Generic (..)
|
||||||
|
, RemoteObject227Generic (..)
|
||||||
|
, RemoteMessage227
|
||||||
|
, RemoteMessage227Generic (..)
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
|
|
||||||
|
@ -343,3 +347,6 @@ model_2020_02_09 = $(schema "2020_02_09_tup")
|
||||||
|
|
||||||
makeEntitiesMigration "223"
|
makeEntitiesMigration "223"
|
||||||
$(modelFile "migrations/2020_02_09_tup_mig.model")
|
$(modelFile "migrations/2020_02_09_tup_mig.model")
|
||||||
|
|
||||||
|
makeEntitiesMigration "227"
|
||||||
|
$(modelFile "migrations/2020_02_10_rm_point_to_ro.model")
|
||||||
|
|
Loading…
Reference in a new issue