]>
Commit | Line | Data |
---|---|---|
e71bcc0f | 1 | import * as express from 'express' |
d52eb8f6 | 2 | import { Activity } from '../../../shared/models/activitypub/activity' |
0bc22f8d | 3 | import { VideoPrivacy } from '../../../shared/models/videos' |
40ff5707 C |
4 | import { activityPubCollectionPagination } from '../../helpers/activitypub' |
5 | import { pageToStartAndCount } from '../../helpers/core-utils' | |
40ff5707 | 6 | import { ACTIVITY_PUB } from '../../initializers/constants' |
50d6de9c | 7 | import { announceActivityData, createActivityData } from '../../lib/activitypub/send' |
54e74059 | 8 | import { buildAudience } from '../../lib/activitypub/send/misc' |
e71bcc0f | 9 | import { asyncMiddleware, localAccountValidator } from '../../middlewares' |
3fd3ab2d | 10 | import { AccountModel } from '../../models/account/account' |
54e74059 | 11 | import { ActorModel } from '../../models/activitypub/actor' |
3fd3ab2d | 12 | import { VideoModel } from '../../models/video/video' |
e71bcc0f C |
13 | |
14 | const outboxRouter = express.Router() | |
15 | ||
e8e12200 | 16 | outboxRouter.get('/accounts/:name/outbox', |
e71bcc0f C |
17 | localAccountValidator, |
18 | asyncMiddleware(outboxController) | |
19 | ) | |
20 | ||
21 | // --------------------------------------------------------------------------- | |
22 | ||
23 | export { | |
24 | outboxRouter | |
25 | } | |
26 | ||
27 | // --------------------------------------------------------------------------- | |
28 | ||
29 | async function outboxController (req: express.Request, res: express.Response, next: express.NextFunction) { | |
3fd3ab2d | 30 | const account: AccountModel = res.locals.account |
50d6de9c | 31 | const actor = account.Actor |
e71bcc0f | 32 | |
c46edbc2 | 33 | const page = req.query.page || 1 |
e71bcc0f C |
34 | const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) |
35 | ||
50d6de9c | 36 | const data = await VideoModel.listAllAndSharedByActorForOutbox(actor.id, start, count) |
e71bcc0f C |
37 | const activities: Activity[] = [] |
38 | ||
54e74059 C |
39 | // Avoid too many SQL requests |
40 | const actors = data.data.map(v => v.VideoChannel.Account.Actor) | |
41 | actors.push(actor) | |
42 | ||
43 | const followersMatrix = await ActorModel.getActorsFollowerSharedInboxUrls(actors, undefined) | |
44 | ||
e71bcc0f | 45 | for (const video of data.data) { |
54e74059 | 46 | const byActor = video.VideoChannel.Account.Actor |
0bc22f8d | 47 | const createActivityAudience = buildAudience(followersMatrix[byActor.id], video.privacy === VideoPrivacy.PUBLIC) |
54e74059 | 48 | |
50d6de9c | 49 | // This is a shared video |
40ff5707 | 50 | if (video.VideoShares !== undefined && video.VideoShares.length !== 0) { |
4ba3b8ea | 51 | const videoShare = video.VideoShares[0] |
0bc22f8d | 52 | const announceAudience = buildAudience(followersMatrix[actor.id], video.privacy === VideoPrivacy.PUBLIC) |
4ba3b8ea | 53 | const announceActivity = await announceActivityData(videoShare.url, actor, video.url, undefined, announceAudience) |
40ff5707 | 54 | |
e71bcc0f C |
55 | activities.push(announceActivity) |
56 | } else { | |
7acee6f1 | 57 | const videoObject = video.toActivityPubObject() |
54e74059 | 58 | const createActivity = await createActivityData(video.url, byActor, videoObject, undefined, createActivityAudience) |
40ff5707 | 59 | |
50d6de9c | 60 | activities.push(createActivity) |
e71bcc0f C |
61 | } |
62 | } | |
63 | ||
64 | const newResult = { | |
65 | data: activities, | |
66 | total: data.total | |
67 | } | |
50d6de9c | 68 | const json = activityPubCollectionPagination(account.Actor.url + '/outbox', page, newResult) |
e71bcc0f C |
69 | |
70 | return res.json(json).end() | |
71 | } |