diff options
Diffstat (limited to 'server/lib/activitypub/send/misc.ts')
-rw-r--r-- | server/lib/activitypub/send/misc.ts | 56 |
1 files changed, 27 insertions, 29 deletions
diff --git a/server/lib/activitypub/send/misc.ts b/server/lib/activitypub/send/misc.ts index 999def701..ffc221477 100644 --- a/server/lib/activitypub/send/misc.ts +++ b/server/lib/activitypub/send/misc.ts | |||
@@ -1,19 +1,19 @@ | |||
1 | import { Transaction } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { Activity } from '../../../../shared/models/activitypub/activity' | 2 | import { Activity } from '../../../../shared/models/activitypub' |
3 | import { logger } from '../../../helpers/logger' | 3 | import { logger } from '../../../helpers' |
4 | import { ACTIVITY_PUB, database as db } from '../../../initializers' | 4 | import { ACTIVITY_PUB } from '../../../initializers' |
5 | import { AccountInstance } from '../../../models/account/account-interface' | 5 | import { AccountModel } from '../../../models/account/account' |
6 | import { VideoChannelInstance } from '../../../models/index' | 6 | import { AccountFollowModel } from '../../../models/account/account-follow' |
7 | import { VideoInstance } from '../../../models/video/video-interface' | 7 | import { VideoModel } from '../../../models/video/video' |
8 | import { | 8 | import { VideoChannelModel } from '../../../models/video/video-channel' |
9 | activitypubHttpJobScheduler, | 9 | import { VideoChannelShareModel } from '../../../models/video/video-channel-share' |
10 | ActivityPubHttpPayload | 10 | import { VideoShareModel } from '../../../models/video/video-share' |
11 | } from '../../jobs/activitypub-http-job-scheduler/activitypub-http-job-scheduler' | 11 | import { activitypubHttpJobScheduler, ActivityPubHttpPayload } from '../../jobs/activitypub-http-job-scheduler' |
12 | 12 | ||
13 | async function forwardActivity ( | 13 | async function forwardActivity ( |
14 | activity: Activity, | 14 | activity: Activity, |
15 | t: Transaction, | 15 | t: Transaction, |
16 | followersException: AccountInstance[] = [] | 16 | followersException: AccountModel[] = [] |
17 | ) { | 17 | ) { |
18 | const to = activity.to || [] | 18 | const to = activity.to || [] |
19 | const cc = activity.cc || [] | 19 | const cc = activity.cc || [] |
@@ -25,7 +25,7 @@ async function forwardActivity ( | |||
25 | } | 25 | } |
26 | } | 26 | } |
27 | 27 | ||
28 | const toAccountFollowers = await db.Account.listByFollowersUrls(followersUrls, t) | 28 | const toAccountFollowers = await AccountModel.listByFollowersUrls(followersUrls, t) |
29 | const uris = await computeFollowerUris(toAccountFollowers, followersException, t) | 29 | const uris = await computeFollowerUris(toAccountFollowers, followersException, t) |
30 | 30 | ||
31 | if (uris.length === 0) { | 31 | if (uris.length === 0) { |
@@ -45,10 +45,10 @@ async function forwardActivity ( | |||
45 | 45 | ||
46 | async function broadcastToFollowers ( | 46 | async function broadcastToFollowers ( |
47 | data: any, | 47 | data: any, |
48 | byAccount: AccountInstance, | 48 | byAccount: AccountModel, |
49 | toAccountFollowers: AccountInstance[], | 49 | toAccountFollowers: AccountModel[], |
50 | t: Transaction, | 50 | t: Transaction, |
51 | followersException: AccountInstance[] = [] | 51 | followersException: AccountModel[] = [] |
52 | ) { | 52 | ) { |
53 | const uris = await computeFollowerUris(toAccountFollowers, followersException, t) | 53 | const uris = await computeFollowerUris(toAccountFollowers, followersException, t) |
54 | if (uris.length === 0) { | 54 | if (uris.length === 0) { |
@@ -67,7 +67,7 @@ async function broadcastToFollowers ( | |||
67 | return activitypubHttpJobScheduler.createJob(t, 'activitypubHttpBroadcastHandler', jobPayload) | 67 | return activitypubHttpJobScheduler.createJob(t, 'activitypubHttpBroadcastHandler', jobPayload) |
68 | } | 68 | } |
69 | 69 | ||
70 | async function unicastTo (data: any, byAccount: AccountInstance, toAccountUrl: string, t: Transaction) { | 70 | async function unicastTo (data: any, byAccount: AccountModel, toAccountUrl: string, t: Transaction) { |
71 | logger.debug('Creating unicast job.', { uri: toAccountUrl }) | 71 | logger.debug('Creating unicast job.', { uri: toAccountUrl }) |
72 | 72 | ||
73 | const jobPayload: ActivityPubHttpPayload = { | 73 | const jobPayload: ActivityPubHttpPayload = { |
@@ -79,42 +79,42 @@ async function unicastTo (data: any, byAccount: AccountInstance, toAccountUrl: s | |||
79 | return activitypubHttpJobScheduler.createJob(t, 'activitypubHttpUnicastHandler', jobPayload) | 79 | return activitypubHttpJobScheduler.createJob(t, 'activitypubHttpUnicastHandler', jobPayload) |
80 | } | 80 | } |
81 | 81 | ||
82 | function getOriginVideoAudience (video: VideoInstance, accountsInvolvedInVideo: AccountInstance[]) { | 82 | function getOriginVideoAudience (video: VideoModel, accountsInvolvedInVideo: AccountModel[]) { |
83 | return { | 83 | return { |
84 | to: [ video.VideoChannel.Account.url ], | 84 | to: [ video.VideoChannel.Account.url ], |
85 | cc: accountsInvolvedInVideo.map(a => a.followersUrl) | 85 | cc: accountsInvolvedInVideo.map(a => a.followersUrl) |
86 | } | 86 | } |
87 | } | 87 | } |
88 | 88 | ||
89 | function getOriginVideoChannelAudience (videoChannel: VideoChannelInstance, accountsInvolved: AccountInstance[]) { | 89 | function getOriginVideoChannelAudience (videoChannel: VideoChannelModel, accountsInvolved: AccountModel[]) { |
90 | return { | 90 | return { |
91 | to: [ videoChannel.Account.url ], | 91 | to: [ videoChannel.Account.url ], |
92 | cc: accountsInvolved.map(a => a.followersUrl) | 92 | cc: accountsInvolved.map(a => a.followersUrl) |
93 | } | 93 | } |
94 | } | 94 | } |
95 | 95 | ||
96 | function getObjectFollowersAudience (accountsInvolvedInObject: AccountInstance[]) { | 96 | function getObjectFollowersAudience (accountsInvolvedInObject: AccountModel[]) { |
97 | return { | 97 | return { |
98 | to: accountsInvolvedInObject.map(a => a.followersUrl), | 98 | to: accountsInvolvedInObject.map(a => a.followersUrl), |
99 | cc: [] | 99 | cc: [] |
100 | } | 100 | } |
101 | } | 101 | } |
102 | 102 | ||
103 | async function getAccountsInvolvedInVideo (video: VideoInstance, t: Transaction) { | 103 | async function getAccountsInvolvedInVideo (video: VideoModel, t: Transaction) { |
104 | const accountsToForwardView = await db.VideoShare.loadAccountsByShare(video.id, t) | 104 | const accountsToForwardView = await VideoShareModel.loadAccountsByShare(video.id, t) |
105 | accountsToForwardView.push(video.VideoChannel.Account) | 105 | accountsToForwardView.push(video.VideoChannel.Account) |
106 | 106 | ||
107 | return accountsToForwardView | 107 | return accountsToForwardView |
108 | } | 108 | } |
109 | 109 | ||
110 | async function getAccountsInvolvedInVideoChannel (videoChannel: VideoChannelInstance, t: Transaction) { | 110 | async function getAccountsInvolvedInVideoChannel (videoChannel: VideoChannelModel, t: Transaction) { |
111 | const accountsToForwardView = await db.VideoChannelShare.loadAccountsByShare(videoChannel.id, t) | 111 | const accountsToForwardView = await VideoChannelShareModel.loadAccountsByShare(videoChannel.id, t) |
112 | accountsToForwardView.push(videoChannel.Account) | 112 | accountsToForwardView.push(videoChannel.Account) |
113 | 113 | ||
114 | return accountsToForwardView | 114 | return accountsToForwardView |
115 | } | 115 | } |
116 | 116 | ||
117 | async function getAudience (accountSender: AccountInstance, t: Transaction, isPublic = true) { | 117 | async function getAudience (accountSender: AccountModel, t: Transaction, isPublic = true) { |
118 | const followerInboxUrls = await accountSender.getFollowerSharedInboxUrls(t) | 118 | const followerInboxUrls = await accountSender.getFollowerSharedInboxUrls(t) |
119 | 119 | ||
120 | // Thanks Mastodon: https://github.com/tootsuite/mastodon/blob/master/app/lib/activitypub/tag_manager.rb#L47 | 120 | // Thanks Mastodon: https://github.com/tootsuite/mastodon/blob/master/app/lib/activitypub/tag_manager.rb#L47 |
@@ -132,14 +132,12 @@ async function getAudience (accountSender: AccountInstance, t: Transaction, isPu | |||
132 | return { to, cc } | 132 | return { to, cc } |
133 | } | 133 | } |
134 | 134 | ||
135 | async function computeFollowerUris (toAccountFollower: AccountInstance[], followersException: AccountInstance[], t: Transaction) { | 135 | async function computeFollowerUris (toAccountFollower: AccountModel[], followersException: AccountModel[], t: Transaction) { |
136 | const toAccountFollowerIds = toAccountFollower.map(a => a.id) | 136 | const toAccountFollowerIds = toAccountFollower.map(a => a.id) |
137 | 137 | ||
138 | const result = await db.AccountFollow.listAcceptedFollowerSharedInboxUrls(toAccountFollowerIds, t) | 138 | const result = await AccountFollowModel.listAcceptedFollowerSharedInboxUrls(toAccountFollowerIds, t) |
139 | const followersSharedInboxException = followersException.map(f => f.sharedInboxUrl) | 139 | const followersSharedInboxException = followersException.map(f => f.sharedInboxUrl) |
140 | const uris = result.data.filter(sharedInbox => followersSharedInboxException.indexOf(sharedInbox) === -1) | 140 | return result.data.filter(sharedInbox => followersSharedInboxException.indexOf(sharedInbox) === -1) |
141 | |||
142 | return uris | ||
143 | } | 141 | } |
144 | 142 | ||
145 | // --------------------------------------------------------------------------- | 143 | // --------------------------------------------------------------------------- |