aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-30 11:31:15 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-30 11:31:15 +0100
commit25ed141c7c7631ef21d8764c1163fbf8a6591391 (patch)
tree8f556181a3369e7e4938d612d91be0af813e5067 /server/lib
parent5cd80545422bba855cc9a730a2e13cc9d982c34b (diff)
downloadPeerTube-25ed141c7c7631ef21d8764c1163fbf8a6591391.tar.gz
PeerTube-25ed141c7c7631ef21d8764c1163fbf8a6591391.tar.zst
PeerTube-25ed141c7c7631ef21d8764c1163fbf8a6591391.zip
Put activity pub sends inside transactions
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/activitypub/process/process-update.ts4
-rw-r--r--server/lib/activitypub/send/misc.ts22
-rw-r--r--server/lib/activitypub/send/send-accept.ts4
-rw-r--r--server/lib/activitypub/send/send-add.ts13
-rw-r--r--server/lib/activitypub/send/send-announce.ts27
-rw-r--r--server/lib/activitypub/send/send-create.ts26
-rw-r--r--server/lib/activitypub/send/send-delete.ts10
-rw-r--r--server/lib/activitypub/send/send-follow.ts6
-rw-r--r--server/lib/activitypub/send/send-like.ts24
-rw-r--r--server/lib/activitypub/send/send-undo.ts31
-rw-r--r--server/lib/activitypub/send/send-update.ts12
11 files changed, 96 insertions, 83 deletions
diff --git a/server/lib/activitypub/process/process-update.ts b/server/lib/activitypub/process/process-update.ts
index 84a62de9f..11c6de8f5 100644
--- a/server/lib/activitypub/process/process-update.ts
+++ b/server/lib/activitypub/process/process-update.ts
@@ -1,3 +1,4 @@
1import * as Bluebird from 'bluebird'
1import { VideoChannelObject, VideoTorrentObject } from '../../../../shared' 2import { VideoChannelObject, VideoTorrentObject } from '../../../../shared'
2import { ActivityUpdate } from '../../../../shared/models/activitypub/activity' 3import { ActivityUpdate } from '../../../../shared/models/activitypub/activity'
3import { retryTransactionWrapper } from '../../../helpers/database-utils' 4import { retryTransactionWrapper } from '../../../helpers/database-utils'
@@ -6,9 +7,8 @@ import { resetSequelizeInstance } from '../../../helpers/utils'
6import { database as db } from '../../../initializers' 7import { database as db } from '../../../initializers'
7import { AccountInstance } from '../../../models/account/account-interface' 8import { AccountInstance } from '../../../models/account/account-interface'
8import { VideoInstance } from '../../../models/video/video-interface' 9import { VideoInstance } from '../../../models/video/video-interface'
9import { videoActivityObjectToDBAttributes, videoFileActivityUrlToDBAttributes } from './misc'
10import Bluebird = require('bluebird')
11import { getOrCreateAccountAndServer } from '../account' 10import { getOrCreateAccountAndServer } from '../account'
11import { videoActivityObjectToDBAttributes, videoFileActivityUrlToDBAttributes } from './misc'
12 12
13async function processUpdateActivity (activity: ActivityUpdate) { 13async function processUpdateActivity (activity: ActivityUpdate) {
14 const account = await getOrCreateAccountAndServer(activity.actor) 14 const account = await getOrCreateAccountAndServer(activity.actor)
diff --git a/server/lib/activitypub/send/misc.ts b/server/lib/activitypub/send/misc.ts
index fd1add68e..999def701 100644
--- a/server/lib/activitypub/send/misc.ts
+++ b/server/lib/activitypub/send/misc.ts
@@ -25,8 +25,8 @@ async function forwardActivity (
25 } 25 }
26 } 26 }
27 27
28 const toAccountFollowers = await db.Account.listByFollowersUrls(followersUrls) 28 const toAccountFollowers = await db.Account.listByFollowersUrls(followersUrls, t)
29 const uris = await computeFollowerUris(toAccountFollowers, followersException) 29 const uris = await computeFollowerUris(toAccountFollowers, followersException, t)
30 30
31 if (uris.length === 0) { 31 if (uris.length === 0) {
32 logger.info('0 followers for %s, no forwarding.', toAccountFollowers.map(a => a.id).join(', ')) 32 logger.info('0 followers for %s, no forwarding.', toAccountFollowers.map(a => a.id).join(', '))
@@ -50,7 +50,7 @@ async function broadcastToFollowers (
50 t: Transaction, 50 t: Transaction,
51 followersException: AccountInstance[] = [] 51 followersException: AccountInstance[] = []
52) { 52) {
53 const uris = await computeFollowerUris(toAccountFollowers, followersException) 53 const uris = await computeFollowerUris(toAccountFollowers, followersException, t)
54 if (uris.length === 0) { 54 if (uris.length === 0) {
55 logger.info('0 followers for %s, no broadcasting.', toAccountFollowers.map(a => a.id).join(', ')) 55 logger.info('0 followers for %s, no broadcasting.', toAccountFollowers.map(a => a.id).join(', '))
56 return undefined 56 return undefined
@@ -100,22 +100,22 @@ function getObjectFollowersAudience (accountsInvolvedInObject: AccountInstance[]
100 } 100 }
101} 101}
102 102
103async function getAccountsInvolvedInVideo (video: VideoInstance) { 103async function getAccountsInvolvedInVideo (video: VideoInstance, t: Transaction) {
104 const accountsToForwardView = await db.VideoShare.loadAccountsByShare(video.id) 104 const accountsToForwardView = await db.VideoShare.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
110async function getAccountsInvolvedInVideoChannel (videoChannel: VideoChannelInstance) { 110async function getAccountsInvolvedInVideoChannel (videoChannel: VideoChannelInstance, t: Transaction) {
111 const accountsToForwardView = await db.VideoChannelShare.loadAccountsByShare(videoChannel.id) 111 const accountsToForwardView = await db.VideoChannelShare.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
117async function getAudience (accountSender: AccountInstance, isPublic = true) { 117async function getAudience (accountSender: AccountInstance, t: Transaction, isPublic = true) {
118 const followerInboxUrls = await accountSender.getFollowerSharedInboxUrls() 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
121 let to = [] 121 let to = []
@@ -132,10 +132,10 @@ async function getAudience (accountSender: AccountInstance, isPublic = true) {
132 return { to, cc } 132 return { to, cc }
133} 133}
134 134
135async function computeFollowerUris (toAccountFollower: AccountInstance[], followersException: AccountInstance[]) { 135async function computeFollowerUris (toAccountFollower: AccountInstance[], followersException: AccountInstance[], 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) 138 const result = await db.AccountFollow.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 const uris = result.data.filter(sharedInbox => followersSharedInboxException.indexOf(sharedInbox) === -1)
141 141
diff --git a/server/lib/activitypub/send/send-accept.ts b/server/lib/activitypub/send/send-accept.ts
index eeab19ed0..d3f8fbe38 100644
--- a/server/lib/activitypub/send/send-accept.ts
+++ b/server/lib/activitypub/send/send-accept.ts
@@ -10,7 +10,7 @@ async function sendAccept (accountFollow: AccountFollowInstance, t: Transaction)
10 const me = accountFollow.AccountFollowing 10 const me = accountFollow.AccountFollowing
11 11
12 const url = getAccountFollowAcceptActivityPubUrl(accountFollow) 12 const url = getAccountFollowAcceptActivityPubUrl(accountFollow)
13 const data = await acceptActivityData(url, me) 13 const data = acceptActivityData(url, me)
14 14
15 return unicastTo(data, me, follower.inboxUrl, t) 15 return unicastTo(data, me, follower.inboxUrl, t)
16} 16}
@@ -23,7 +23,7 @@ export {
23 23
24// --------------------------------------------------------------------------- 24// ---------------------------------------------------------------------------
25 25
26async function acceptActivityData (url: string, byAccount: AccountInstance) { 26function acceptActivityData (url: string, byAccount: AccountInstance) {
27 const activity: ActivityAccept = { 27 const activity: ActivityAccept = {
28 type: 'Accept', 28 type: 'Accept',
29 id: url, 29 id: url,
diff --git a/server/lib/activitypub/send/send-add.ts b/server/lib/activitypub/send/send-add.ts
index 3012b7533..d8ac2853e 100644
--- a/server/lib/activitypub/send/send-add.ts
+++ b/server/lib/activitypub/send/send-add.ts
@@ -8,15 +8,22 @@ async function sendAddVideo (video: VideoInstance, t: Transaction) {
8 const byAccount = video.VideoChannel.Account 8 const byAccount = video.VideoChannel.Account
9 9
10 const videoObject = video.toActivityPubObject() 10 const videoObject = video.toActivityPubObject()
11 const data = await addActivityData(video.url, byAccount, video, video.VideoChannel.url, videoObject) 11 const data = await addActivityData(video.url, byAccount, video, video.VideoChannel.url, videoObject, t)
12 12
13 return broadcastToFollowers(data, byAccount, [ byAccount ], t) 13 return broadcastToFollowers(data, byAccount, [ byAccount ], t)
14} 14}
15 15
16async function addActivityData (url: string, byAccount: AccountInstance, video: VideoInstance, target: string, object: any) { 16async function addActivityData (
17 url: string,
18 byAccount: AccountInstance,
19 video: VideoInstance,
20 target: string,
21 object: any,
22 t: Transaction
23) {
17 const videoPublic = video.privacy === VideoPrivacy.PUBLIC 24 const videoPublic = video.privacy === VideoPrivacy.PUBLIC
18 25
19 const { to, cc } = await getAudience(byAccount, videoPublic) 26 const { to, cc } = await getAudience(byAccount, t, videoPublic)
20 const activity: ActivityAdd = { 27 const activity: ActivityAdd = {
21 type: 'Add', 28 type: 'Add',
22 id: url, 29 id: url,
diff --git a/server/lib/activitypub/send/send-announce.ts b/server/lib/activitypub/send/send-announce.ts
index efc23af46..3acf604cd 100644
--- a/server/lib/activitypub/send/send-announce.ts
+++ b/server/lib/activitypub/send/send-announce.ts
@@ -21,11 +21,11 @@ async function buildVideoAnnounceToFollowers (byAccount: AccountInstance, video:
21 const url = getAnnounceActivityPubUrl(video.url, byAccount) 21 const url = getAnnounceActivityPubUrl(video.url, byAccount)
22 22
23 const videoChannel = video.VideoChannel 23 const videoChannel = video.VideoChannel
24 const announcedActivity = await addActivityData(url, videoChannel.Account, video, videoChannel.url, video.toActivityPubObject()) 24 const announcedActivity = await addActivityData(url, videoChannel.Account, video, videoChannel.url, video.toActivityPubObject(), t)
25 25
26 const accountsToForwardView = await getAccountsInvolvedInVideo(video) 26 const accountsToForwardView = await getAccountsInvolvedInVideo(video, t)
27 const audience = getObjectFollowersAudience(accountsToForwardView) 27 const audience = getObjectFollowersAudience(accountsToForwardView)
28 const data = await announceActivityData(url, byAccount, announcedActivity, audience) 28 const data = await announceActivityData(url, byAccount, announcedActivity, t, audience)
29 29
30 return data 30 return data
31} 31}
@@ -40,22 +40,22 @@ async function sendVideoAnnounceToOrigin (byAccount: AccountInstance, video: Vid
40 const url = getAnnounceActivityPubUrl(video.url, byAccount) 40 const url = getAnnounceActivityPubUrl(video.url, byAccount)
41 41
42 const videoChannel = video.VideoChannel 42 const videoChannel = video.VideoChannel
43 const announcedActivity = await addActivityData(url, videoChannel.Account, video, videoChannel.url, video.toActivityPubObject()) 43 const announcedActivity = await addActivityData(url, videoChannel.Account, video, videoChannel.url, video.toActivityPubObject(), t)
44 44
45 const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video) 45 const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t)
46 const audience = getOriginVideoAudience(video, accountsInvolvedInVideo) 46 const audience = getOriginVideoAudience(video, accountsInvolvedInVideo)
47 const data = await createActivityData(url, byAccount, announcedActivity, audience) 47 const data = await createActivityData(url, byAccount, announcedActivity, t, audience)
48 48
49 return unicastTo(data, byAccount, videoChannel.Account.sharedInboxUrl, t) 49 return unicastTo(data, byAccount, videoChannel.Account.sharedInboxUrl, t)
50} 50}
51 51
52async function buildVideoChannelAnnounceToFollowers (byAccount: AccountInstance, videoChannel: VideoChannelInstance, t: Transaction) { 52async function buildVideoChannelAnnounceToFollowers (byAccount: AccountInstance, videoChannel: VideoChannelInstance, t: Transaction) {
53 const url = getAnnounceActivityPubUrl(videoChannel.url, byAccount) 53 const url = getAnnounceActivityPubUrl(videoChannel.url, byAccount)
54 const announcedActivity = await createActivityData(url, videoChannel.Account, videoChannel.toActivityPubObject()) 54 const announcedActivity = await createActivityData(url, videoChannel.Account, videoChannel.toActivityPubObject(), t)
55 55
56 const accountsToForwardView = await getAccountsInvolvedInVideoChannel(videoChannel) 56 const accountsToForwardView = await getAccountsInvolvedInVideoChannel(videoChannel, t)
57 const audience = getObjectFollowersAudience(accountsToForwardView) 57 const audience = getObjectFollowersAudience(accountsToForwardView)
58 const data = await announceActivityData(url, byAccount, announcedActivity, audience) 58 const data = await announceActivityData(url, byAccount, announcedActivity, t, audience)
59 59
60 return data 60 return data
61} 61}
@@ -68,11 +68,11 @@ async function sendVideoChannelAnnounceToFollowers (byAccount: AccountInstance,
68 68
69async function sendVideoChannelAnnounceToOrigin (byAccount: AccountInstance, videoChannel: VideoChannelInstance, t: Transaction) { 69async function sendVideoChannelAnnounceToOrigin (byAccount: AccountInstance, videoChannel: VideoChannelInstance, t: Transaction) {
70 const url = getAnnounceActivityPubUrl(videoChannel.url, byAccount) 70 const url = getAnnounceActivityPubUrl(videoChannel.url, byAccount)
71 const announcedActivity = await createActivityData(url, videoChannel.Account, videoChannel.toActivityPubObject()) 71 const announcedActivity = await createActivityData(url, videoChannel.Account, videoChannel.toActivityPubObject(), t)
72 72
73 const accountsInvolvedInVideo = await getAccountsInvolvedInVideoChannel(videoChannel) 73 const accountsInvolvedInVideo = await getAccountsInvolvedInVideoChannel(videoChannel, t)
74 const audience = getOriginVideoChannelAudience(videoChannel, accountsInvolvedInVideo) 74 const audience = getOriginVideoChannelAudience(videoChannel, accountsInvolvedInVideo)
75 const data = await createActivityData(url, byAccount, announcedActivity, audience) 75 const data = await createActivityData(url, byAccount, announcedActivity, t, audience)
76 76
77 return unicastTo(data, byAccount, videoChannel.Account.sharedInboxUrl, t) 77 return unicastTo(data, byAccount, videoChannel.Account.sharedInboxUrl, t)
78} 78}
@@ -81,10 +81,11 @@ async function announceActivityData (
81 url: string, 81 url: string,
82 byAccount: AccountInstance, 82 byAccount: AccountInstance,
83 object: ActivityCreate | ActivityAdd, 83 object: ActivityCreate | ActivityAdd,
84 t: Transaction,
84 audience?: ActivityAudience 85 audience?: ActivityAudience
85) { 86) {
86 if (!audience) { 87 if (!audience) {
87 audience = await getAudience(byAccount) 88 audience = await getAudience(byAccount, t)
88 } 89 }
89 90
90 const activity: ActivityAnnounce = { 91 const activity: ActivityAnnounce = {
diff --git a/server/lib/activitypub/send/send-create.ts b/server/lib/activitypub/send/send-create.ts
index bf66606c1..a34d3776c 100644
--- a/server/lib/activitypub/send/send-create.ts
+++ b/server/lib/activitypub/send/send-create.ts
@@ -8,8 +8,8 @@ import {
8 broadcastToFollowers, 8 broadcastToFollowers,
9 getAccountsInvolvedInVideo, 9 getAccountsInvolvedInVideo,
10 getAudience, 10 getAudience,
11 getOriginVideoAudience,
12 getObjectFollowersAudience, 11 getObjectFollowersAudience,
12 getOriginVideoAudience,
13 unicastTo 13 unicastTo
14} from './misc' 14} from './misc'
15 15
@@ -17,7 +17,7 @@ async function sendCreateVideoChannel (videoChannel: VideoChannelInstance, t: Tr
17 const byAccount = videoChannel.Account 17 const byAccount = videoChannel.Account
18 18
19 const videoChannelObject = videoChannel.toActivityPubObject() 19 const videoChannelObject = videoChannel.toActivityPubObject()
20 const data = await createActivityData(videoChannel.url, byAccount, videoChannelObject) 20 const data = await createActivityData(videoChannel.url, byAccount, videoChannelObject, t)
21 21
22 return broadcastToFollowers(data, byAccount, [ byAccount ], t) 22 return broadcastToFollowers(data, byAccount, [ byAccount ], t)
23} 23}
@@ -26,7 +26,7 @@ async function sendVideoAbuse (byAccount: AccountInstance, videoAbuse: VideoAbus
26 const url = getVideoAbuseActivityPubUrl(videoAbuse) 26 const url = getVideoAbuseActivityPubUrl(videoAbuse)
27 27
28 const audience = { to: [ video.VideoChannel.Account.url ], cc: [] } 28 const audience = { to: [ video.VideoChannel.Account.url ], cc: [] }
29 const data = await createActivityData(url, byAccount, videoAbuse.toActivityPubObject(), audience) 29 const data = await createActivityData(url, byAccount, videoAbuse.toActivityPubObject(), t, audience)
30 30
31 return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) 31 return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t)
32} 32}
@@ -35,9 +35,9 @@ async function sendCreateViewToOrigin (byAccount: AccountInstance, video: VideoI
35 const url = getVideoViewActivityPubUrl(byAccount, video) 35 const url = getVideoViewActivityPubUrl(byAccount, video)
36 const viewActivity = createViewActivityData(byAccount, video) 36 const viewActivity = createViewActivityData(byAccount, video)
37 37
38 const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video) 38 const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t)
39 const audience = getOriginVideoAudience(video, accountsInvolvedInVideo) 39 const audience = getOriginVideoAudience(video, accountsInvolvedInVideo)
40 const data = await createActivityData(url, byAccount, viewActivity, audience) 40 const data = await createActivityData(url, byAccount, viewActivity, t, audience)
41 41
42 return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) 42 return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t)
43} 43}
@@ -46,9 +46,9 @@ async function sendCreateViewToVideoFollowers (byAccount: AccountInstance, video
46 const url = getVideoViewActivityPubUrl(byAccount, video) 46 const url = getVideoViewActivityPubUrl(byAccount, video)
47 const viewActivity = createViewActivityData(byAccount, video) 47 const viewActivity = createViewActivityData(byAccount, video)
48 48
49 const accountsToForwardView = await getAccountsInvolvedInVideo(video) 49 const accountsToForwardView = await getAccountsInvolvedInVideo(video, t)
50 const audience = getObjectFollowersAudience(accountsToForwardView) 50 const audience = getObjectFollowersAudience(accountsToForwardView)
51 const data = await createActivityData(url, byAccount, viewActivity, audience) 51 const data = await createActivityData(url, byAccount, viewActivity, t, audience)
52 52
53 // Use the server account to send the view, because it could be an unregistered account 53 // Use the server account to send the view, because it could be an unregistered account
54 const serverAccount = await getServerAccount() 54 const serverAccount = await getServerAccount()
@@ -60,9 +60,9 @@ async function sendCreateDislikeToOrigin (byAccount: AccountInstance, video: Vid
60 const url = getVideoDislikeActivityPubUrl(byAccount, video) 60 const url = getVideoDislikeActivityPubUrl(byAccount, video)
61 const dislikeActivity = createDislikeActivityData(byAccount, video) 61 const dislikeActivity = createDislikeActivityData(byAccount, video)
62 62
63 const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video) 63 const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t)
64 const audience = getOriginVideoAudience(video, accountsInvolvedInVideo) 64 const audience = getOriginVideoAudience(video, accountsInvolvedInVideo)
65 const data = await createActivityData(url, byAccount, dislikeActivity, audience) 65 const data = await createActivityData(url, byAccount, dislikeActivity, t, audience)
66 66
67 return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) 67 return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t)
68} 68}
@@ -71,17 +71,17 @@ async function sendCreateDislikeToVideoFollowers (byAccount: AccountInstance, vi
71 const url = getVideoDislikeActivityPubUrl(byAccount, video) 71 const url = getVideoDislikeActivityPubUrl(byAccount, video)
72 const dislikeActivity = createDislikeActivityData(byAccount, video) 72 const dislikeActivity = createDislikeActivityData(byAccount, video)
73 73
74 const accountsToForwardView = await getAccountsInvolvedInVideo(video) 74 const accountsToForwardView = await getAccountsInvolvedInVideo(video, t)
75 const audience = getObjectFollowersAudience(accountsToForwardView) 75 const audience = getObjectFollowersAudience(accountsToForwardView)
76 const data = await createActivityData(url, byAccount, dislikeActivity, audience) 76 const data = await createActivityData(url, byAccount, dislikeActivity, t, audience)
77 77
78 const followersException = [ byAccount ] 78 const followersException = [ byAccount ]
79 return broadcastToFollowers(data, byAccount, accountsToForwardView, t, followersException) 79 return broadcastToFollowers(data, byAccount, accountsToForwardView, t, followersException)
80} 80}
81 81
82async function createActivityData (url: string, byAccount: AccountInstance, object: any, audience?: ActivityAudience) { 82async function createActivityData (url: string, byAccount: AccountInstance, object: any, t: Transaction, audience?: ActivityAudience) {
83 if (!audience) { 83 if (!audience) {
84 audience = await getAudience(byAccount) 84 audience = await getAudience(byAccount, t)
85 } 85 }
86 86
87 const activity: ActivityCreate = { 87 const activity: ActivityCreate = {
diff --git a/server/lib/activitypub/send/send-delete.ts b/server/lib/activitypub/send/send-delete.ts
index 5be0e2d24..c49cda04f 100644
--- a/server/lib/activitypub/send/send-delete.ts
+++ b/server/lib/activitypub/send/send-delete.ts
@@ -7,9 +7,9 @@ import { broadcastToFollowers } from './misc'
7async function sendDeleteVideoChannel (videoChannel: VideoChannelInstance, t: Transaction) { 7async function sendDeleteVideoChannel (videoChannel: VideoChannelInstance, t: Transaction) {
8 const byAccount = videoChannel.Account 8 const byAccount = videoChannel.Account
9 9
10 const data = await deleteActivityData(videoChannel.url, byAccount) 10 const data = deleteActivityData(videoChannel.url, byAccount)
11 11
12 const accountsInvolved = await db.VideoChannelShare.loadAccountsByShare(videoChannel.id) 12 const accountsInvolved = await db.VideoChannelShare.loadAccountsByShare(videoChannel.id, t)
13 accountsInvolved.push(byAccount) 13 accountsInvolved.push(byAccount)
14 14
15 return broadcastToFollowers(data, byAccount, accountsInvolved, t) 15 return broadcastToFollowers(data, byAccount, accountsInvolved, t)
@@ -18,9 +18,9 @@ async function sendDeleteVideoChannel (videoChannel: VideoChannelInstance, t: Tr
18async function sendDeleteVideo (video: VideoInstance, t: Transaction) { 18async function sendDeleteVideo (video: VideoInstance, t: Transaction) {
19 const byAccount = video.VideoChannel.Account 19 const byAccount = video.VideoChannel.Account
20 20
21 const data = await deleteActivityData(video.url, byAccount) 21 const data = deleteActivityData(video.url, byAccount)
22 22
23 const accountsInvolved = await db.VideoShare.loadAccountsByShare(video.id) 23 const accountsInvolved = await db.VideoShare.loadAccountsByShare(video.id, t)
24 accountsInvolved.push(byAccount) 24 accountsInvolved.push(byAccount)
25 25
26 return broadcastToFollowers(data, byAccount, accountsInvolved, t) 26 return broadcastToFollowers(data, byAccount, accountsInvolved, t)
@@ -42,7 +42,7 @@ export {
42 42
43// --------------------------------------------------------------------------- 43// ---------------------------------------------------------------------------
44 44
45async function deleteActivityData (url: string, byAccount: AccountInstance) { 45function deleteActivityData (url: string, byAccount: AccountInstance) {
46 const activity: ActivityDelete = { 46 const activity: ActivityDelete = {
47 type: 'Delete', 47 type: 'Delete',
48 id: url, 48 id: url,
diff --git a/server/lib/activitypub/send/send-follow.ts b/server/lib/activitypub/send/send-follow.ts
index 3c01fb77c..8fba1b6b5 100644
--- a/server/lib/activitypub/send/send-follow.ts
+++ b/server/lib/activitypub/send/send-follow.ts
@@ -5,17 +5,17 @@ import { AccountFollowInstance } from '../../../models/account/account-follow-in
5import { getAccountFollowActivityPubUrl } from '../url' 5import { getAccountFollowActivityPubUrl } from '../url'
6import { unicastTo } from './misc' 6import { unicastTo } from './misc'
7 7
8async function sendFollow (accountFollow: AccountFollowInstance, t: Transaction) { 8function sendFollow (accountFollow: AccountFollowInstance, t: Transaction) {
9 const me = accountFollow.AccountFollower 9 const me = accountFollow.AccountFollower
10 const following = accountFollow.AccountFollowing 10 const following = accountFollow.AccountFollowing
11 11
12 const url = getAccountFollowActivityPubUrl(accountFollow) 12 const url = getAccountFollowActivityPubUrl(accountFollow)
13 const data = await followActivityData(url, me, following) 13 const data = followActivityData(url, me, following)
14 14
15 return unicastTo(data, me, following.inboxUrl, t) 15 return unicastTo(data, me, following.inboxUrl, t)
16} 16}
17 17
18async function followActivityData (url: string, byAccount: AccountInstance, targetAccount: AccountInstance) { 18function followActivityData (url: string, byAccount: AccountInstance, targetAccount: AccountInstance) {
19 const activity: ActivityFollow = { 19 const activity: ActivityFollow = {
20 type: 'Follow', 20 type: 'Follow',
21 id: url, 21 id: url,
diff --git a/server/lib/activitypub/send/send-like.ts b/server/lib/activitypub/send/send-like.ts
index 41b879b8a..0c464b2d3 100644
--- a/server/lib/activitypub/send/send-like.ts
+++ b/server/lib/activitypub/send/send-like.ts
@@ -1,5 +1,5 @@
1import { Transaction } from 'sequelize' 1import { Transaction } from 'sequelize'
2import { ActivityLike } from '../../../../shared/models/activitypub/activity' 2import { ActivityAudience, ActivityLike } from '../../../../shared/models/activitypub/activity'
3import { AccountInstance, VideoInstance } from '../../../models' 3import { AccountInstance, VideoInstance } from '../../../models'
4import { getVideoLikeActivityPubUrl } from '../url' 4import { getVideoLikeActivityPubUrl } from '../url'
5import { 5import {
@@ -14,9 +14,9 @@ import {
14async function sendLikeToOrigin (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { 14async function sendLikeToOrigin (byAccount: AccountInstance, video: VideoInstance, t: Transaction) {
15 const url = getVideoLikeActivityPubUrl(byAccount, video) 15 const url = getVideoLikeActivityPubUrl(byAccount, video)
16 16
17 const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video) 17 const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t)
18 const audience = getOriginVideoAudience(video, accountsInvolvedInVideo) 18 const audience = getOriginVideoAudience(video, accountsInvolvedInVideo)
19 const data = await likeActivityData(url, byAccount, video, audience) 19 const data = await likeActivityData(url, byAccount, video, t, audience)
20 20
21 return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) 21 return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t)
22} 22}
@@ -24,19 +24,23 @@ async function sendLikeToOrigin (byAccount: AccountInstance, video: VideoInstanc
24async function sendLikeToVideoFollowers (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { 24async function sendLikeToVideoFollowers (byAccount: AccountInstance, video: VideoInstance, t: Transaction) {
25 const url = getVideoLikeActivityPubUrl(byAccount, video) 25 const url = getVideoLikeActivityPubUrl(byAccount, video)
26 26
27 const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video) 27 const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t)
28 const audience = getObjectFollowersAudience(accountsInvolvedInVideo) 28 const audience = getObjectFollowersAudience(accountsInvolvedInVideo)
29 const data = await likeActivityData(url, byAccount, video, audience) 29 const data = await likeActivityData(url, byAccount, video, t, audience)
30
31 const toAccountsFollowers = await getAccountsInvolvedInVideo(video)
32 30
33 const followersException = [ byAccount ] 31 const followersException = [ byAccount ]
34 return broadcastToFollowers(data, byAccount, toAccountsFollowers, t, followersException) 32 return broadcastToFollowers(data, byAccount, accountsInvolvedInVideo, t, followersException)
35} 33}
36 34
37async function likeActivityData (url: string, byAccount: AccountInstance, video: VideoInstance, audience?: { to: string[], cc: string[] }) { 35async function likeActivityData (
36 url: string,
37 byAccount: AccountInstance,
38 video: VideoInstance,
39 t: Transaction,
40 audience?: ActivityAudience
41) {
38 if (!audience) { 42 if (!audience) {
39 audience = await getAudience(byAccount) 43 audience = await getAudience(byAccount, t)
40 } 44 }
41 45
42 const activity: ActivityLike = { 46 const activity: ActivityLike = {
diff --git a/server/lib/activitypub/send/send-undo.ts b/server/lib/activitypub/send/send-undo.ts
index 878acd21e..2f5e6998e 100644
--- a/server/lib/activitypub/send/send-undo.ts
+++ b/server/lib/activitypub/send/send-undo.ts
@@ -29,8 +29,8 @@ async function sendUndoFollow (accountFollow: AccountFollowInstance, t: Transact
29 const followUrl = getAccountFollowActivityPubUrl(accountFollow) 29 const followUrl = getAccountFollowActivityPubUrl(accountFollow)
30 const undoUrl = getUndoActivityPubUrl(followUrl) 30 const undoUrl = getUndoActivityPubUrl(followUrl)
31 31
32 const object = await followActivityData(followUrl, me, following) 32 const object = followActivityData(followUrl, me, following)
33 const data = await undoActivityData(undoUrl, me, object) 33 const data = await undoActivityData(undoUrl, me, object, t)
34 34
35 return unicastTo(data, me, following.inboxUrl, t) 35 return unicastTo(data, me, following.inboxUrl, t)
36} 36}
@@ -39,10 +39,10 @@ async function sendUndoLikeToOrigin (byAccount: AccountInstance, video: VideoIns
39 const likeUrl = getVideoLikeActivityPubUrl(byAccount, video) 39 const likeUrl = getVideoLikeActivityPubUrl(byAccount, video)
40 const undoUrl = getUndoActivityPubUrl(likeUrl) 40 const undoUrl = getUndoActivityPubUrl(likeUrl)
41 41
42 const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video) 42 const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t)
43 const audience = getOriginVideoAudience(video, accountsInvolvedInVideo) 43 const audience = getOriginVideoAudience(video, accountsInvolvedInVideo)
44 const object = await likeActivityData(likeUrl, byAccount, video) 44 const object = await likeActivityData(likeUrl, byAccount, video, t)
45 const data = await undoActivityData(undoUrl, byAccount, object, audience) 45 const data = await undoActivityData(undoUrl, byAccount, object, t, audience)
46 46
47 return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) 47 return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t)
48} 48}
@@ -51,10 +51,10 @@ async function sendUndoLikeToVideoFollowers (byAccount: AccountInstance, video:
51 const likeUrl = getVideoLikeActivityPubUrl(byAccount, video) 51 const likeUrl = getVideoLikeActivityPubUrl(byAccount, video)
52 const undoUrl = getUndoActivityPubUrl(likeUrl) 52 const undoUrl = getUndoActivityPubUrl(likeUrl)
53 53
54 const toAccountsFollowers = await getAccountsInvolvedInVideo(video) 54 const toAccountsFollowers = await getAccountsInvolvedInVideo(video, t)
55 const audience = getObjectFollowersAudience(toAccountsFollowers) 55 const audience = getObjectFollowersAudience(toAccountsFollowers)
56 const object = await likeActivityData(likeUrl, byAccount, video) 56 const object = await likeActivityData(likeUrl, byAccount, video, t)
57 const data = await undoActivityData(undoUrl, byAccount, object, audience) 57 const data = await undoActivityData(undoUrl, byAccount, object, t, audience)
58 58
59 const followersException = [ byAccount ] 59 const followersException = [ byAccount ]
60 return broadcastToFollowers(data, byAccount, toAccountsFollowers, t, followersException) 60 return broadcastToFollowers(data, byAccount, toAccountsFollowers, t, followersException)
@@ -64,12 +64,12 @@ async function sendUndoDislikeToOrigin (byAccount: AccountInstance, video: Video
64 const dislikeUrl = getVideoDislikeActivityPubUrl(byAccount, video) 64 const dislikeUrl = getVideoDislikeActivityPubUrl(byAccount, video)
65 const undoUrl = getUndoActivityPubUrl(dislikeUrl) 65 const undoUrl = getUndoActivityPubUrl(dislikeUrl)
66 66
67 const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video) 67 const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t)
68 const audience = getOriginVideoAudience(video, accountsInvolvedInVideo) 68 const audience = getOriginVideoAudience(video, accountsInvolvedInVideo)
69 const dislikeActivity = createDislikeActivityData(byAccount, video) 69 const dislikeActivity = createDislikeActivityData(byAccount, video)
70 const object = await createActivityData(undoUrl, byAccount, dislikeActivity, audience) 70 const object = await createActivityData(undoUrl, byAccount, dislikeActivity, t, audience)
71 71
72 const data = await undoActivityData(undoUrl, byAccount, object) 72 const data = await undoActivityData(undoUrl, byAccount, object, t)
73 73
74 return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) 74 return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t)
75} 75}
@@ -79,11 +79,11 @@ async function sendUndoDislikeToVideoFollowers (byAccount: AccountInstance, vide
79 const undoUrl = getUndoActivityPubUrl(dislikeUrl) 79 const undoUrl = getUndoActivityPubUrl(dislikeUrl)
80 80
81 const dislikeActivity = createDislikeActivityData(byAccount, video) 81 const dislikeActivity = createDislikeActivityData(byAccount, video)
82 const object = await createActivityData(undoUrl, byAccount, dislikeActivity) 82 const object = await createActivityData(undoUrl, byAccount, dislikeActivity, t)
83 83
84 const data = await undoActivityData(undoUrl, byAccount, object) 84 const data = await undoActivityData(undoUrl, byAccount, object, t)
85 85
86 const toAccountsFollowers = await getAccountsInvolvedInVideo(video) 86 const toAccountsFollowers = await getAccountsInvolvedInVideo(video, t)
87 87
88 const followersException = [ byAccount ] 88 const followersException = [ byAccount ]
89 return broadcastToFollowers(data, byAccount, toAccountsFollowers, t, followersException) 89 return broadcastToFollowers(data, byAccount, toAccountsFollowers, t, followersException)
@@ -105,10 +105,11 @@ async function undoActivityData (
105 url: string, 105 url: string,
106 byAccount: AccountInstance, 106 byAccount: AccountInstance,
107 object: ActivityFollow | ActivityLike | ActivityCreate, 107 object: ActivityFollow | ActivityLike | ActivityCreate,
108 t: Transaction,
108 audience?: ActivityAudience 109 audience?: ActivityAudience
109) { 110) {
110 if (!audience) { 111 if (!audience) {
111 audience = await getAudience(byAccount) 112 audience = await getAudience(byAccount, t)
112 } 113 }
113 114
114 const activity: ActivityUndo = { 115 const activity: ActivityUndo = {
diff --git a/server/lib/activitypub/send/send-update.ts b/server/lib/activitypub/send/send-update.ts
index 32cada06e..59524e523 100644
--- a/server/lib/activitypub/send/send-update.ts
+++ b/server/lib/activitypub/send/send-update.ts
@@ -10,9 +10,9 @@ async function sendUpdateVideoChannel (videoChannel: VideoChannelInstance, t: Tr
10 10
11 const url = getUpdateActivityPubUrl(videoChannel.url, videoChannel.updatedAt.toISOString()) 11 const url = getUpdateActivityPubUrl(videoChannel.url, videoChannel.updatedAt.toISOString())
12 const videoChannelObject = videoChannel.toActivityPubObject() 12 const videoChannelObject = videoChannel.toActivityPubObject()
13 const data = await updateActivityData(url, byAccount, videoChannelObject) 13 const data = await updateActivityData(url, byAccount, videoChannelObject, t)
14 14
15 const accountsInvolved = await db.VideoChannelShare.loadAccountsByShare(videoChannel.id) 15 const accountsInvolved = await db.VideoChannelShare.loadAccountsByShare(videoChannel.id, t)
16 accountsInvolved.push(byAccount) 16 accountsInvolved.push(byAccount)
17 17
18 return broadcastToFollowers(data, byAccount, accountsInvolved, t) 18 return broadcastToFollowers(data, byAccount, accountsInvolved, t)
@@ -23,9 +23,9 @@ async function sendUpdateVideo (video: VideoInstance, t: Transaction) {
23 23
24 const url = getUpdateActivityPubUrl(video.url, video.updatedAt.toISOString()) 24 const url = getUpdateActivityPubUrl(video.url, video.updatedAt.toISOString())
25 const videoObject = video.toActivityPubObject() 25 const videoObject = video.toActivityPubObject()
26 const data = await updateActivityData(url, byAccount, videoObject) 26 const data = await updateActivityData(url, byAccount, videoObject, t)
27 27
28 const accountsInvolved = await db.VideoShare.loadAccountsByShare(video.id) 28 const accountsInvolved = await db.VideoShare.loadAccountsByShare(video.id, t)
29 accountsInvolved.push(byAccount) 29 accountsInvolved.push(byAccount)
30 30
31 return broadcastToFollowers(data, byAccount, accountsInvolved, t) 31 return broadcastToFollowers(data, byAccount, accountsInvolved, t)
@@ -40,8 +40,8 @@ export {
40 40
41// --------------------------------------------------------------------------- 41// ---------------------------------------------------------------------------
42 42
43async function updateActivityData (url: string, byAccount: AccountInstance, object: any) { 43async function updateActivityData (url: string, byAccount: AccountInstance, object: any, t: Transaction) {
44 const { to, cc } = await getAudience(byAccount) 44 const { to, cc } = await getAudience(byAccount, t)
45 const activity: ActivityUpdate = { 45 const activity: ActivityUpdate = {
46 type: 'Update', 46 type: 'Update',
47 id: url, 47 id: url,