mirror of
https://code.naskya.net/repos/ndqEd
synced 2025-01-10 11:26:45 +09:00
DB: Add received::UTCTime field to InboxItem
To record *when* an activity, local or remote, was inserted into the specific inbox. I'm surprised I haven't been keeping that data until now :P
This commit is contained in:
parent
c5bc60d9fa
commit
4269385e15
6 changed files with 26 additions and 21 deletions
|
@ -1441,9 +1441,9 @@ createTicketTrackerC (Entity pidUser personUser) senderActor summary audience tr
|
||||||
-- Deliver the Follow and Accept by simply manually inserting them to
|
-- Deliver the Follow and Accept by simply manually inserting them to
|
||||||
-- deck and sender inboxes respectively
|
-- deck and sender inboxes respectively
|
||||||
lift $ do
|
lift $ do
|
||||||
ibiidF <- insert $ InboxItem False
|
ibiidF <- insert $ InboxItem False now
|
||||||
insert_ $ InboxItemLocal ibidDeck obiidFollow ibiidF
|
insert_ $ InboxItemLocal ibidDeck obiidFollow ibiidF
|
||||||
ibiidA <- insert $ InboxItem False
|
ibiidA <- insert $ InboxItem False now
|
||||||
insert_ $ InboxItemLocal (actorInbox senderActor) obiidAccept ibiidA
|
insert_ $ InboxItemLocal (actorInbox senderActor) obiidAccept ibiidA
|
||||||
|
|
||||||
-- Return instructions for HTTP delivery to remote recipients
|
-- Return instructions for HTTP delivery to remote recipients
|
||||||
|
@ -1634,6 +1634,7 @@ followC (Entity pidSender personSender) summary audience follow@(AP.Follow uObje
|
||||||
federation <- asksSite $ appFederation . appSettings
|
federation <- asksSite $ appFederation . appSettings
|
||||||
unless (federation || null remoteRecips) $
|
unless (federation || null remoteRecips) $
|
||||||
throwE "Federation disabled, but remote recipients specified"
|
throwE "Federation disabled, but remote recipients specified"
|
||||||
|
now <- liftIO getCurrentTime
|
||||||
senderHash <- encodeKeyHashid pidSender
|
senderHash <- encodeKeyHashid pidSender
|
||||||
mfollowee <- do
|
mfollowee <- do
|
||||||
let ObjURI h luObject = uObject
|
let ObjURI h luObject = uObject
|
||||||
|
@ -1665,7 +1666,7 @@ followC (Entity pidSender personSender) summary audience follow@(AP.Follow uObje
|
||||||
actorSender <- lift $ getJust actorSenderID
|
actorSender <- lift $ getJust actorSenderID
|
||||||
let ibidSender = actorInbox actorSender
|
let ibidSender = actorInbox actorSender
|
||||||
obidSender = actorOutbox actorSender
|
obidSender = actorOutbox actorSender
|
||||||
(obiidFollow, doc, luFollow) <- lift $ insertFollowToOutbox senderHash obidSender blinded
|
(obiidFollow, doc, luFollow) <- lift $ insertFollowToOutbox now senderHash obidSender blinded
|
||||||
case mfollowee of
|
case mfollowee of
|
||||||
Nothing -> lift $ insert_ $ FollowRemoteRequest pidSender uObject muContext (not hide) obiidFollow
|
Nothing -> lift $ insert_ $ FollowRemoteRequest pidSender uObject muContext (not hide) obiidFollow
|
||||||
Just (followee, actorRecip) -> do
|
Just (followee, actorRecip) -> do
|
||||||
|
@ -1675,8 +1676,8 @@ followC (Entity pidSender personSender) summary audience follow@(AP.Follow uObje
|
||||||
obiidAccept <- lift $ insertAcceptToOutbox senderHash luFollow actorRecip obidRecip
|
obiidAccept <- lift $ insertAcceptToOutbox senderHash luFollow actorRecip obidRecip
|
||||||
let ibidRecip = actorInbox actorRecipDB
|
let ibidRecip = actorInbox actorRecipDB
|
||||||
fsid = fromMaybe (actorFollowers actorRecipDB) mfsid
|
fsid = fromMaybe (actorFollowers actorRecipDB) mfsid
|
||||||
deliverFollowLocal actorSenderID fsid unread obiidFollow obiidAccept ibidRecip
|
deliverFollowLocal now actorSenderID fsid unread obiidFollow obiidAccept ibidRecip
|
||||||
lift $ deliverAcceptLocal obiidAccept ibidSender
|
lift $ deliverAcceptLocal now obiidAccept ibidSender
|
||||||
remotesHttp <- lift $ deliverRemoteDB'' fwdHosts obiidFollow remoteRecips []
|
remotesHttp <- lift $ deliverRemoteDB'' fwdHosts obiidFollow remoteRecips []
|
||||||
return (obiidFollow, doc, remotesHttp)
|
return (obiidFollow, doc, remotesHttp)
|
||||||
lift $ forkWorker "Outbox POST handler: async HTTP delivery" $ deliverRemoteHttp' fwdHosts obiidFollow doc remotesHttp
|
lift $ forkWorker "Outbox POST handler: async HTTP delivery" $ deliverRemoteHttp' fwdHosts obiidFollow doc remotesHttp
|
||||||
|
@ -1731,10 +1732,9 @@ followC (Entity pidSender personSender) summary audience follow@(AP.Follow uObje
|
||||||
fromMaybeE mticket "Follow object: No such cloth in DB"
|
fromMaybeE mticket "Follow object: No such cloth in DB"
|
||||||
return (actor, Just $ ticketFollowers ticket, False)
|
return (actor, Just $ ticketFollowers ticket, False)
|
||||||
|
|
||||||
insertFollowToOutbox senderHash obid blinded = do
|
insertFollowToOutbox now senderHash obid blinded = do
|
||||||
encodeRouteLocal <- getEncodeRouteLocal
|
encodeRouteLocal <- getEncodeRouteLocal
|
||||||
hLocal <- asksSite siteInstanceHost
|
hLocal <- asksSite siteInstanceHost
|
||||||
now <- liftIO getCurrentTime
|
|
||||||
obiid <- insertEmptyOutboxItem obid now
|
obiid <- insertEmptyOutboxItem obid now
|
||||||
obikhid <- encodeKeyHashid obiid
|
obikhid <- encodeKeyHashid obiid
|
||||||
let luFollow = encodeRouteLocal $ PersonOutboxItemR senderHash obikhid
|
let luFollow = encodeRouteLocal $ PersonOutboxItemR senderHash obikhid
|
||||||
|
@ -1791,14 +1791,14 @@ followC (Entity pidSender personSender) summary audience follow@(AP.Follow uObje
|
||||||
update obiid [OutboxItemActivity =. persistJSONObjectFromDoc doc]
|
update obiid [OutboxItemActivity =. persistJSONObjectFromDoc doc]
|
||||||
return obiid
|
return obiid
|
||||||
|
|
||||||
deliverFollowLocal aidSender fsid unread obiidF obiidA ibidRecip = do
|
deliverFollowLocal now aidSender fsid unread obiidF obiidA ibidRecip = do
|
||||||
mfid <- lift $ insertUnique $ Follow aidSender fsid (not hide) obiidF obiidA
|
mfid <- lift $ insertUnique $ Follow aidSender fsid (not hide) obiidF obiidA
|
||||||
_ <- fromMaybeE mfid "Already following this object"
|
_ <- fromMaybeE mfid "Already following this object"
|
||||||
ibiid <- lift $ insert $ InboxItem unread
|
ibiid <- lift $ insert $ InboxItem unread now
|
||||||
lift $ insert_ $ InboxItemLocal ibidRecip obiidF ibiid
|
lift $ insert_ $ InboxItemLocal ibidRecip obiidF ibiid
|
||||||
|
|
||||||
deliverAcceptLocal obiidAccept ibidAuthor = do
|
deliverAcceptLocal now obiidAccept ibidAuthor = do
|
||||||
ibiid <- insert $ InboxItem True
|
ibiid <- insert $ InboxItem True now
|
||||||
insert_ $ InboxItemLocal ibidAuthor obiidAccept ibiid
|
insert_ $ InboxItemLocal ibidAuthor obiidAccept ibiid
|
||||||
|
|
||||||
data Result
|
data Result
|
||||||
|
@ -3122,11 +3122,11 @@ pushCommitsC eperson summary push shrRepo rpRepo = do
|
||||||
( L.delete pidAuthor $ union repoPids $ union pfsPids rfsPids
|
( L.delete pidAuthor $ union repoPids $ union pfsPids rfsPids
|
||||||
, repoRemotes `unionRemotes` pfsRemotes `unionRemotes` rfsRemotes
|
, repoRemotes `unionRemotes` pfsRemotes `unionRemotes` rfsRemotes
|
||||||
)
|
)
|
||||||
ibiid <- insert $ InboxItem False
|
ibiid <- insert $ InboxItem False now
|
||||||
insert_ $ InboxItemLocal (repoInbox repo) obiid ibiid
|
insert_ $ InboxItemLocal (repoInbox repo) obiid ibiid
|
||||||
for_ pids $ \ pid -> do
|
for_ pids $ \ pid -> do
|
||||||
ibid <- personInbox <$> getJust pid
|
ibid <- personInbox <$> getJust pid
|
||||||
ibiid <- insert $ InboxItem True
|
ibiid <- insert $ InboxItem True now
|
||||||
insert_ $ InboxItemLocal ibid obiid ibiid
|
insert_ $ InboxItemLocal ibid obiid ibiid
|
||||||
return remotes
|
return remotes
|
||||||
-}
|
-}
|
||||||
|
|
|
@ -655,7 +655,8 @@ insertActivityToLocalInboxes makeInboxItem requireOwner mauthor maidAuthor recip
|
||||||
inboxIDs <-
|
inboxIDs <-
|
||||||
map (actorInbox . entityVal) <$>
|
map (actorInbox . entityVal) <$>
|
||||||
selectList [ActorId <-. localRecipients] []
|
selectList [ActorId <-. localRecipients] []
|
||||||
inboxItemIDs <- insertMany $ replicate (length inboxIDs) $ InboxItem True
|
now <- liftIO getCurrentTime
|
||||||
|
inboxItemIDs <- insertMany $ replicate (length inboxIDs) $ InboxItem True now
|
||||||
insertMany_ $ zipWith makeInboxItem inboxIDs inboxItemIDs
|
insertMany_ $ zipWith makeInboxItem inboxIDs inboxItemIDs
|
||||||
|
|
||||||
-- Return remote followers, to whom we need to deliver via HTTP
|
-- Return remote followers, to whom we need to deliver via HTTP
|
||||||
|
|
|
@ -67,7 +67,7 @@ insertToInbox' now author body ibid luAct unread = do
|
||||||
, remoteActivityContent = persistJSONFromBL $ actbBL body
|
, remoteActivityContent = persistJSONFromBL $ actbBL body
|
||||||
, remoteActivityReceived = now
|
, remoteActivityReceived = now
|
||||||
}
|
}
|
||||||
ibiid <- insert $ InboxItem unread
|
ibiid <- insert $ InboxItem unread now
|
||||||
mibrid <- insertUnique $ InboxItemRemote ibid ractid ibiid
|
mibrid <- insertUnique $ InboxItemRemote ibid ractid ibiid
|
||||||
case mibrid of
|
case mibrid of
|
||||||
Nothing -> do
|
Nothing -> do
|
||||||
|
|
|
@ -151,10 +151,11 @@ verifyLocalActivityExistsInDB actorByKey outboxItemID = do
|
||||||
throwE "Actor-in-URI and Actor-owning-the-outbox-item-in-DB mismatch"
|
throwE "Actor-in-URI and Actor-owning-the-outbox-item-in-DB mismatch"
|
||||||
|
|
||||||
insertActivityToInbox
|
insertActivityToInbox
|
||||||
:: MonadIO m => ActorId -> OutboxItemId -> ReaderT SqlBackend m Bool
|
:: MonadIO m
|
||||||
insertActivityToInbox recipActorID outboxItemID = do
|
=> UTCTime -> ActorId -> OutboxItemId -> ReaderT SqlBackend m Bool
|
||||||
|
insertActivityToInbox now recipActorID outboxItemID = do
|
||||||
inboxID <- actorInbox <$> getJust recipActorID
|
inboxID <- actorInbox <$> getJust recipActorID
|
||||||
inboxItemID <- insert $ InboxItem True
|
inboxItemID <- insert $ InboxItem True now
|
||||||
maybeItem <- insertUnique $ InboxItemLocal inboxID outboxItemID inboxItemID
|
maybeItem <- insertUnique $ InboxItemLocal inboxID outboxItemID inboxItemID
|
||||||
case maybeItem of
|
case maybeItem of
|
||||||
Nothing -> do
|
Nothing -> do
|
||||||
|
@ -171,7 +172,7 @@ postPersonInboxR recipPersonHash = postInbox handle
|
||||||
-> ActivityBody
|
-> ActivityBody
|
||||||
-> ExceptT Text Handler (Text, Maybe (ExceptT Text Worker Text))
|
-> ExceptT Text Handler (Text, Maybe (ExceptT Text Worker Text))
|
||||||
|
|
||||||
handle _ (ActivityAuthLocal authorByKey) body = (,Nothing) <$> do
|
handle now (ActivityAuthLocal authorByKey) body = (,Nothing) <$> do
|
||||||
outboxItemID <-
|
outboxItemID <-
|
||||||
parseAuthenticatedLocalActivityURI
|
parseAuthenticatedLocalActivityURI
|
||||||
authorByKey
|
authorByKey
|
||||||
|
@ -183,7 +184,7 @@ postPersonInboxR recipPersonHash = postInbox handle
|
||||||
if LocalActorPerson recipPersonID == authorByKey
|
if LocalActorPerson recipPersonID == authorByKey
|
||||||
then return "Received activity authored by self, ignoring"
|
then return "Received activity authored by self, ignoring"
|
||||||
else lift $ do
|
else lift $ do
|
||||||
inserted <- insertActivityToInbox (personActor recipPerson) outboxItemID
|
inserted <- insertActivityToInbox now (personActor recipPerson) outboxItemID
|
||||||
return $
|
return $
|
||||||
if inserted
|
if inserted
|
||||||
then "Activity inserted to recipient's inbox"
|
then "Activity inserted to recipient's inbox"
|
||||||
|
|
|
@ -2552,6 +2552,8 @@ changes hLocal ctx =
|
||||||
, renameField "CollabTopicLocalAccept" "collabNew" "collab"
|
, renameField "CollabTopicLocalAccept" "collabNew" "collab"
|
||||||
-- 451
|
-- 451
|
||||||
, addEntities model_451_collab_remote_accept
|
, addEntities model_451_collab_remote_accept
|
||||||
|
-- 452
|
||||||
|
, addFieldPrimRequired "InboxItem" defaultTime "received"
|
||||||
]
|
]
|
||||||
|
|
||||||
migrateDB
|
migrateDB
|
||||||
|
|
|
@ -77,7 +77,8 @@ OutboxItem
|
||||||
Inbox
|
Inbox
|
||||||
|
|
||||||
InboxItem
|
InboxItem
|
||||||
unread Bool
|
unread Bool
|
||||||
|
received UTCTime
|
||||||
|
|
||||||
InboxItemLocal
|
InboxItemLocal
|
||||||
inbox InboxId
|
inbox InboxId
|
||||||
|
|
Loading…
Reference in a new issue