aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/controllers/api/videos/rate.ts4
-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
-rw-r--r--server/models/account/account-follow-interface.ts16
-rw-r--r--server/models/account/account-follow.ts16
-rw-r--r--server/models/account/account-interface.ts4
-rw-r--r--server/models/account/account-video-rate.ts2
-rw-r--r--server/models/account/account.ts6
-rw-r--r--server/models/video/video-channel-share-interface.ts5
-rw-r--r--server/models/video/video-channel-share.ts10
-rw-r--r--server/models/video/video-share-interface.ts5
-rw-r--r--server/models/video/video-share.ts10
21 files changed, 144 insertions, 113 deletions
diff --git a/server/controllers/api/videos/rate.ts b/server/controllers/api/videos/rate.ts
index 0c6a988cf..c27c61116 100644
--- a/server/controllers/api/videos/rate.ts
+++ b/server/controllers/api/videos/rate.ts
@@ -58,11 +58,11 @@ async function rateVideo (req: express.Request, res: express.Response) {
58 else if (previousRate.type === VIDEO_RATE_TYPES.DISLIKE) dislikesToIncrement-- 58 else if (previousRate.type === VIDEO_RATE_TYPES.DISLIKE) dislikesToIncrement--
59 59
60 if (rateType === 'none') { // Destroy previous rate 60 if (rateType === 'none') { // Destroy previous rate
61 await previousRate.destroy() 61 await previousRate.destroy({ transaction: t })
62 } else { // Update previous rate 62 } else { // Update previous rate
63 previousRate.type = rateType 63 previousRate.type = rateType
64 64
65 await previousRate.save() 65 await previousRate.save({ transaction: t })
66 } 66 }
67 } else if (rateType !== 'none') { // There was not a previous rate, insert a new one if there is a rate 67 } else if (rateType !== 'none') { // There was not a previous rate, insert a new one if there is a rate
68 const query = { 68 const query = {
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,
diff --git a/server/models/account/account-follow-interface.ts b/server/models/account/account-follow-interface.ts
index a0d620dd0..7975a46f3 100644
--- a/server/models/account/account-follow-interface.ts
+++ b/server/models/account/account-follow-interface.ts
@@ -14,9 +14,19 @@ export namespace AccountFollowMethods {
14 export type ListFollowingForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList<AccountFollowInstance>> 14 export type ListFollowingForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList<AccountFollowInstance>>
15 export type ListFollowersForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList<AccountFollowInstance>> 15 export type ListFollowersForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList<AccountFollowInstance>>
16 16
17 export type ListAcceptedFollowerUrlsForApi = (accountId: number[], start?: number, count?: number) => Promise< ResultList<string> > 17 export type ListAcceptedFollowerUrlsForApi = (
18 export type ListAcceptedFollowingUrlsForApi = (accountId: number[], start?: number, count?: number) => Promise< ResultList<string> > 18 accountId: number[],
19 export type ListAcceptedFollowerSharedInboxUrls = (accountId: number[]) => Promise< ResultList<string> > 19 t: Sequelize.Transaction,
20 start?: number,
21 count?: number
22 ) => Promise< ResultList<string> >
23 export type ListAcceptedFollowingUrlsForApi = (
24 accountId: number[],
25 t: Sequelize.Transaction,
26 start?: number,
27 count?: number
28 ) => Promise< ResultList<string> >
29 export type ListAcceptedFollowerSharedInboxUrls = (accountId: number[], t: Sequelize.Transaction) => Promise< ResultList<string> >
20 export type ToFormattedJSON = (this: AccountFollowInstance) => AccountFollow 30 export type ToFormattedJSON = (this: AccountFollowInstance) => AccountFollow
21} 31}
22 32
diff --git a/server/models/account/account-follow.ts b/server/models/account/account-follow.ts
index 8e35c7d20..724f37baa 100644
--- a/server/models/account/account-follow.ts
+++ b/server/models/account/account-follow.ts
@@ -181,16 +181,16 @@ listFollowersForApi = function (id: number, start: number, count: number, sort:
181 }) 181 })
182} 182}
183 183
184listAcceptedFollowerUrlsForApi = function (accountIds: number[], start?: number, count?: number) { 184listAcceptedFollowerUrlsForApi = function (accountIds: number[], t: Sequelize.Transaction, start?: number, count?: number) {
185 return createListAcceptedFollowForApiQuery('followers', accountIds, start, count) 185 return createListAcceptedFollowForApiQuery('followers', accountIds, t, start, count)
186} 186}
187 187
188listAcceptedFollowerSharedInboxUrls = function (accountIds: number[]) { 188listAcceptedFollowerSharedInboxUrls = function (accountIds: number[], t: Sequelize.Transaction) {
189 return createListAcceptedFollowForApiQuery('followers', accountIds, undefined, undefined, 'sharedInboxUrl') 189 return createListAcceptedFollowForApiQuery('followers', accountIds, t, undefined, undefined, 'sharedInboxUrl')
190} 190}
191 191
192listAcceptedFollowingUrlsForApi = function (accountIds: number[], start?: number, count?: number) { 192listAcceptedFollowingUrlsForApi = function (accountIds: number[], t: Sequelize.Transaction, start?: number, count?: number) {
193 return createListAcceptedFollowForApiQuery('following', accountIds, start, count) 193 return createListAcceptedFollowForApiQuery('following', accountIds, t, start, count)
194} 194}
195 195
196// ------------------------------ UTILS ------------------------------ 196// ------------------------------ UTILS ------------------------------
@@ -198,6 +198,7 @@ listAcceptedFollowingUrlsForApi = function (accountIds: number[], start?: number
198async function createListAcceptedFollowForApiQuery ( 198async function createListAcceptedFollowForApiQuery (
199 type: 'followers' | 'following', 199 type: 'followers' | 'following',
200 accountIds: number[], 200 accountIds: number[],
201 t: Sequelize.Transaction,
201 start?: number, 202 start?: number,
202 count?: number, 203 count?: number,
203 columnUrl = 'url' 204 columnUrl = 'url'
@@ -227,7 +228,8 @@ async function createListAcceptedFollowForApiQuery (
227 228
228 const options = { 229 const options = {
229 bind: { accountIds }, 230 bind: { accountIds },
230 type: Sequelize.QueryTypes.SELECT 231 type: Sequelize.QueryTypes.SELECT,
232 transaction: t
231 } 233 }
232 tasks.push(AccountFollow['sequelize'].query(query, options)) 234 tasks.push(AccountFollow['sequelize'].query(query, options))
233 } 235 }
diff --git a/server/models/account/account-interface.ts b/server/models/account/account-interface.ts
index 6fc98ba45..b369766dc 100644
--- a/server/models/account/account-interface.ts
+++ b/server/models/account/account-interface.ts
@@ -12,12 +12,12 @@ export namespace AccountMethods {
12 export type LoadByUrl = (url: string, transaction?: Sequelize.Transaction) => Bluebird<AccountInstance> 12 export type LoadByUrl = (url: string, transaction?: Sequelize.Transaction) => Bluebird<AccountInstance>
13 export type LoadLocalByName = (name: string) => Bluebird<AccountInstance> 13 export type LoadLocalByName = (name: string) => Bluebird<AccountInstance>
14 export type LoadByNameAndHost = (name: string, host: string) => Bluebird<AccountInstance> 14 export type LoadByNameAndHost = (name: string, host: string) => Bluebird<AccountInstance>
15 export type ListByFollowersUrls = (followerUrls: string[], transaction?: Sequelize.Transaction) => Bluebird<AccountInstance[]> 15 export type ListByFollowersUrls = (followerUrls: string[], transaction: Sequelize.Transaction) => Bluebird<AccountInstance[]>
16 16
17 export type ToActivityPubObject = (this: AccountInstance) => ActivityPubActor 17 export type ToActivityPubObject = (this: AccountInstance) => ActivityPubActor
18 export type ToFormattedJSON = (this: AccountInstance) => FormattedAccount 18 export type ToFormattedJSON = (this: AccountInstance) => FormattedAccount
19 export type IsOwned = (this: AccountInstance) => boolean 19 export type IsOwned = (this: AccountInstance) => boolean
20 export type GetFollowerSharedInboxUrls = (this: AccountInstance) => Bluebird<string[]> 20 export type GetFollowerSharedInboxUrls = (this: AccountInstance, t: Sequelize.Transaction) => Bluebird<string[]>
21 export type GetFollowingUrl = (this: AccountInstance) => string 21 export type GetFollowingUrl = (this: AccountInstance) => string
22 export type GetFollowersUrl = (this: AccountInstance) => string 22 export type GetFollowersUrl = (this: AccountInstance) => string
23 export type GetPublicKeyUrl = (this: AccountInstance) => string 23 export type GetPublicKeyUrl = (this: AccountInstance) => string
diff --git a/server/models/account/account-video-rate.ts b/server/models/account/account-video-rate.ts
index 7f7c97606..d92834bbb 100644
--- a/server/models/account/account-video-rate.ts
+++ b/server/models/account/account-video-rate.ts
@@ -28,7 +28,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
28 { 28 {
29 indexes: [ 29 indexes: [
30 { 30 {
31 fields: [ 'videoId', 'accountId', 'type' ], 31 fields: [ 'videoId', 'accountId' ],
32 unique: true 32 unique: true
33 } 33 }
34 ] 34 ]
diff --git a/server/models/account/account.ts b/server/models/account/account.ts
index c721656cb..61a88524c 100644
--- a/server/models/account/account.ts
+++ b/server/models/account/account.ts
@@ -10,7 +10,6 @@ import {
10import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' 10import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
11import { CONFIG, CONSTRAINTS_FIELDS } from '../../initializers/constants' 11import { CONFIG, CONSTRAINTS_FIELDS } from '../../initializers/constants'
12import { sendDeleteAccount } from '../../lib/activitypub/send/send-delete' 12import { sendDeleteAccount } from '../../lib/activitypub/send/send-delete'
13
14import { addMethodsToModel } from '../utils' 13import { addMethodsToModel } from '../utils'
15import { AccountAttributes, AccountInstance, AccountMethods } from './account-interface' 14import { AccountAttributes, AccountInstance, AccountMethods } from './account-interface'
16 15
@@ -315,7 +314,7 @@ isOwned = function (this: AccountInstance) {
315 return this.serverId === null 314 return this.serverId === null
316} 315}
317 316
318getFollowerSharedInboxUrls = function (this: AccountInstance) { 317getFollowerSharedInboxUrls = function (this: AccountInstance, t: Sequelize.Transaction) {
319 const query: Sequelize.FindOptions<AccountAttributes> = { 318 const query: Sequelize.FindOptions<AccountAttributes> = {
320 attributes: [ 'sharedInboxUrl' ], 319 attributes: [ 'sharedInboxUrl' ],
321 include: [ 320 include: [
@@ -327,7 +326,8 @@ getFollowerSharedInboxUrls = function (this: AccountInstance) {
327 targetAccountId: this.id 326 targetAccountId: this.id
328 } 327 }
329 } 328 }
330 ] 329 ],
330 transaction: t
331 } 331 }
332 332
333 return Account.findAll(query) 333 return Account.findAll(query)
diff --git a/server/models/video/video-channel-share-interface.ts b/server/models/video/video-channel-share-interface.ts
index bcb3a0e24..0482e8297 100644
--- a/server/models/video/video-channel-share-interface.ts
+++ b/server/models/video/video-channel-share-interface.ts
@@ -1,11 +1,12 @@
1import * as Bluebird from 'bluebird' 1import * as Bluebird from 'bluebird'
2import * as Sequelize from 'sequelize' 2import * as Sequelize from 'sequelize'
3import { Transaction } from 'sequelize'
3import { AccountInstance } from '../account/account-interface' 4import { AccountInstance } from '../account/account-interface'
4import { VideoChannelInstance } from './video-channel-interface' 5import { VideoChannelInstance } from './video-channel-interface'
5 6
6export namespace VideoChannelShareMethods { 7export namespace VideoChannelShareMethods {
7 export type LoadAccountsByShare = (videoChannelId: number) => Bluebird<AccountInstance[]> 8 export type LoadAccountsByShare = (videoChannelId: number, t: Transaction) => Bluebird<AccountInstance[]>
8 export type Load = (accountId: number, videoId: number) => Bluebird<VideoChannelShareInstance> 9 export type Load = (accountId: number, videoId: number, t: Transaction) => Bluebird<VideoChannelShareInstance>
9} 10}
10 11
11export interface VideoChannelShareClass { 12export interface VideoChannelShareClass {
diff --git a/server/models/video/video-channel-share.ts b/server/models/video/video-channel-share.ts
index e47c0dae7..2e9b658a3 100644
--- a/server/models/video/video-channel-share.ts
+++ b/server/models/video/video-channel-share.ts
@@ -52,7 +52,7 @@ function associate (models) {
52 }) 52 })
53} 53}
54 54
55load = function (accountId: number, videoChannelId: number) { 55load = function (accountId: number, videoChannelId: number, t: Sequelize.Transaction) {
56 return VideoChannelShare.findOne({ 56 return VideoChannelShare.findOne({
57 where: { 57 where: {
58 accountId, 58 accountId,
@@ -61,11 +61,12 @@ load = function (accountId: number, videoChannelId: number) {
61 include: [ 61 include: [
62 VideoChannelShare['sequelize'].models.Account, 62 VideoChannelShare['sequelize'].models.Account,
63 VideoChannelShare['sequelize'].models.VideoChannel 63 VideoChannelShare['sequelize'].models.VideoChannel
64 ] 64 ],
65 transaction: t
65 }) 66 })
66} 67}
67 68
68loadAccountsByShare = function (videoChannelId: number) { 69loadAccountsByShare = function (videoChannelId: number, t: Sequelize.Transaction) {
69 const query = { 70 const query = {
70 where: { 71 where: {
71 videoChannelId 72 videoChannelId
@@ -75,7 +76,8 @@ loadAccountsByShare = function (videoChannelId: number) {
75 model: VideoChannelShare['sequelize'].models.Account, 76 model: VideoChannelShare['sequelize'].models.Account,
76 required: true 77 required: true
77 } 78 }
78 ] 79 ],
80 transaction: t
79 } 81 }
80 82
81 return VideoChannelShare.findAll(query) 83 return VideoChannelShare.findAll(query)
diff --git a/server/models/video/video-share-interface.ts b/server/models/video/video-share-interface.ts
index ad23444b6..8ad10e095 100644
--- a/server/models/video/video-share-interface.ts
+++ b/server/models/video/video-share-interface.ts
@@ -1,11 +1,12 @@
1import * as Bluebird from 'bluebird' 1import * as Bluebird from 'bluebird'
2import * as Sequelize from 'sequelize' 2import * as Sequelize from 'sequelize'
3import { Transaction } from 'sequelize'
3import { AccountInstance } from '../account/account-interface' 4import { AccountInstance } from '../account/account-interface'
4import { VideoInstance } from './video-interface' 5import { VideoInstance } from './video-interface'
5 6
6export namespace VideoShareMethods { 7export namespace VideoShareMethods {
7 export type LoadAccountsByShare = (videoId: number) => Bluebird<AccountInstance[]> 8 export type LoadAccountsByShare = (videoId: number, t: Transaction) => Bluebird<AccountInstance[]>
8 export type Load = (accountId: number, videoId: number) => Bluebird<VideoShareInstance> 9 export type Load = (accountId: number, videoId: number, t: Transaction) => Bluebird<VideoShareInstance>
9} 10}
10 11
11export interface VideoShareClass { 12export interface VideoShareClass {
diff --git a/server/models/video/video-share.ts b/server/models/video/video-share.ts
index fe5d56d42..37e405fa9 100644
--- a/server/models/video/video-share.ts
+++ b/server/models/video/video-share.ts
@@ -52,7 +52,7 @@ function associate (models) {
52 }) 52 })
53} 53}
54 54
55load = function (accountId: number, videoId: number) { 55load = function (accountId: number, videoId: number, t: Sequelize.Transaction) {
56 return VideoShare.findOne({ 56 return VideoShare.findOne({
57 where: { 57 where: {
58 accountId, 58 accountId,
@@ -60,11 +60,12 @@ load = function (accountId: number, videoId: number) {
60 }, 60 },
61 include: [ 61 include: [
62 VideoShare['sequelize'].models.Account 62 VideoShare['sequelize'].models.Account
63 ] 63 ],
64 transaction: t
64 }) 65 })
65} 66}
66 67
67loadAccountsByShare = function (videoId: number) { 68loadAccountsByShare = function (videoId: number, t: Sequelize.Transaction) {
68 const query = { 69 const query = {
69 where: { 70 where: {
70 videoId 71 videoId
@@ -74,7 +75,8 @@ loadAccountsByShare = function (videoId: number) {
74 model: VideoShare['sequelize'].models.Account, 75 model: VideoShare['sequelize'].models.Account,
75 required: true 76 required: true
76 } 77 }
77 ] 78 ],
79 transaction: t
78 } 80 }
79 81
80 return VideoShare.findAll(query) 82 return VideoShare.findAll(query)