diff options
author | Chocobozzz <me@florianbigard.com> | 2017-12-12 17:53:50 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2017-12-13 16:50:33 +0100 |
commit | 3fd3ab2d34d512b160a5e6084d7609be7b4f4452 (patch) | |
tree | e5ca358287fca6ecacce83defcf23af1e8e9f419 /server/lib/activitypub | |
parent | c893d4514e6ecbf282c7985fe5f82b8acd8a1137 (diff) | |
download | PeerTube-3fd3ab2d34d512b160a5e6084d7609be7b4f4452.tar.gz PeerTube-3fd3ab2d34d512b160a5e6084d7609be7b4f4452.tar.zst PeerTube-3fd3ab2d34d512b160a5e6084d7609be7b4f4452.zip |
Move models to typescript-sequelize
Diffstat (limited to 'server/lib/activitypub')
27 files changed, 374 insertions, 377 deletions
diff --git a/server/lib/activitypub/account.ts b/server/lib/activitypub/account.ts index 906c8ff29..45690b88d 100644 --- a/server/lib/activitypub/account.ts +++ b/server/lib/activitypub/account.ts | |||
@@ -1,17 +1,15 @@ | |||
1 | import * as Bluebird from 'bluebird' | 1 | import * as Bluebird from 'bluebird' |
2 | import * as url from 'url' | ||
3 | import { ActivityPubActor } from '../../../shared/models/activitypub/activitypub-actor' | ||
4 | import { isRemoteAccountValid } from '../../helpers/custom-validators/activitypub/account' | ||
5 | import { retryTransactionWrapper } from '../../helpers/database-utils' | ||
6 | import { logger } from '../../helpers/logger' | ||
7 | import { doRequest } from '../../helpers/requests' | ||
8 | import { ACTIVITY_PUB } from '../../initializers/constants' | ||
9 | import { database as db } from '../../initializers/database' | ||
10 | import { AccountInstance } from '../../models/account/account-interface' | ||
11 | import { Transaction } from 'sequelize' | 2 | import { Transaction } from 'sequelize' |
3 | import * as url from 'url' | ||
4 | import { ActivityPubActor } from '../../../shared/models/activitypub' | ||
5 | import { doRequest, logger, retryTransactionWrapper } from '../../helpers' | ||
6 | import { isRemoteAccountValid } from '../../helpers/custom-validators/activitypub' | ||
7 | import { ACTIVITY_PUB, sequelizeTypescript } from '../../initializers' | ||
8 | import { AccountModel } from '../../models/account/account' | ||
9 | import { ServerModel } from '../../models/server/server' | ||
12 | 10 | ||
13 | async function getOrCreateAccountAndServer (accountUrl: string) { | 11 | async function getOrCreateAccountAndServer (accountUrl: string) { |
14 | let account = await db.Account.loadByUrl(accountUrl) | 12 | let account = await AccountModel.loadByUrl(accountUrl) |
15 | 13 | ||
16 | // We don't have this account in our database, fetch it on remote | 14 | // We don't have this account in our database, fetch it on remote |
17 | if (!account) { | 15 | if (!account) { |
@@ -28,11 +26,11 @@ async function getOrCreateAccountAndServer (accountUrl: string) { | |||
28 | return account | 26 | return account |
29 | } | 27 | } |
30 | 28 | ||
31 | function saveAccountAndServerIfNotExist (account: AccountInstance, t?: Transaction): Bluebird<AccountInstance> | Promise<AccountInstance> { | 29 | function saveAccountAndServerIfNotExist (account: AccountModel, t?: Transaction): Bluebird<AccountModel> | Promise<AccountModel> { |
32 | if (t !== undefined) { | 30 | if (t !== undefined) { |
33 | return save(t) | 31 | return save(t) |
34 | } else { | 32 | } else { |
35 | return db.sequelize.transaction(t => { | 33 | return sequelizeTypescript.transaction(t => { |
36 | return save(t) | 34 | return save(t) |
37 | }) | 35 | }) |
38 | } | 36 | } |
@@ -49,7 +47,7 @@ function saveAccountAndServerIfNotExist (account: AccountInstance, t?: Transacti | |||
49 | }, | 47 | }, |
50 | transaction: t | 48 | transaction: t |
51 | } | 49 | } |
52 | const [ server ] = await db.Server.findOrCreate(serverOptions) | 50 | const [ server ] = await ServerModel.findOrCreate(serverOptions) |
53 | 51 | ||
54 | // Save our new account in database | 52 | // Save our new account in database |
55 | account.set('serverId', server.id) | 53 | account.set('serverId', server.id) |
@@ -87,7 +85,7 @@ async function fetchRemoteAccount (accountUrl: string) { | |||
87 | const followersCount = await fetchAccountCount(accountJSON.followers) | 85 | const followersCount = await fetchAccountCount(accountJSON.followers) |
88 | const followingCount = await fetchAccountCount(accountJSON.following) | 86 | const followingCount = await fetchAccountCount(accountJSON.following) |
89 | 87 | ||
90 | const account = db.Account.build({ | 88 | return new AccountModel({ |
91 | uuid: accountJSON.uuid, | 89 | uuid: accountJSON.uuid, |
92 | name: accountJSON.preferredUsername, | 90 | name: accountJSON.preferredUsername, |
93 | url: accountJSON.url, | 91 | url: accountJSON.url, |
@@ -101,8 +99,6 @@ async function fetchRemoteAccount (accountUrl: string) { | |||
101 | followersUrl: accountJSON.followers, | 99 | followersUrl: accountJSON.followers, |
102 | followingUrl: accountJSON.following | 100 | followingUrl: accountJSON.following |
103 | }) | 101 | }) |
104 | |||
105 | return account | ||
106 | } | 102 | } |
107 | 103 | ||
108 | export { | 104 | export { |
diff --git a/server/lib/activitypub/fetch.ts b/server/lib/activitypub/fetch.ts index fd2af0761..aa4dea8e0 100644 --- a/server/lib/activitypub/fetch.ts +++ b/server/lib/activitypub/fetch.ts | |||
@@ -1,8 +1,8 @@ | |||
1 | import { Transaction } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { AccountInstance } from '../../models/account/account-interface' | 2 | import { AccountModel } from '../../models/account/account' |
3 | import { activitypubHttpJobScheduler, ActivityPubHttpPayload } from '../jobs/activitypub-http-job-scheduler/activitypub-http-job-scheduler' | 3 | import { activitypubHttpJobScheduler, ActivityPubHttpPayload } from '../jobs/activitypub-http-job-scheduler' |
4 | 4 | ||
5 | async function addFetchOutboxJob (account: AccountInstance, t: Transaction) { | 5 | async function addFetchOutboxJob (account: AccountModel, t: Transaction) { |
6 | const jobPayload: ActivityPubHttpPayload = { | 6 | const jobPayload: ActivityPubHttpPayload = { |
7 | uris: [ account.outboxUrl ] | 7 | uris: [ account.outboxUrl ] |
8 | } | 8 | } |
diff --git a/server/lib/activitypub/process/misc.ts b/server/lib/activitypub/process/misc.ts index 0baa22c26..a775c858a 100644 --- a/server/lib/activitypub/process/misc.ts +++ b/server/lib/activitypub/process/misc.ts | |||
@@ -1,18 +1,18 @@ | |||
1 | import * as magnetUtil from 'magnet-uri' | 1 | import * as magnetUtil from 'magnet-uri' |
2 | import { VideoTorrentObject } from '../../../../shared' | 2 | import { VideoTorrentObject } from '../../../../shared' |
3 | import { VideoChannelObject } from '../../../../shared/models/activitypub/objects/video-channel-object' | 3 | import { VideoChannelObject } from '../../../../shared/models/activitypub/objects' |
4 | import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' | 4 | import { VideoPrivacy } from '../../../../shared/models/videos' |
5 | import { doRequest } from '../../../helpers' | ||
5 | import { isVideoFileInfoHashValid } from '../../../helpers/custom-validators/videos' | 6 | import { isVideoFileInfoHashValid } from '../../../helpers/custom-validators/videos' |
6 | import { doRequest } from '../../../helpers/requests' | 7 | import { ACTIVITY_PUB, VIDEO_MIMETYPE_EXT } from '../../../initializers' |
7 | import { database as db } from '../../../initializers' | 8 | import { AccountModel } from '../../../models/account/account' |
8 | import { ACTIVITY_PUB, VIDEO_MIMETYPE_EXT } from '../../../initializers/constants' | 9 | import { VideoModel } from '../../../models/video/video' |
9 | import { AccountInstance } from '../../../models/account/account-interface' | 10 | import { VideoChannelModel } from '../../../models/video/video-channel' |
10 | import { VideoChannelInstance } from '../../../models/video/video-channel-interface' | 11 | import { VideoChannelShareModel } from '../../../models/video/video-channel-share' |
11 | import { VideoFileAttributes } from '../../../models/video/video-file-interface' | 12 | import { VideoShareModel } from '../../../models/video/video-share' |
12 | import { VideoAttributes, VideoInstance } from '../../../models/video/video-interface' | ||
13 | import { getOrCreateAccountAndServer } from '../account' | 13 | import { getOrCreateAccountAndServer } from '../account' |
14 | 14 | ||
15 | function videoChannelActivityObjectToDBAttributes (videoChannelObject: VideoChannelObject, account: AccountInstance) { | 15 | function videoChannelActivityObjectToDBAttributes (videoChannelObject: VideoChannelObject, account: AccountModel) { |
16 | return { | 16 | return { |
17 | name: videoChannelObject.name, | 17 | name: videoChannelObject.name, |
18 | description: videoChannelObject.content, | 18 | description: videoChannelObject.content, |
@@ -26,7 +26,7 @@ function videoChannelActivityObjectToDBAttributes (videoChannelObject: VideoChan | |||
26 | } | 26 | } |
27 | 27 | ||
28 | async function videoActivityObjectToDBAttributes ( | 28 | async function videoActivityObjectToDBAttributes ( |
29 | videoChannel: VideoChannelInstance, | 29 | videoChannel: VideoChannelModel, |
30 | videoObject: VideoTorrentObject, | 30 | videoObject: VideoTorrentObject, |
31 | to: string[] = [], | 31 | to: string[] = [], |
32 | cc: string[] = [] | 32 | cc: string[] = [] |
@@ -56,7 +56,7 @@ async function videoActivityObjectToDBAttributes ( | |||
56 | description = videoObject.content | 56 | description = videoObject.content |
57 | } | 57 | } |
58 | 58 | ||
59 | const videoData: VideoAttributes = { | 59 | return { |
60 | name: videoObject.name, | 60 | name: videoObject.name, |
61 | uuid: videoObject.uuid, | 61 | uuid: videoObject.uuid, |
62 | url: videoObject.id, | 62 | url: videoObject.id, |
@@ -76,11 +76,9 @@ async function videoActivityObjectToDBAttributes ( | |||
76 | remote: true, | 76 | remote: true, |
77 | privacy | 77 | privacy |
78 | } | 78 | } |
79 | |||
80 | return videoData | ||
81 | } | 79 | } |
82 | 80 | ||
83 | function videoFileActivityUrlToDBAttributes (videoCreated: VideoInstance, videoObject: VideoTorrentObject) { | 81 | function videoFileActivityUrlToDBAttributes (videoCreated: VideoModel, videoObject: VideoTorrentObject) { |
84 | const mimeTypes = Object.keys(VIDEO_MIMETYPE_EXT) | 82 | const mimeTypes = Object.keys(VIDEO_MIMETYPE_EXT) |
85 | const fileUrls = videoObject.url.filter(u => { | 83 | const fileUrls = videoObject.url.filter(u => { |
86 | return mimeTypes.indexOf(u.mimeType) !== -1 && u.mimeType.startsWith('video/') | 84 | return mimeTypes.indexOf(u.mimeType) !== -1 && u.mimeType.startsWith('video/') |
@@ -90,7 +88,7 @@ function videoFileActivityUrlToDBAttributes (videoCreated: VideoInstance, videoO | |||
90 | throw new Error('Cannot find video files for ' + videoCreated.url) | 88 | throw new Error('Cannot find video files for ' + videoCreated.url) |
91 | } | 89 | } |
92 | 90 | ||
93 | const attributes: VideoFileAttributes[] = [] | 91 | const attributes = [] |
94 | for (const fileUrl of fileUrls) { | 92 | for (const fileUrl of fileUrls) { |
95 | // Fetch associated magnet uri | 93 | // Fetch associated magnet uri |
96 | const magnet = videoObject.url.find(u => { | 94 | const magnet = videoObject.url.find(u => { |
@@ -115,7 +113,7 @@ function videoFileActivityUrlToDBAttributes (videoCreated: VideoInstance, videoO | |||
115 | return attributes | 113 | return attributes |
116 | } | 114 | } |
117 | 115 | ||
118 | async function addVideoShares (instance: VideoInstance, shares: string[]) { | 116 | async function addVideoShares (instance: VideoModel, shares: string[]) { |
119 | for (const share of shares) { | 117 | for (const share of shares) { |
120 | // Fetch url | 118 | // Fetch url |
121 | const json = await doRequest({ | 119 | const json = await doRequest({ |
@@ -132,14 +130,14 @@ async function addVideoShares (instance: VideoInstance, shares: string[]) { | |||
132 | videoId: instance.id | 130 | videoId: instance.id |
133 | } | 131 | } |
134 | 132 | ||
135 | await db.VideoShare.findOrCreate({ | 133 | await VideoShareModel.findOrCreate({ |
136 | where: entry, | 134 | where: entry, |
137 | defaults: entry | 135 | defaults: entry |
138 | }) | 136 | }) |
139 | } | 137 | } |
140 | } | 138 | } |
141 | 139 | ||
142 | async function addVideoChannelShares (instance: VideoChannelInstance, shares: string[]) { | 140 | async function addVideoChannelShares (instance: VideoChannelModel, shares: string[]) { |
143 | for (const share of shares) { | 141 | for (const share of shares) { |
144 | // Fetch url | 142 | // Fetch url |
145 | const json = await doRequest({ | 143 | const json = await doRequest({ |
@@ -156,7 +154,7 @@ async function addVideoChannelShares (instance: VideoChannelInstance, shares: st | |||
156 | videoChannelId: instance.id | 154 | videoChannelId: instance.id |
157 | } | 155 | } |
158 | 156 | ||
159 | await db.VideoChannelShare.findOrCreate({ | 157 | await VideoChannelShareModel.findOrCreate({ |
160 | where: entry, | 158 | where: entry, |
161 | defaults: entry | 159 | defaults: entry |
162 | }) | 160 | }) |
diff --git a/server/lib/activitypub/process/process-accept.ts b/server/lib/activitypub/process/process-accept.ts index 73c6cb279..5b321f771 100644 --- a/server/lib/activitypub/process/process-accept.ts +++ b/server/lib/activitypub/process/process-accept.ts | |||
@@ -1,12 +1,12 @@ | |||
1 | import { ActivityAccept } from '../../../../shared/models/activitypub/activity' | 1 | import { ActivityAccept } from '../../../../shared/models/activitypub' |
2 | import { database as db } from '../../../initializers' | 2 | import { AccountModel } from '../../../models/account/account' |
3 | import { AccountInstance } from '../../../models/account/account-interface' | 3 | import { AccountFollowModel } from '../../../models/account/account-follow' |
4 | import { addFetchOutboxJob } from '../fetch' | 4 | import { addFetchOutboxJob } from '../fetch' |
5 | 5 | ||
6 | async function processAcceptActivity (activity: ActivityAccept, inboxAccount?: AccountInstance) { | 6 | async function processAcceptActivity (activity: ActivityAccept, inboxAccount?: AccountModel) { |
7 | if (inboxAccount === undefined) throw new Error('Need to accept on explicit inbox.') | 7 | if (inboxAccount === undefined) throw new Error('Need to accept on explicit inbox.') |
8 | 8 | ||
9 | const targetAccount = await db.Account.loadByUrl(activity.actor) | 9 | const targetAccount = await AccountModel.loadByUrl(activity.actor) |
10 | 10 | ||
11 | return processAccept(inboxAccount, targetAccount) | 11 | return processAccept(inboxAccount, targetAccount) |
12 | } | 12 | } |
@@ -19,8 +19,8 @@ export { | |||
19 | 19 | ||
20 | // --------------------------------------------------------------------------- | 20 | // --------------------------------------------------------------------------- |
21 | 21 | ||
22 | async function processAccept (account: AccountInstance, targetAccount: AccountInstance) { | 22 | async function processAccept (account: AccountModel, targetAccount: AccountModel) { |
23 | const follow = await db.AccountFollow.loadByAccountAndTarget(account.id, targetAccount.id) | 23 | const follow = await AccountFollowModel.loadByAccountAndTarget(account.id, targetAccount.id) |
24 | if (!follow) throw new Error('Cannot find associated follow.') | 24 | if (!follow) throw new Error('Cannot find associated follow.') |
25 | 25 | ||
26 | follow.set('state', 'accepted') | 26 | follow.set('state', 'accepted') |
diff --git a/server/lib/activitypub/process/process-add.ts b/server/lib/activitypub/process/process-add.ts index e6bf63eb2..550593eab 100644 --- a/server/lib/activitypub/process/process-add.ts +++ b/server/lib/activitypub/process/process-add.ts | |||
@@ -1,13 +1,15 @@ | |||
1 | import * as Bluebird from 'bluebird' | 1 | import * as Bluebird from 'bluebird' |
2 | import { VideoTorrentObject } from '../../../../shared' | 2 | import { VideoTorrentObject } from '../../../../shared' |
3 | import { ActivityAdd } from '../../../../shared/models/activitypub/activity' | 3 | import { ActivityAdd } from '../../../../shared/models/activitypub' |
4 | import { VideoRateType } from '../../../../shared/models/videos/video-rate.type' | 4 | import { VideoRateType } from '../../../../shared/models/videos' |
5 | import { retryTransactionWrapper } from '../../../helpers/database-utils' | 5 | import { logger, retryTransactionWrapper } from '../../../helpers' |
6 | import { logger } from '../../../helpers/logger' | 6 | import { sequelizeTypescript } from '../../../initializers' |
7 | import { database as db } from '../../../initializers' | 7 | import { AccountModel } from '../../../models/account/account' |
8 | import { AccountInstance } from '../../../models/account/account-interface' | 8 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' |
9 | import { VideoChannelInstance } from '../../../models/video/video-channel-interface' | 9 | import { TagModel } from '../../../models/video/tag' |
10 | import { VideoInstance } from '../../../models/video/video-interface' | 10 | import { VideoModel } from '../../../models/video/video' |
11 | import { VideoChannelModel } from '../../../models/video/video-channel' | ||
12 | import { VideoFileModel } from '../../../models/video/video-file' | ||
11 | import { getOrCreateAccountAndServer } from '../account' | 13 | import { getOrCreateAccountAndServer } from '../account' |
12 | import { getOrCreateVideoChannel } from '../video-channels' | 14 | import { getOrCreateVideoChannel } from '../video-channels' |
13 | import { generateThumbnailFromUrl } from '../videos' | 15 | import { generateThumbnailFromUrl } from '../videos' |
@@ -37,9 +39,9 @@ export { | |||
37 | 39 | ||
38 | // --------------------------------------------------------------------------- | 40 | // --------------------------------------------------------------------------- |
39 | 41 | ||
40 | async function processAddVideo (account: AccountInstance, | 42 | async function processAddVideo (account: AccountModel, |
41 | activity: ActivityAdd, | 43 | activity: ActivityAdd, |
42 | videoChannel: VideoChannelInstance, | 44 | videoChannel: VideoChannelModel, |
43 | videoToCreateData: VideoTorrentObject) { | 45 | videoToCreateData: VideoTorrentObject) { |
44 | const options = { | 46 | const options = { |
45 | arguments: [ account, activity, videoChannel, videoToCreateData ], | 47 | arguments: [ account, activity, videoChannel, videoToCreateData ], |
@@ -64,24 +66,24 @@ async function processAddVideo (account: AccountInstance, | |||
64 | return video | 66 | return video |
65 | } | 67 | } |
66 | 68 | ||
67 | function addRemoteVideo (account: AccountInstance, | 69 | function addRemoteVideo (account: AccountModel, |
68 | activity: ActivityAdd, | 70 | activity: ActivityAdd, |
69 | videoChannel: VideoChannelInstance, | 71 | videoChannel: VideoChannelModel, |
70 | videoToCreateData: VideoTorrentObject) { | 72 | videoToCreateData: VideoTorrentObject) { |
71 | logger.debug('Adding remote video %s.', videoToCreateData.id) | 73 | logger.debug('Adding remote video %s.', videoToCreateData.id) |
72 | 74 | ||
73 | return db.sequelize.transaction(async t => { | 75 | return sequelizeTypescript.transaction(async t => { |
74 | const sequelizeOptions = { | 76 | const sequelizeOptions = { |
75 | transaction: t | 77 | transaction: t |
76 | } | 78 | } |
77 | 79 | ||
78 | if (videoChannel.Account.id !== account.id) throw new Error('Video channel is not owned by this account.') | 80 | if (videoChannel.Account.id !== account.id) throw new Error('Video channel is not owned by this account.') |
79 | 81 | ||
80 | const videoFromDatabase = await db.Video.loadByUUIDOrURL(videoToCreateData.uuid, videoToCreateData.id, t) | 82 | const videoFromDatabase = await VideoModel.loadByUUIDOrURL(videoToCreateData.uuid, videoToCreateData.id, t) |
81 | if (videoFromDatabase) return videoFromDatabase | 83 | if (videoFromDatabase) return videoFromDatabase |
82 | 84 | ||
83 | const videoData = await videoActivityObjectToDBAttributes(videoChannel, videoToCreateData, activity.to, activity.cc) | 85 | const videoData = await videoActivityObjectToDBAttributes(videoChannel, videoToCreateData, activity.to, activity.cc) |
84 | const video = db.Video.build(videoData) | 86 | const video = VideoModel.build(videoData) |
85 | 87 | ||
86 | // Don't block on request | 88 | // Don't block on request |
87 | generateThumbnailFromUrl(video, videoToCreateData.icon) | 89 | generateThumbnailFromUrl(video, videoToCreateData.icon) |
@@ -94,12 +96,12 @@ function addRemoteVideo (account: AccountInstance, | |||
94 | throw new Error('Cannot find valid files for video %s ' + videoToCreateData.url) | 96 | throw new Error('Cannot find valid files for video %s ' + videoToCreateData.url) |
95 | } | 97 | } |
96 | 98 | ||
97 | const tasks: Bluebird<any>[] = videoFileAttributes.map(f => db.VideoFile.create(f, { transaction: t })) | 99 | const tasks: Bluebird<any>[] = videoFileAttributes.map(f => VideoFileModel.create(f, { transaction: t })) |
98 | await Promise.all(tasks) | 100 | await Promise.all(tasks) |
99 | 101 | ||
100 | const tags = videoToCreateData.tag.map(t => t.name) | 102 | const tags = videoToCreateData.tag.map(t => t.name) |
101 | const tagInstances = await db.Tag.findOrCreateTags(tags, t) | 103 | const tagInstances = await TagModel.findOrCreateTags(tags, t) |
102 | await videoCreated.setTags(tagInstances, sequelizeOptions) | 104 | await videoCreated.$set('Tags', tagInstances, sequelizeOptions) |
103 | 105 | ||
104 | logger.info('Remote video with uuid %s inserted.', videoToCreateData.uuid) | 106 | logger.info('Remote video with uuid %s inserted.', videoToCreateData.uuid) |
105 | 107 | ||
@@ -107,13 +109,13 @@ function addRemoteVideo (account: AccountInstance, | |||
107 | }) | 109 | }) |
108 | } | 110 | } |
109 | 111 | ||
110 | async function createRates (accountUrls: string[], video: VideoInstance, rate: VideoRateType) { | 112 | async function createRates (accountUrls: string[], video: VideoModel, rate: VideoRateType) { |
111 | let rateCounts = 0 | 113 | let rateCounts = 0 |
112 | const tasks: Bluebird<any>[] = [] | 114 | const tasks: Bluebird<any>[] = [] |
113 | 115 | ||
114 | for (const accountUrl of accountUrls) { | 116 | for (const accountUrl of accountUrls) { |
115 | const account = await getOrCreateAccountAndServer(accountUrl) | 117 | const account = await getOrCreateAccountAndServer(accountUrl) |
116 | const p = db.AccountVideoRate | 118 | const p = AccountVideoRateModel |
117 | .create({ | 119 | .create({ |
118 | videoId: video.id, | 120 | videoId: video.id, |
119 | accountId: account.id, | 121 | accountId: account.id, |
diff --git a/server/lib/activitypub/process/process-announce.ts b/server/lib/activitypub/process/process-announce.ts index 2aa9ad5c7..ff2c6d708 100644 --- a/server/lib/activitypub/process/process-announce.ts +++ b/server/lib/activitypub/process/process-announce.ts | |||
@@ -1,10 +1,11 @@ | |||
1 | import { ActivityAdd, ActivityAnnounce, ActivityCreate } from '../../../../shared/models/activitypub/activity' | 1 | import { ActivityAdd, ActivityAnnounce, ActivityCreate } from '../../../../shared/models/activitypub' |
2 | import { retryTransactionWrapper } from '../../../helpers/database-utils' | 2 | import { logger, retryTransactionWrapper } from '../../../helpers' |
3 | import { logger } from '../../../helpers/logger' | 3 | import { sequelizeTypescript } from '../../../initializers' |
4 | import { database as db } from '../../../initializers/index' | 4 | import { AccountModel } from '../../../models/account/account' |
5 | import { AccountInstance } from '../../../models/account/account-interface' | 5 | import { VideoModel } from '../../../models/video/video' |
6 | import { VideoInstance } from '../../../models/index' | 6 | import { VideoChannelModel } from '../../../models/video/video-channel' |
7 | import { VideoChannelInstance } from '../../../models/video/video-channel-interface' | 7 | import { VideoChannelShareModel } from '../../../models/video/video-channel-share' |
8 | import { VideoShareModel } from '../../../models/video/video-share' | ||
8 | import { getOrCreateAccountAndServer } from '../account' | 9 | import { getOrCreateAccountAndServer } from '../account' |
9 | import { forwardActivity } from '../send/misc' | 10 | import { forwardActivity } from '../send/misc' |
10 | import { processAddActivity } from './process-add' | 11 | import { processAddActivity } from './process-add' |
@@ -36,7 +37,7 @@ export { | |||
36 | 37 | ||
37 | // --------------------------------------------------------------------------- | 38 | // --------------------------------------------------------------------------- |
38 | 39 | ||
39 | function processVideoChannelShare (accountAnnouncer: AccountInstance, activity: ActivityAnnounce) { | 40 | function processVideoChannelShare (accountAnnouncer: AccountModel, activity: ActivityAnnounce) { |
40 | const options = { | 41 | const options = { |
41 | arguments: [ accountAnnouncer, activity ], | 42 | arguments: [ accountAnnouncer, activity ], |
42 | errorMessage: 'Cannot share the video channel with many retries.' | 43 | errorMessage: 'Cannot share the video channel with many retries.' |
@@ -45,18 +46,18 @@ function processVideoChannelShare (accountAnnouncer: AccountInstance, activity: | |||
45 | return retryTransactionWrapper(shareVideoChannel, options) | 46 | return retryTransactionWrapper(shareVideoChannel, options) |
46 | } | 47 | } |
47 | 48 | ||
48 | async function shareVideoChannel (accountAnnouncer: AccountInstance, activity: ActivityAnnounce) { | 49 | async function shareVideoChannel (accountAnnouncer: AccountModel, activity: ActivityAnnounce) { |
49 | const announcedActivity = activity.object as ActivityCreate | 50 | const announcedActivity = activity.object as ActivityCreate |
50 | 51 | ||
51 | return db.sequelize.transaction(async t => { | 52 | return sequelizeTypescript.transaction(async t => { |
52 | // Add share entry | 53 | // Add share entry |
53 | const videoChannel: VideoChannelInstance = await processCreateActivity(announcedActivity) | 54 | const videoChannel: VideoChannelModel = await processCreateActivity(announcedActivity) |
54 | const share = { | 55 | const share = { |
55 | accountId: accountAnnouncer.id, | 56 | accountId: accountAnnouncer.id, |
56 | videoChannelId: videoChannel.id | 57 | videoChannelId: videoChannel.id |
57 | } | 58 | } |
58 | 59 | ||
59 | const [ , created ] = await db.VideoChannelShare.findOrCreate({ | 60 | const [ , created ] = await VideoChannelShareModel.findOrCreate({ |
60 | where: share, | 61 | where: share, |
61 | defaults: share, | 62 | defaults: share, |
62 | transaction: t | 63 | transaction: t |
@@ -72,7 +73,7 @@ async function shareVideoChannel (accountAnnouncer: AccountInstance, activity: A | |||
72 | }) | 73 | }) |
73 | } | 74 | } |
74 | 75 | ||
75 | function processVideoShare (accountAnnouncer: AccountInstance, activity: ActivityAnnounce) { | 76 | function processVideoShare (accountAnnouncer: AccountModel, activity: ActivityAnnounce) { |
76 | const options = { | 77 | const options = { |
77 | arguments: [ accountAnnouncer, activity ], | 78 | arguments: [ accountAnnouncer, activity ], |
78 | errorMessage: 'Cannot share the video with many retries.' | 79 | errorMessage: 'Cannot share the video with many retries.' |
@@ -81,19 +82,19 @@ function processVideoShare (accountAnnouncer: AccountInstance, activity: Activit | |||
81 | return retryTransactionWrapper(shareVideo, options) | 82 | return retryTransactionWrapper(shareVideo, options) |
82 | } | 83 | } |
83 | 84 | ||
84 | function shareVideo (accountAnnouncer: AccountInstance, activity: ActivityAnnounce) { | 85 | function shareVideo (accountAnnouncer: AccountModel, activity: ActivityAnnounce) { |
85 | const announcedActivity = activity.object as ActivityAdd | 86 | const announcedActivity = activity.object as ActivityAdd |
86 | 87 | ||
87 | return db.sequelize.transaction(async t => { | 88 | return sequelizeTypescript.transaction(async t => { |
88 | // Add share entry | 89 | // Add share entry |
89 | const video: VideoInstance = await processAddActivity(announcedActivity) | 90 | const video: VideoModel = await processAddActivity(announcedActivity) |
90 | 91 | ||
91 | const share = { | 92 | const share = { |
92 | accountId: accountAnnouncer.id, | 93 | accountId: accountAnnouncer.id, |
93 | videoId: video.id | 94 | videoId: video.id |
94 | } | 95 | } |
95 | 96 | ||
96 | const [ , created ] = await db.VideoShare.findOrCreate({ | 97 | const [ , created ] = await VideoShareModel.findOrCreate({ |
97 | where: share, | 98 | where: share, |
98 | defaults: share, | 99 | defaults: share, |
99 | transaction: t | 100 | transaction: t |
diff --git a/server/lib/activitypub/process/process-create.ts b/server/lib/activitypub/process/process-create.ts index 4740dc432..c1eb2a8ab 100644 --- a/server/lib/activitypub/process/process-create.ts +++ b/server/lib/activitypub/process/process-create.ts | |||
@@ -1,10 +1,12 @@ | |||
1 | import { ActivityCreate, VideoChannelObject } from '../../../../shared' | 1 | import { ActivityCreate, VideoChannelObject } from '../../../../shared' |
2 | import { DislikeObject } from '../../../../shared/models/activitypub/objects/dislike-object' | 2 | import { DislikeObject, VideoAbuseObject, ViewObject } from '../../../../shared/models/activitypub/objects' |
3 | import { VideoAbuseObject } from '../../../../shared/models/activitypub/objects/video-abuse-object' | ||
4 | import { ViewObject } from '../../../../shared/models/activitypub/objects/view-object' | ||
5 | import { logger, retryTransactionWrapper } from '../../../helpers' | 3 | import { logger, retryTransactionWrapper } from '../../../helpers' |
6 | import { database as db } from '../../../initializers' | 4 | import { sequelizeTypescript } from '../../../initializers' |
7 | import { AccountInstance } from '../../../models/account/account-interface' | 5 | import { AccountModel } from '../../../models/account/account' |
6 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' | ||
7 | import { VideoModel } from '../../../models/video/video' | ||
8 | import { VideoAbuseModel } from '../../../models/video/video-abuse' | ||
9 | import { VideoChannelModel } from '../../../models/video/video-channel' | ||
8 | import { getOrCreateAccountAndServer } from '../account' | 10 | import { getOrCreateAccountAndServer } from '../account' |
9 | import { forwardActivity } from '../send/misc' | 11 | import { forwardActivity } from '../send/misc' |
10 | import { getVideoChannelActivityPubUrl } from '../url' | 12 | import { getVideoChannelActivityPubUrl } from '../url' |
@@ -37,7 +39,7 @@ export { | |||
37 | 39 | ||
38 | // --------------------------------------------------------------------------- | 40 | // --------------------------------------------------------------------------- |
39 | 41 | ||
40 | async function processCreateDislike (byAccount: AccountInstance, activity: ActivityCreate) { | 42 | async function processCreateDislike (byAccount: AccountModel, activity: ActivityCreate) { |
41 | const options = { | 43 | const options = { |
42 | arguments: [ byAccount, activity ], | 44 | arguments: [ byAccount, activity ], |
43 | errorMessage: 'Cannot dislike the video with many retries.' | 45 | errorMessage: 'Cannot dislike the video with many retries.' |
@@ -46,11 +48,11 @@ async function processCreateDislike (byAccount: AccountInstance, activity: Activ | |||
46 | return retryTransactionWrapper(createVideoDislike, options) | 48 | return retryTransactionWrapper(createVideoDislike, options) |
47 | } | 49 | } |
48 | 50 | ||
49 | function createVideoDislike (byAccount: AccountInstance, activity: ActivityCreate) { | 51 | function createVideoDislike (byAccount: AccountModel, activity: ActivityCreate) { |
50 | const dislike = activity.object as DislikeObject | 52 | const dislike = activity.object as DislikeObject |
51 | 53 | ||
52 | return db.sequelize.transaction(async t => { | 54 | return sequelizeTypescript.transaction(async t => { |
53 | const video = await db.Video.loadByUrlAndPopulateAccount(dislike.object, t) | 55 | const video = await VideoModel.loadByUrlAndPopulateAccount(dislike.object, t) |
54 | if (!video) throw new Error('Unknown video ' + dislike.object) | 56 | if (!video) throw new Error('Unknown video ' + dislike.object) |
55 | 57 | ||
56 | const rate = { | 58 | const rate = { |
@@ -58,7 +60,7 @@ function createVideoDislike (byAccount: AccountInstance, activity: ActivityCreat | |||
58 | videoId: video.id, | 60 | videoId: video.id, |
59 | accountId: byAccount.id | 61 | accountId: byAccount.id |
60 | } | 62 | } |
61 | const [ , created ] = await db.AccountVideoRate.findOrCreate({ | 63 | const [ , created ] = await AccountVideoRateModel.findOrCreate({ |
62 | where: rate, | 64 | where: rate, |
63 | defaults: rate, | 65 | defaults: rate, |
64 | transaction: t | 66 | transaction: t |
@@ -73,14 +75,14 @@ function createVideoDislike (byAccount: AccountInstance, activity: ActivityCreat | |||
73 | }) | 75 | }) |
74 | } | 76 | } |
75 | 77 | ||
76 | async function processCreateView (byAccount: AccountInstance, activity: ActivityCreate) { | 78 | async function processCreateView (byAccount: AccountModel, activity: ActivityCreate) { |
77 | const view = activity.object as ViewObject | 79 | const view = activity.object as ViewObject |
78 | 80 | ||
79 | const video = await db.Video.loadByUrlAndPopulateAccount(view.object) | 81 | const video = await VideoModel.loadByUrlAndPopulateAccount(view.object) |
80 | 82 | ||
81 | if (!video) throw new Error('Unknown video ' + view.object) | 83 | if (!video) throw new Error('Unknown video ' + view.object) |
82 | 84 | ||
83 | const account = await db.Account.loadByUrl(view.actor) | 85 | const account = await AccountModel.loadByUrl(view.actor) |
84 | if (!account) throw new Error('Unknown account ' + view.actor) | 86 | if (!account) throw new Error('Unknown account ' + view.actor) |
85 | 87 | ||
86 | await video.increment('views') | 88 | await video.increment('views') |
@@ -92,7 +94,7 @@ async function processCreateView (byAccount: AccountInstance, activity: Activity | |||
92 | } | 94 | } |
93 | } | 95 | } |
94 | 96 | ||
95 | async function processCreateVideoChannel (account: AccountInstance, videoChannelToCreateData: VideoChannelObject) { | 97 | async function processCreateVideoChannel (account: AccountModel, videoChannelToCreateData: VideoChannelObject) { |
96 | const options = { | 98 | const options = { |
97 | arguments: [ account, videoChannelToCreateData ], | 99 | arguments: [ account, videoChannelToCreateData ], |
98 | errorMessage: 'Cannot insert the remote video channel with many retries.' | 100 | errorMessage: 'Cannot insert the remote video channel with many retries.' |
@@ -107,15 +109,15 @@ async function processCreateVideoChannel (account: AccountInstance, videoChannel | |||
107 | return videoChannel | 109 | return videoChannel |
108 | } | 110 | } |
109 | 111 | ||
110 | function addRemoteVideoChannel (account: AccountInstance, videoChannelToCreateData: VideoChannelObject) { | 112 | function addRemoteVideoChannel (account: AccountModel, videoChannelToCreateData: VideoChannelObject) { |
111 | logger.debug('Adding remote video channel "%s".', videoChannelToCreateData.uuid) | 113 | logger.debug('Adding remote video channel "%s".', videoChannelToCreateData.uuid) |
112 | 114 | ||
113 | return db.sequelize.transaction(async t => { | 115 | return sequelizeTypescript.transaction(async t => { |
114 | let videoChannel = await db.VideoChannel.loadByUUIDOrUrl(videoChannelToCreateData.uuid, videoChannelToCreateData.id, t) | 116 | let videoChannel = await VideoChannelModel.loadByUUIDOrUrl(videoChannelToCreateData.uuid, videoChannelToCreateData.id, t) |
115 | if (videoChannel) return videoChannel | 117 | if (videoChannel) return videoChannel |
116 | 118 | ||
117 | const videoChannelData = videoChannelActivityObjectToDBAttributes(videoChannelToCreateData, account) | 119 | const videoChannelData = videoChannelActivityObjectToDBAttributes(videoChannelToCreateData, account) |
118 | videoChannel = db.VideoChannel.build(videoChannelData) | 120 | videoChannel = new VideoChannelModel(videoChannelData) |
119 | videoChannel.url = getVideoChannelActivityPubUrl(videoChannel) | 121 | videoChannel.url = getVideoChannelActivityPubUrl(videoChannel) |
120 | 122 | ||
121 | videoChannel = await videoChannel.save({ transaction: t }) | 123 | videoChannel = await videoChannel.save({ transaction: t }) |
@@ -125,7 +127,7 @@ function addRemoteVideoChannel (account: AccountInstance, videoChannelToCreateDa | |||
125 | }) | 127 | }) |
126 | } | 128 | } |
127 | 129 | ||
128 | function processCreateVideoAbuse (account: AccountInstance, videoAbuseToCreateData: VideoAbuseObject) { | 130 | function processCreateVideoAbuse (account: AccountModel, videoAbuseToCreateData: VideoAbuseObject) { |
129 | const options = { | 131 | const options = { |
130 | arguments: [ account, videoAbuseToCreateData ], | 132 | arguments: [ account, videoAbuseToCreateData ], |
131 | errorMessage: 'Cannot insert the remote video abuse with many retries.' | 133 | errorMessage: 'Cannot insert the remote video abuse with many retries.' |
@@ -134,11 +136,11 @@ function processCreateVideoAbuse (account: AccountInstance, videoAbuseToCreateDa | |||
134 | return retryTransactionWrapper(addRemoteVideoAbuse, options) | 136 | return retryTransactionWrapper(addRemoteVideoAbuse, options) |
135 | } | 137 | } |
136 | 138 | ||
137 | function addRemoteVideoAbuse (account: AccountInstance, videoAbuseToCreateData: VideoAbuseObject) { | 139 | function addRemoteVideoAbuse (account: AccountModel, videoAbuseToCreateData: VideoAbuseObject) { |
138 | logger.debug('Reporting remote abuse for video %s.', videoAbuseToCreateData.object) | 140 | logger.debug('Reporting remote abuse for video %s.', videoAbuseToCreateData.object) |
139 | 141 | ||
140 | return db.sequelize.transaction(async t => { | 142 | return sequelizeTypescript.transaction(async t => { |
141 | const video = await db.Video.loadByUrlAndPopulateAccount(videoAbuseToCreateData.object, t) | 143 | const video = await VideoModel.loadByUrlAndPopulateAccount(videoAbuseToCreateData.object, t) |
142 | if (!video) { | 144 | if (!video) { |
143 | logger.warn('Unknown video %s for remote video abuse.', videoAbuseToCreateData.object) | 145 | logger.warn('Unknown video %s for remote video abuse.', videoAbuseToCreateData.object) |
144 | return undefined | 146 | return undefined |
@@ -150,7 +152,7 @@ function addRemoteVideoAbuse (account: AccountInstance, videoAbuseToCreateData: | |||
150 | videoId: video.id | 152 | videoId: video.id |
151 | } | 153 | } |
152 | 154 | ||
153 | await db.VideoAbuse.create(videoAbuseData) | 155 | await VideoAbuseModel.create(videoAbuseData) |
154 | 156 | ||
155 | logger.info('Remote abuse for video uuid %s created', videoAbuseToCreateData.object) | 157 | logger.info('Remote abuse for video uuid %s created', videoAbuseToCreateData.object) |
156 | }) | 158 | }) |
diff --git a/server/lib/activitypub/process/process-delete.ts b/server/lib/activitypub/process/process-delete.ts index 41cdc236d..8f280d37f 100644 --- a/server/lib/activitypub/process/process-delete.ts +++ b/server/lib/activitypub/process/process-delete.ts | |||
@@ -1,10 +1,9 @@ | |||
1 | import { ActivityDelete } from '../../../../shared/models/activitypub/activity' | 1 | import { ActivityDelete } from '../../../../shared/models/activitypub' |
2 | import { retryTransactionWrapper } from '../../../helpers/database-utils' | 2 | import { logger, retryTransactionWrapper } from '../../../helpers' |
3 | import { logger } from '../../../helpers/logger' | 3 | import { sequelizeTypescript } from '../../../initializers' |
4 | import { database as db } from '../../../initializers' | 4 | import { AccountModel } from '../../../models/account/account' |
5 | import { AccountInstance } from '../../../models/account/account-interface' | 5 | import { VideoModel } from '../../../models/video/video' |
6 | import { VideoChannelInstance } from '../../../models/video/video-channel-interface' | 6 | import { VideoChannelModel } from '../../../models/video/video-channel' |
7 | import { VideoInstance } from '../../../models/video/video-interface' | ||
8 | import { getOrCreateAccountAndServer } from '../account' | 7 | import { getOrCreateAccountAndServer } from '../account' |
9 | 8 | ||
10 | async function processDeleteActivity (activity: ActivityDelete) { | 9 | async function processDeleteActivity (activity: ActivityDelete) { |
@@ -15,14 +14,14 @@ async function processDeleteActivity (activity: ActivityDelete) { | |||
15 | } | 14 | } |
16 | 15 | ||
17 | { | 16 | { |
18 | let videoObject = await db.Video.loadByUrlAndPopulateAccount(activity.id) | 17 | let videoObject = await VideoModel.loadByUrlAndPopulateAccount(activity.id) |
19 | if (videoObject !== undefined) { | 18 | if (videoObject !== undefined) { |
20 | return processDeleteVideo(account, videoObject) | 19 | return processDeleteVideo(account, videoObject) |
21 | } | 20 | } |
22 | } | 21 | } |
23 | 22 | ||
24 | { | 23 | { |
25 | let videoChannelObject = await db.VideoChannel.loadByUrl(activity.id) | 24 | let videoChannelObject = await VideoChannelModel.loadByUrl(activity.id) |
26 | if (videoChannelObject !== undefined) { | 25 | if (videoChannelObject !== undefined) { |
27 | return processDeleteVideoChannel(account, videoChannelObject) | 26 | return processDeleteVideoChannel(account, videoChannelObject) |
28 | } | 27 | } |
@@ -39,7 +38,7 @@ export { | |||
39 | 38 | ||
40 | // --------------------------------------------------------------------------- | 39 | // --------------------------------------------------------------------------- |
41 | 40 | ||
42 | async function processDeleteVideo (account: AccountInstance, videoToDelete: VideoInstance) { | 41 | async function processDeleteVideo (account: AccountModel, videoToDelete: VideoModel) { |
43 | const options = { | 42 | const options = { |
44 | arguments: [ account, videoToDelete ], | 43 | arguments: [ account, videoToDelete ], |
45 | errorMessage: 'Cannot remove the remote video with many retries.' | 44 | errorMessage: 'Cannot remove the remote video with many retries.' |
@@ -48,10 +47,10 @@ async function processDeleteVideo (account: AccountInstance, videoToDelete: Vide | |||
48 | await retryTransactionWrapper(deleteRemoteVideo, options) | 47 | await retryTransactionWrapper(deleteRemoteVideo, options) |
49 | } | 48 | } |
50 | 49 | ||
51 | async function deleteRemoteVideo (account: AccountInstance, videoToDelete: VideoInstance) { | 50 | async function deleteRemoteVideo (account: AccountModel, videoToDelete: VideoModel) { |
52 | logger.debug('Removing remote video "%s".', videoToDelete.uuid) | 51 | logger.debug('Removing remote video "%s".', videoToDelete.uuid) |
53 | 52 | ||
54 | await db.sequelize.transaction(async t => { | 53 | await sequelizeTypescript.transaction(async t => { |
55 | if (videoToDelete.VideoChannel.Account.id !== account.id) { | 54 | if (videoToDelete.VideoChannel.Account.id !== account.id) { |
56 | throw new Error('Account ' + account.url + ' does not own video channel ' + videoToDelete.VideoChannel.url) | 55 | throw new Error('Account ' + account.url + ' does not own video channel ' + videoToDelete.VideoChannel.url) |
57 | } | 56 | } |
@@ -62,7 +61,7 @@ async function deleteRemoteVideo (account: AccountInstance, videoToDelete: Video | |||
62 | logger.info('Remote video with uuid %s removed.', videoToDelete.uuid) | 61 | logger.info('Remote video with uuid %s removed.', videoToDelete.uuid) |
63 | } | 62 | } |
64 | 63 | ||
65 | async function processDeleteVideoChannel (account: AccountInstance, videoChannelToRemove: VideoChannelInstance) { | 64 | async function processDeleteVideoChannel (account: AccountModel, videoChannelToRemove: VideoChannelModel) { |
66 | const options = { | 65 | const options = { |
67 | arguments: [ account, videoChannelToRemove ], | 66 | arguments: [ account, videoChannelToRemove ], |
68 | errorMessage: 'Cannot remove the remote video channel with many retries.' | 67 | errorMessage: 'Cannot remove the remote video channel with many retries.' |
@@ -71,10 +70,10 @@ async function processDeleteVideoChannel (account: AccountInstance, videoChannel | |||
71 | await retryTransactionWrapper(deleteRemoteVideoChannel, options) | 70 | await retryTransactionWrapper(deleteRemoteVideoChannel, options) |
72 | } | 71 | } |
73 | 72 | ||
74 | async function deleteRemoteVideoChannel (account: AccountInstance, videoChannelToRemove: VideoChannelInstance) { | 73 | async function deleteRemoteVideoChannel (account: AccountModel, videoChannelToRemove: VideoChannelModel) { |
75 | logger.debug('Removing remote video channel "%s".', videoChannelToRemove.uuid) | 74 | logger.debug('Removing remote video channel "%s".', videoChannelToRemove.uuid) |
76 | 75 | ||
77 | await db.sequelize.transaction(async t => { | 76 | await sequelizeTypescript.transaction(async t => { |
78 | if (videoChannelToRemove.Account.id !== account.id) { | 77 | if (videoChannelToRemove.Account.id !== account.id) { |
79 | throw new Error('Account ' + account.url + ' does not own video channel ' + videoChannelToRemove.url) | 78 | throw new Error('Account ' + account.url + ' does not own video channel ' + videoChannelToRemove.url) |
80 | } | 79 | } |
@@ -85,7 +84,7 @@ async function deleteRemoteVideoChannel (account: AccountInstance, videoChannelT | |||
85 | logger.info('Remote video channel with uuid %s removed.', videoChannelToRemove.uuid) | 84 | logger.info('Remote video channel with uuid %s removed.', videoChannelToRemove.uuid) |
86 | } | 85 | } |
87 | 86 | ||
88 | async function processDeleteAccount (accountToRemove: AccountInstance) { | 87 | async function processDeleteAccount (accountToRemove: AccountModel) { |
89 | const options = { | 88 | const options = { |
90 | arguments: [ accountToRemove ], | 89 | arguments: [ accountToRemove ], |
91 | errorMessage: 'Cannot remove the remote account with many retries.' | 90 | errorMessage: 'Cannot remove the remote account with many retries.' |
@@ -94,10 +93,10 @@ async function processDeleteAccount (accountToRemove: AccountInstance) { | |||
94 | await retryTransactionWrapper(deleteRemoteAccount, options) | 93 | await retryTransactionWrapper(deleteRemoteAccount, options) |
95 | } | 94 | } |
96 | 95 | ||
97 | async function deleteRemoteAccount (accountToRemove: AccountInstance) { | 96 | async function deleteRemoteAccount (accountToRemove: AccountModel) { |
98 | logger.debug('Removing remote account "%s".', accountToRemove.uuid) | 97 | logger.debug('Removing remote account "%s".', accountToRemove.uuid) |
99 | 98 | ||
100 | await db.sequelize.transaction(async t => { | 99 | await sequelizeTypescript.transaction(async t => { |
101 | await accountToRemove.destroy({ transaction: t }) | 100 | await accountToRemove.destroy({ transaction: t }) |
102 | }) | 101 | }) |
103 | 102 | ||
diff --git a/server/lib/activitypub/process/process-follow.ts b/server/lib/activitypub/process/process-follow.ts index 320dc1138..ccaee43a6 100644 --- a/server/lib/activitypub/process/process-follow.ts +++ b/server/lib/activitypub/process/process-follow.ts | |||
@@ -1,10 +1,10 @@ | |||
1 | import { ActivityFollow } from '../../../../shared/models/activitypub/activity' | 1 | import { ActivityFollow } from '../../../../shared/models/activitypub' |
2 | import { retryTransactionWrapper } from '../../../helpers' | 2 | import { logger, retryTransactionWrapper } from '../../../helpers' |
3 | import { database as db } from '../../../initializers' | 3 | import { sequelizeTypescript } from '../../../initializers' |
4 | import { AccountInstance } from '../../../models/account/account-interface' | 4 | import { AccountModel } from '../../../models/account/account' |
5 | import { logger } from '../../../helpers/logger' | 5 | import { AccountFollowModel } from '../../../models/account/account-follow' |
6 | import { sendAccept } from '../send/send-accept' | ||
7 | import { getOrCreateAccountAndServer } from '../account' | 6 | import { getOrCreateAccountAndServer } from '../account' |
7 | import { sendAccept } from '../send' | ||
8 | 8 | ||
9 | async function processFollowActivity (activity: ActivityFollow) { | 9 | async function processFollowActivity (activity: ActivityFollow) { |
10 | const activityObject = activity.object | 10 | const activityObject = activity.object |
@@ -21,7 +21,7 @@ export { | |||
21 | 21 | ||
22 | // --------------------------------------------------------------------------- | 22 | // --------------------------------------------------------------------------- |
23 | 23 | ||
24 | function processFollow (account: AccountInstance, targetAccountURL: string) { | 24 | function processFollow (account: AccountModel, targetAccountURL: string) { |
25 | const options = { | 25 | const options = { |
26 | arguments: [ account, targetAccountURL ], | 26 | arguments: [ account, targetAccountURL ], |
27 | errorMessage: 'Cannot follow with many retries.' | 27 | errorMessage: 'Cannot follow with many retries.' |
@@ -30,14 +30,14 @@ function processFollow (account: AccountInstance, targetAccountURL: string) { | |||
30 | return retryTransactionWrapper(follow, options) | 30 | return retryTransactionWrapper(follow, options) |
31 | } | 31 | } |
32 | 32 | ||
33 | async function follow (account: AccountInstance, targetAccountURL: string) { | 33 | async function follow (account: AccountModel, targetAccountURL: string) { |
34 | await db.sequelize.transaction(async t => { | 34 | await sequelizeTypescript.transaction(async t => { |
35 | const targetAccount = await db.Account.loadByUrl(targetAccountURL, t) | 35 | const targetAccount = await AccountModel.loadByUrl(targetAccountURL, t) |
36 | 36 | ||
37 | if (!targetAccount) throw new Error('Unknown account') | 37 | if (!targetAccount) throw new Error('Unknown account') |
38 | if (targetAccount.isOwned() === false) throw new Error('This is not a local account.') | 38 | if (targetAccount.isOwned() === false) throw new Error('This is not a local account.') |
39 | 39 | ||
40 | const [ accountFollow ] = await db.AccountFollow.findOrCreate({ | 40 | const [ accountFollow ] = await AccountFollowModel.findOrCreate({ |
41 | where: { | 41 | where: { |
42 | accountId: account.id, | 42 | accountId: account.id, |
43 | targetAccountId: targetAccount.id | 43 | targetAccountId: targetAccount.id |
diff --git a/server/lib/activitypub/process/process-like.ts b/server/lib/activitypub/process/process-like.ts index 5f2ffe7ea..a6e391f1e 100644 --- a/server/lib/activitypub/process/process-like.ts +++ b/server/lib/activitypub/process/process-like.ts | |||
@@ -1,7 +1,9 @@ | |||
1 | import { ActivityLike } from '../../../../shared/models/activitypub/activity' | 1 | import { ActivityLike } from '../../../../shared/models/activitypub' |
2 | import { retryTransactionWrapper } from '../../../helpers/database-utils' | 2 | import { retryTransactionWrapper } from '../../../helpers' |
3 | import { database as db } from '../../../initializers' | 3 | import { sequelizeTypescript } from '../../../initializers' |
4 | import { AccountInstance } from '../../../models/account/account-interface' | 4 | import { AccountModel } from '../../../models/account/account' |
5 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' | ||
6 | import { VideoModel } from '../../../models/video/video' | ||
5 | import { getOrCreateAccountAndServer } from '../account' | 7 | import { getOrCreateAccountAndServer } from '../account' |
6 | import { forwardActivity } from '../send/misc' | 8 | import { forwardActivity } from '../send/misc' |
7 | 9 | ||
@@ -19,7 +21,7 @@ export { | |||
19 | 21 | ||
20 | // --------------------------------------------------------------------------- | 22 | // --------------------------------------------------------------------------- |
21 | 23 | ||
22 | async function processLikeVideo (byAccount: AccountInstance, activity: ActivityLike) { | 24 | async function processLikeVideo (byAccount: AccountModel, activity: ActivityLike) { |
23 | const options = { | 25 | const options = { |
24 | arguments: [ byAccount, activity ], | 26 | arguments: [ byAccount, activity ], |
25 | errorMessage: 'Cannot like the video with many retries.' | 27 | errorMessage: 'Cannot like the video with many retries.' |
@@ -28,11 +30,11 @@ async function processLikeVideo (byAccount: AccountInstance, activity: ActivityL | |||
28 | return retryTransactionWrapper(createVideoLike, options) | 30 | return retryTransactionWrapper(createVideoLike, options) |
29 | } | 31 | } |
30 | 32 | ||
31 | function createVideoLike (byAccount: AccountInstance, activity: ActivityLike) { | 33 | function createVideoLike (byAccount: AccountModel, activity: ActivityLike) { |
32 | const videoUrl = activity.object | 34 | const videoUrl = activity.object |
33 | 35 | ||
34 | return db.sequelize.transaction(async t => { | 36 | return sequelizeTypescript.transaction(async t => { |
35 | const video = await db.Video.loadByUrlAndPopulateAccount(videoUrl) | 37 | const video = await VideoModel.loadByUrlAndPopulateAccount(videoUrl) |
36 | 38 | ||
37 | if (!video) throw new Error('Unknown video ' + videoUrl) | 39 | if (!video) throw new Error('Unknown video ' + videoUrl) |
38 | 40 | ||
@@ -41,7 +43,7 @@ function createVideoLike (byAccount: AccountInstance, activity: ActivityLike) { | |||
41 | videoId: video.id, | 43 | videoId: video.id, |
42 | accountId: byAccount.id | 44 | accountId: byAccount.id |
43 | } | 45 | } |
44 | const [ , created ] = await db.AccountVideoRate.findOrCreate({ | 46 | const [ , created ] = await AccountVideoRateModel.findOrCreate({ |
45 | where: rate, | 47 | where: rate, |
46 | defaults: rate, | 48 | defaults: rate, |
47 | transaction: t | 49 | transaction: t |
diff --git a/server/lib/activitypub/process/process-undo.ts b/server/lib/activitypub/process/process-undo.ts index cc221045f..efa63122b 100644 --- a/server/lib/activitypub/process/process-undo.ts +++ b/server/lib/activitypub/process/process-undo.ts | |||
@@ -1,8 +1,11 @@ | |||
1 | import { ActivityFollow, ActivityLike, ActivityUndo } from '../../../../shared/models/activitypub/activity' | 1 | import { ActivityFollow, ActivityLike, ActivityUndo } from '../../../../shared/models/activitypub' |
2 | import { DislikeObject } from '../../../../shared/models/activitypub/objects/dislike-object' | 2 | import { DislikeObject } from '../../../../shared/models/activitypub/objects' |
3 | import { retryTransactionWrapper } from '../../../helpers/database-utils' | 3 | import { logger, retryTransactionWrapper } from '../../../helpers' |
4 | import { logger } from '../../../helpers/logger' | 4 | import { sequelizeTypescript } from '../../../initializers' |
5 | import { database as db } from '../../../initializers' | 5 | import { AccountModel } from '../../../models/account/account' |
6 | import { AccountFollowModel } from '../../../models/account/account-follow' | ||
7 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' | ||
8 | import { VideoModel } from '../../../models/video/video' | ||
6 | import { forwardActivity } from '../send/misc' | 9 | import { forwardActivity } from '../send/misc' |
7 | 10 | ||
8 | async function processUndoActivity (activity: ActivityUndo) { | 11 | async function processUndoActivity (activity: ActivityUndo) { |
@@ -41,14 +44,14 @@ function processUndoLike (actor: string, activity: ActivityUndo) { | |||
41 | function undoLike (actor: string, activity: ActivityUndo) { | 44 | function undoLike (actor: string, activity: ActivityUndo) { |
42 | const likeActivity = activity.object as ActivityLike | 45 | const likeActivity = activity.object as ActivityLike |
43 | 46 | ||
44 | return db.sequelize.transaction(async t => { | 47 | return sequelizeTypescript.transaction(async t => { |
45 | const byAccount = await db.Account.loadByUrl(actor, t) | 48 | const byAccount = await AccountModel.loadByUrl(actor, t) |
46 | if (!byAccount) throw new Error('Unknown account ' + actor) | 49 | if (!byAccount) throw new Error('Unknown account ' + actor) |
47 | 50 | ||
48 | const video = await db.Video.loadByUrlAndPopulateAccount(likeActivity.object, t) | 51 | const video = await VideoModel.loadByUrlAndPopulateAccount(likeActivity.object, t) |
49 | if (!video) throw new Error('Unknown video ' + likeActivity.actor) | 52 | if (!video) throw new Error('Unknown video ' + likeActivity.actor) |
50 | 53 | ||
51 | const rate = await db.AccountVideoRate.load(byAccount.id, video.id, t) | 54 | const rate = await AccountVideoRateModel.load(byAccount.id, video.id, t) |
52 | if (!rate) throw new Error(`Unknown rate by account ${byAccount.id} for video ${video.id}.`) | 55 | if (!rate) throw new Error(`Unknown rate by account ${byAccount.id} for video ${video.id}.`) |
53 | 56 | ||
54 | await rate.destroy({ transaction: t }) | 57 | await rate.destroy({ transaction: t }) |
@@ -74,14 +77,14 @@ function processUndoDislike (actor: string, activity: ActivityUndo) { | |||
74 | function undoDislike (actor: string, activity: ActivityUndo) { | 77 | function undoDislike (actor: string, activity: ActivityUndo) { |
75 | const dislike = activity.object.object as DislikeObject | 78 | const dislike = activity.object.object as DislikeObject |
76 | 79 | ||
77 | return db.sequelize.transaction(async t => { | 80 | return sequelizeTypescript.transaction(async t => { |
78 | const byAccount = await db.Account.loadByUrl(actor, t) | 81 | const byAccount = await AccountModel.loadByUrl(actor, t) |
79 | if (!byAccount) throw new Error('Unknown account ' + actor) | 82 | if (!byAccount) throw new Error('Unknown account ' + actor) |
80 | 83 | ||
81 | const video = await db.Video.loadByUrlAndPopulateAccount(dislike.object, t) | 84 | const video = await VideoModel.loadByUrlAndPopulateAccount(dislike.object, t) |
82 | if (!video) throw new Error('Unknown video ' + dislike.actor) | 85 | if (!video) throw new Error('Unknown video ' + dislike.actor) |
83 | 86 | ||
84 | const rate = await db.AccountVideoRate.load(byAccount.id, video.id, t) | 87 | const rate = await AccountVideoRateModel.load(byAccount.id, video.id, t) |
85 | if (!rate) throw new Error(`Unknown rate by account ${byAccount.id} for video ${video.id}.`) | 88 | if (!rate) throw new Error(`Unknown rate by account ${byAccount.id} for video ${video.id}.`) |
86 | 89 | ||
87 | await rate.destroy({ transaction: t }) | 90 | await rate.destroy({ transaction: t }) |
@@ -105,10 +108,10 @@ function processUndoFollow (actor: string, followActivity: ActivityFollow) { | |||
105 | } | 108 | } |
106 | 109 | ||
107 | function undoFollow (actor: string, followActivity: ActivityFollow) { | 110 | function undoFollow (actor: string, followActivity: ActivityFollow) { |
108 | return db.sequelize.transaction(async t => { | 111 | return sequelizeTypescript.transaction(async t => { |
109 | const follower = await db.Account.loadByUrl(actor, t) | 112 | const follower = await AccountModel.loadByUrl(actor, t) |
110 | const following = await db.Account.loadByUrl(followActivity.object, t) | 113 | const following = await AccountModel.loadByUrl(followActivity.object, t) |
111 | const accountFollow = await db.AccountFollow.loadByAccountAndTarget(follower.id, following.id, t) | 114 | const accountFollow = await AccountFollowModel.loadByAccountAndTarget(follower.id, following.id, t) |
112 | 115 | ||
113 | if (!accountFollow) throw new Error(`'Unknown account follow ${follower.id} -> ${following.id}.`) | 116 | if (!accountFollow) throw new Error(`'Unknown account follow ${follower.id} -> ${following.id}.`) |
114 | 117 | ||
diff --git a/server/lib/activitypub/process/process-update.ts b/server/lib/activitypub/process/process-update.ts index 11c6de8f5..771021f0c 100644 --- a/server/lib/activitypub/process/process-update.ts +++ b/server/lib/activitypub/process/process-update.ts | |||
@@ -1,12 +1,13 @@ | |||
1 | import * as Bluebird from 'bluebird' | 1 | import * as Bluebird from 'bluebird' |
2 | import { VideoChannelObject, VideoTorrentObject } from '../../../../shared' | 2 | import { VideoChannelObject, VideoTorrentObject } from '../../../../shared' |
3 | import { ActivityUpdate } from '../../../../shared/models/activitypub/activity' | 3 | import { ActivityUpdate } from '../../../../shared/models/activitypub' |
4 | import { retryTransactionWrapper } from '../../../helpers/database-utils' | 4 | import { logger, resetSequelizeInstance, retryTransactionWrapper } from '../../../helpers' |
5 | import { logger } from '../../../helpers/logger' | 5 | import { sequelizeTypescript } from '../../../initializers' |
6 | import { resetSequelizeInstance } from '../../../helpers/utils' | 6 | import { AccountModel } from '../../../models/account/account' |
7 | import { database as db } from '../../../initializers' | 7 | import { TagModel } from '../../../models/video/tag' |
8 | import { AccountInstance } from '../../../models/account/account-interface' | 8 | import { VideoModel } from '../../../models/video/video' |
9 | import { VideoInstance } from '../../../models/video/video-interface' | 9 | import { VideoChannelModel } from '../../../models/video/video-channel' |
10 | import { VideoFileModel } from '../../../models/video/video-file' | ||
10 | import { getOrCreateAccountAndServer } from '../account' | 11 | import { getOrCreateAccountAndServer } from '../account' |
11 | import { videoActivityObjectToDBAttributes, videoFileActivityUrlToDBAttributes } from './misc' | 12 | import { videoActivityObjectToDBAttributes, videoFileActivityUrlToDBAttributes } from './misc' |
12 | 13 | ||
@@ -30,7 +31,7 @@ export { | |||
30 | 31 | ||
31 | // --------------------------------------------------------------------------- | 32 | // --------------------------------------------------------------------------- |
32 | 33 | ||
33 | function processUpdateVideo (account: AccountInstance, video: VideoTorrentObject) { | 34 | function processUpdateVideo (account: AccountModel, video: VideoTorrentObject) { |
34 | const options = { | 35 | const options = { |
35 | arguments: [ account, video ], | 36 | arguments: [ account, video ], |
36 | errorMessage: 'Cannot update the remote video with many retries' | 37 | errorMessage: 'Cannot update the remote video with many retries' |
@@ -39,18 +40,18 @@ function processUpdateVideo (account: AccountInstance, video: VideoTorrentObject | |||
39 | return retryTransactionWrapper(updateRemoteVideo, options) | 40 | return retryTransactionWrapper(updateRemoteVideo, options) |
40 | } | 41 | } |
41 | 42 | ||
42 | async function updateRemoteVideo (account: AccountInstance, videoAttributesToUpdate: VideoTorrentObject) { | 43 | async function updateRemoteVideo (account: AccountModel, videoAttributesToUpdate: VideoTorrentObject) { |
43 | logger.debug('Updating remote video "%s".', videoAttributesToUpdate.uuid) | 44 | logger.debug('Updating remote video "%s".', videoAttributesToUpdate.uuid) |
44 | let videoInstance: VideoInstance | 45 | let videoInstance: VideoModel |
45 | let videoFieldsSave: object | 46 | let videoFieldsSave: object |
46 | 47 | ||
47 | try { | 48 | try { |
48 | await db.sequelize.transaction(async t => { | 49 | await sequelizeTypescript.transaction(async t => { |
49 | const sequelizeOptions = { | 50 | const sequelizeOptions = { |
50 | transaction: t | 51 | transaction: t |
51 | } | 52 | } |
52 | 53 | ||
53 | const videoInstance = await db.Video.loadByUrlAndPopulateAccount(videoAttributesToUpdate.id, t) | 54 | const videoInstance = await VideoModel.loadByUrlAndPopulateAccount(videoAttributesToUpdate.id, t) |
54 | if (!videoInstance) throw new Error('Video ' + videoAttributesToUpdate.id + ' not found.') | 55 | if (!videoInstance) throw new Error('Video ' + videoAttributesToUpdate.id + ' not found.') |
55 | 56 | ||
56 | if (videoInstance.VideoChannel.Account.id !== account.id) { | 57 | if (videoInstance.VideoChannel.Account.id !== account.id) { |
@@ -81,12 +82,12 @@ async function updateRemoteVideo (account: AccountInstance, videoAttributesToUpd | |||
81 | await Promise.all(videoFileDestroyTasks) | 82 | await Promise.all(videoFileDestroyTasks) |
82 | 83 | ||
83 | const videoFileAttributes = videoFileActivityUrlToDBAttributes(videoInstance, videoAttributesToUpdate) | 84 | const videoFileAttributes = videoFileActivityUrlToDBAttributes(videoInstance, videoAttributesToUpdate) |
84 | const tasks: Bluebird<any>[] = videoFileAttributes.map(f => db.VideoFile.create(f)) | 85 | const tasks: Bluebird<any>[] = videoFileAttributes.map(f => VideoFileModel.create(f)) |
85 | await Promise.all(tasks) | 86 | await Promise.all(tasks) |
86 | 87 | ||
87 | const tags = videoAttributesToUpdate.tag.map(t => t.name) | 88 | const tags = videoAttributesToUpdate.tag.map(t => t.name) |
88 | const tagInstances = await db.Tag.findOrCreateTags(tags, t) | 89 | const tagInstances = await TagModel.findOrCreateTags(tags, t) |
89 | await videoInstance.setTags(tagInstances, sequelizeOptions) | 90 | await videoInstance.$set('Tags', tagInstances, sequelizeOptions) |
90 | }) | 91 | }) |
91 | 92 | ||
92 | logger.info('Remote video with uuid %s updated', videoAttributesToUpdate.uuid) | 93 | logger.info('Remote video with uuid %s updated', videoAttributesToUpdate.uuid) |
@@ -101,7 +102,7 @@ async function updateRemoteVideo (account: AccountInstance, videoAttributesToUpd | |||
101 | } | 102 | } |
102 | } | 103 | } |
103 | 104 | ||
104 | async function processUpdateVideoChannel (account: AccountInstance, videoChannel: VideoChannelObject) { | 105 | async function processUpdateVideoChannel (account: AccountModel, videoChannel: VideoChannelObject) { |
105 | const options = { | 106 | const options = { |
106 | arguments: [ account, videoChannel ], | 107 | arguments: [ account, videoChannel ], |
107 | errorMessage: 'Cannot update the remote video channel with many retries.' | 108 | errorMessage: 'Cannot update the remote video channel with many retries.' |
@@ -110,13 +111,13 @@ async function processUpdateVideoChannel (account: AccountInstance, videoChannel | |||
110 | await retryTransactionWrapper(updateRemoteVideoChannel, options) | 111 | await retryTransactionWrapper(updateRemoteVideoChannel, options) |
111 | } | 112 | } |
112 | 113 | ||
113 | async function updateRemoteVideoChannel (account: AccountInstance, videoChannel: VideoChannelObject) { | 114 | async function updateRemoteVideoChannel (account: AccountModel, videoChannel: VideoChannelObject) { |
114 | logger.debug('Updating remote video channel "%s".', videoChannel.uuid) | 115 | logger.debug('Updating remote video channel "%s".', videoChannel.uuid) |
115 | 116 | ||
116 | await db.sequelize.transaction(async t => { | 117 | await sequelizeTypescript.transaction(async t => { |
117 | const sequelizeOptions = { transaction: t } | 118 | const sequelizeOptions = { transaction: t } |
118 | 119 | ||
119 | const videoChannelInstance = await db.VideoChannel.loadByUrl(videoChannel.id) | 120 | const videoChannelInstance = await VideoChannelModel.loadByUrl(videoChannel.id) |
120 | if (!videoChannelInstance) throw new Error('Video ' + videoChannel.id + ' not found.') | 121 | if (!videoChannelInstance) throw new Error('Video ' + videoChannel.id + ' not found.') |
121 | 122 | ||
122 | if (videoChannelInstance.Account.id !== account.id) { | 123 | if (videoChannelInstance.Account.id !== account.id) { |
diff --git a/server/lib/activitypub/process/process.ts b/server/lib/activitypub/process/process.ts index 54981c289..bfbf8053c 100644 --- a/server/lib/activitypub/process/process.ts +++ b/server/lib/activitypub/process/process.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import { Activity, ActivityType } from '../../../../shared/models/activitypub/activity' | 1 | import { Activity, ActivityType } from '../../../../shared/models/activitypub' |
2 | import { logger } from '../../../helpers/logger' | 2 | import { logger } from '../../../helpers' |
3 | import { AccountInstance } from '../../../models/account/account-interface' | 3 | import { AccountModel } from '../../../models/account/account' |
4 | import { processAcceptActivity } from './process-accept' | 4 | import { processAcceptActivity } from './process-accept' |
5 | import { processAddActivity } from './process-add' | 5 | import { processAddActivity } from './process-add' |
6 | import { processAnnounceActivity } from './process-announce' | 6 | import { processAnnounceActivity } from './process-announce' |
@@ -11,7 +11,7 @@ import { processLikeActivity } from './process-like' | |||
11 | import { processUndoActivity } from './process-undo' | 11 | import { processUndoActivity } from './process-undo' |
12 | import { processUpdateActivity } from './process-update' | 12 | import { processUpdateActivity } from './process-update' |
13 | 13 | ||
14 | const processActivity: { [ P in ActivityType ]: (activity: Activity, inboxAccount?: AccountInstance) => Promise<any> } = { | 14 | const processActivity: { [ P in ActivityType ]: (activity: Activity, inboxAccount?: AccountModel) => Promise<any> } = { |
15 | Create: processCreateActivity, | 15 | Create: processCreateActivity, |
16 | Add: processAddActivity, | 16 | Add: processAddActivity, |
17 | Update: processUpdateActivity, | 17 | Update: processUpdateActivity, |
@@ -23,7 +23,7 @@ const processActivity: { [ P in ActivityType ]: (activity: Activity, inboxAccoun | |||
23 | Like: processLikeActivity | 23 | Like: processLikeActivity |
24 | } | 24 | } |
25 | 25 | ||
26 | async function processActivities (activities: Activity[], signatureAccount?: AccountInstance, inboxAccount?: AccountInstance) { | 26 | async function processActivities (activities: Activity[], signatureAccount?: AccountModel, inboxAccount?: AccountModel) { |
27 | for (const activity of activities) { | 27 | for (const activity of activities) { |
28 | // When we fetch remote data, we don't have signature | 28 | // When we fetch remote data, we don't have signature |
29 | if (signatureAccount && activity.actor !== signatureAccount.url) { | 29 | if (signatureAccount && activity.actor !== signatureAccount.url) { |
diff --git a/server/lib/activitypub/send/misc.ts b/server/lib/activitypub/send/misc.ts index 999def701..ffc221477 100644 --- a/server/lib/activitypub/send/misc.ts +++ b/server/lib/activitypub/send/misc.ts | |||
@@ -1,19 +1,19 @@ | |||
1 | import { Transaction } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { Activity } from '../../../../shared/models/activitypub/activity' | 2 | import { Activity } from '../../../../shared/models/activitypub' |
3 | import { logger } from '../../../helpers/logger' | 3 | import { logger } from '../../../helpers' |
4 | import { ACTIVITY_PUB, database as db } from '../../../initializers' | 4 | import { ACTIVITY_PUB } from '../../../initializers' |
5 | import { AccountInstance } from '../../../models/account/account-interface' | 5 | import { AccountModel } from '../../../models/account/account' |
6 | import { VideoChannelInstance } from '../../../models/index' | 6 | import { AccountFollowModel } from '../../../models/account/account-follow' |
7 | import { VideoInstance } from '../../../models/video/video-interface' | 7 | import { VideoModel } from '../../../models/video/video' |
8 | import { | 8 | import { VideoChannelModel } from '../../../models/video/video-channel' |
9 | activitypubHttpJobScheduler, | 9 | import { VideoChannelShareModel } from '../../../models/video/video-channel-share' |
10 | ActivityPubHttpPayload | 10 | import { VideoShareModel } from '../../../models/video/video-share' |
11 | } from '../../jobs/activitypub-http-job-scheduler/activitypub-http-job-scheduler' | 11 | import { activitypubHttpJobScheduler, ActivityPubHttpPayload } from '../../jobs/activitypub-http-job-scheduler' |
12 | 12 | ||
13 | async function forwardActivity ( | 13 | async function forwardActivity ( |
14 | activity: Activity, | 14 | activity: Activity, |
15 | t: Transaction, | 15 | t: Transaction, |
16 | followersException: AccountInstance[] = [] | 16 | followersException: AccountModel[] = [] |
17 | ) { | 17 | ) { |
18 | const to = activity.to || [] | 18 | const to = activity.to || [] |
19 | const cc = activity.cc || [] | 19 | const cc = activity.cc || [] |
@@ -25,7 +25,7 @@ async function forwardActivity ( | |||
25 | } | 25 | } |
26 | } | 26 | } |
27 | 27 | ||
28 | const toAccountFollowers = await db.Account.listByFollowersUrls(followersUrls, t) | 28 | const toAccountFollowers = await AccountModel.listByFollowersUrls(followersUrls, t) |
29 | const uris = await computeFollowerUris(toAccountFollowers, followersException, t) | 29 | const uris = await computeFollowerUris(toAccountFollowers, followersException, t) |
30 | 30 | ||
31 | if (uris.length === 0) { | 31 | if (uris.length === 0) { |
@@ -45,10 +45,10 @@ async function forwardActivity ( | |||
45 | 45 | ||
46 | async function broadcastToFollowers ( | 46 | async function broadcastToFollowers ( |
47 | data: any, | 47 | data: any, |
48 | byAccount: AccountInstance, | 48 | byAccount: AccountModel, |
49 | toAccountFollowers: AccountInstance[], | 49 | toAccountFollowers: AccountModel[], |
50 | t: Transaction, | 50 | t: Transaction, |
51 | followersException: AccountInstance[] = [] | 51 | followersException: AccountModel[] = [] |
52 | ) { | 52 | ) { |
53 | const uris = await computeFollowerUris(toAccountFollowers, followersException, t) | 53 | const uris = await computeFollowerUris(toAccountFollowers, followersException, t) |
54 | if (uris.length === 0) { | 54 | if (uris.length === 0) { |
@@ -67,7 +67,7 @@ async function broadcastToFollowers ( | |||
67 | return activitypubHttpJobScheduler.createJob(t, 'activitypubHttpBroadcastHandler', jobPayload) | 67 | return activitypubHttpJobScheduler.createJob(t, 'activitypubHttpBroadcastHandler', jobPayload) |
68 | } | 68 | } |
69 | 69 | ||
70 | async function unicastTo (data: any, byAccount: AccountInstance, toAccountUrl: string, t: Transaction) { | 70 | async function unicastTo (data: any, byAccount: AccountModel, toAccountUrl: string, t: Transaction) { |
71 | logger.debug('Creating unicast job.', { uri: toAccountUrl }) | 71 | logger.debug('Creating unicast job.', { uri: toAccountUrl }) |
72 | 72 | ||
73 | const jobPayload: ActivityPubHttpPayload = { | 73 | const jobPayload: ActivityPubHttpPayload = { |
@@ -79,42 +79,42 @@ async function unicastTo (data: any, byAccount: AccountInstance, toAccountUrl: s | |||
79 | return activitypubHttpJobScheduler.createJob(t, 'activitypubHttpUnicastHandler', jobPayload) | 79 | return activitypubHttpJobScheduler.createJob(t, 'activitypubHttpUnicastHandler', jobPayload) |
80 | } | 80 | } |
81 | 81 | ||
82 | function getOriginVideoAudience (video: VideoInstance, accountsInvolvedInVideo: AccountInstance[]) { | 82 | function getOriginVideoAudience (video: VideoModel, accountsInvolvedInVideo: AccountModel[]) { |
83 | return { | 83 | return { |
84 | to: [ video.VideoChannel.Account.url ], | 84 | to: [ video.VideoChannel.Account.url ], |
85 | cc: accountsInvolvedInVideo.map(a => a.followersUrl) | 85 | cc: accountsInvolvedInVideo.map(a => a.followersUrl) |
86 | } | 86 | } |
87 | } | 87 | } |
88 | 88 | ||
89 | function getOriginVideoChannelAudience (videoChannel: VideoChannelInstance, accountsInvolved: AccountInstance[]) { | 89 | function getOriginVideoChannelAudience (videoChannel: VideoChannelModel, accountsInvolved: AccountModel[]) { |
90 | return { | 90 | return { |
91 | to: [ videoChannel.Account.url ], | 91 | to: [ videoChannel.Account.url ], |
92 | cc: accountsInvolved.map(a => a.followersUrl) | 92 | cc: accountsInvolved.map(a => a.followersUrl) |
93 | } | 93 | } |
94 | } | 94 | } |
95 | 95 | ||
96 | function getObjectFollowersAudience (accountsInvolvedInObject: AccountInstance[]) { | 96 | function getObjectFollowersAudience (accountsInvolvedInObject: AccountModel[]) { |
97 | return { | 97 | return { |
98 | to: accountsInvolvedInObject.map(a => a.followersUrl), | 98 | to: accountsInvolvedInObject.map(a => a.followersUrl), |
99 | cc: [] | 99 | cc: [] |
100 | } | 100 | } |
101 | } | 101 | } |
102 | 102 | ||
103 | async function getAccountsInvolvedInVideo (video: VideoInstance, t: Transaction) { | 103 | async function getAccountsInvolvedInVideo (video: VideoModel, t: Transaction) { |
104 | const accountsToForwardView = await db.VideoShare.loadAccountsByShare(video.id, t) | 104 | const accountsToForwardView = await VideoShareModel.loadAccountsByShare(video.id, t) |
105 | accountsToForwardView.push(video.VideoChannel.Account) | 105 | accountsToForwardView.push(video.VideoChannel.Account) |
106 | 106 | ||
107 | return accountsToForwardView | 107 | return accountsToForwardView |
108 | } | 108 | } |
109 | 109 | ||
110 | async function getAccountsInvolvedInVideoChannel (videoChannel: VideoChannelInstance, t: Transaction) { | 110 | async function getAccountsInvolvedInVideoChannel (videoChannel: VideoChannelModel, t: Transaction) { |
111 | const accountsToForwardView = await db.VideoChannelShare.loadAccountsByShare(videoChannel.id, t) | 111 | const accountsToForwardView = await VideoChannelShareModel.loadAccountsByShare(videoChannel.id, t) |
112 | accountsToForwardView.push(videoChannel.Account) | 112 | accountsToForwardView.push(videoChannel.Account) |
113 | 113 | ||
114 | return accountsToForwardView | 114 | return accountsToForwardView |
115 | } | 115 | } |
116 | 116 | ||
117 | async function getAudience (accountSender: AccountInstance, t: Transaction, isPublic = true) { | 117 | async function getAudience (accountSender: AccountModel, t: Transaction, isPublic = true) { |
118 | const followerInboxUrls = await accountSender.getFollowerSharedInboxUrls(t) | 118 | const followerInboxUrls = await accountSender.getFollowerSharedInboxUrls(t) |
119 | 119 | ||
120 | // Thanks Mastodon: https://github.com/tootsuite/mastodon/blob/master/app/lib/activitypub/tag_manager.rb#L47 | 120 | // Thanks Mastodon: https://github.com/tootsuite/mastodon/blob/master/app/lib/activitypub/tag_manager.rb#L47 |
@@ -132,14 +132,12 @@ async function getAudience (accountSender: AccountInstance, t: Transaction, isPu | |||
132 | return { to, cc } | 132 | return { to, cc } |
133 | } | 133 | } |
134 | 134 | ||
135 | async function computeFollowerUris (toAccountFollower: AccountInstance[], followersException: AccountInstance[], t: Transaction) { | 135 | async function computeFollowerUris (toAccountFollower: AccountModel[], followersException: AccountModel[], t: Transaction) { |
136 | const toAccountFollowerIds = toAccountFollower.map(a => a.id) | 136 | const toAccountFollowerIds = toAccountFollower.map(a => a.id) |
137 | 137 | ||
138 | const result = await db.AccountFollow.listAcceptedFollowerSharedInboxUrls(toAccountFollowerIds, t) | 138 | const result = await AccountFollowModel.listAcceptedFollowerSharedInboxUrls(toAccountFollowerIds, t) |
139 | const followersSharedInboxException = followersException.map(f => f.sharedInboxUrl) | 139 | const followersSharedInboxException = followersException.map(f => f.sharedInboxUrl) |
140 | const uris = result.data.filter(sharedInbox => followersSharedInboxException.indexOf(sharedInbox) === -1) | 140 | return result.data.filter(sharedInbox => followersSharedInboxException.indexOf(sharedInbox) === -1) |
141 | |||
142 | return uris | ||
143 | } | 141 | } |
144 | 142 | ||
145 | // --------------------------------------------------------------------------- | 143 | // --------------------------------------------------------------------------- |
diff --git a/server/lib/activitypub/send/send-accept.ts b/server/lib/activitypub/send/send-accept.ts index d3f8fbe38..f160af3c9 100644 --- a/server/lib/activitypub/send/send-accept.ts +++ b/server/lib/activitypub/send/send-accept.ts | |||
@@ -1,11 +1,11 @@ | |||
1 | import { Transaction } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { ActivityAccept } from '../../../../shared/models/activitypub/activity' | 2 | import { ActivityAccept } from '../../../../shared/models/activitypub' |
3 | import { AccountInstance } from '../../../models' | 3 | import { AccountModel } from '../../../models/account/account' |
4 | import { AccountFollowInstance } from '../../../models/account/account-follow-interface' | 4 | import { AccountFollowModel } from '../../../models/account/account-follow' |
5 | import { unicastTo } from './misc' | ||
6 | import { getAccountFollowAcceptActivityPubUrl } from '../url' | 5 | import { getAccountFollowAcceptActivityPubUrl } from '../url' |
6 | import { unicastTo } from './misc' | ||
7 | 7 | ||
8 | async function sendAccept (accountFollow: AccountFollowInstance, t: Transaction) { | 8 | async function sendAccept (accountFollow: AccountFollowModel, t: Transaction) { |
9 | const follower = accountFollow.AccountFollower | 9 | const follower = accountFollow.AccountFollower |
10 | const me = accountFollow.AccountFollowing | 10 | const me = accountFollow.AccountFollowing |
11 | 11 | ||
@@ -23,7 +23,7 @@ export { | |||
23 | 23 | ||
24 | // --------------------------------------------------------------------------- | 24 | // --------------------------------------------------------------------------- |
25 | 25 | ||
26 | function acceptActivityData (url: string, byAccount: AccountInstance) { | 26 | function acceptActivityData (url: string, byAccount: AccountModel) { |
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 d8ac2853e..fd614db75 100644 --- a/server/lib/activitypub/send/send-add.ts +++ b/server/lib/activitypub/send/send-add.ts | |||
@@ -1,10 +1,11 @@ | |||
1 | import { Transaction } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { ActivityAdd } from '../../../../shared/models/activitypub/activity' | 2 | import { ActivityAdd } from '../../../../shared/models/activitypub' |
3 | import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' | 3 | import { VideoPrivacy } from '../../../../shared/models/videos' |
4 | import { AccountInstance, VideoInstance } from '../../../models' | 4 | import { AccountModel } from '../../../models/account/account' |
5 | import { VideoModel } from '../../../models/video/video' | ||
5 | import { broadcastToFollowers, getAudience } from './misc' | 6 | import { broadcastToFollowers, getAudience } from './misc' |
6 | 7 | ||
7 | async function sendAddVideo (video: VideoInstance, t: Transaction) { | 8 | async function sendAddVideo (video: VideoModel, t: Transaction) { |
8 | const byAccount = video.VideoChannel.Account | 9 | const byAccount = video.VideoChannel.Account |
9 | 10 | ||
10 | const videoObject = video.toActivityPubObject() | 11 | const videoObject = video.toActivityPubObject() |
@@ -15,16 +16,17 @@ async function sendAddVideo (video: VideoInstance, t: Transaction) { | |||
15 | 16 | ||
16 | async function addActivityData ( | 17 | async function addActivityData ( |
17 | url: string, | 18 | url: string, |
18 | byAccount: AccountInstance, | 19 | byAccount: AccountModel, |
19 | video: VideoInstance, | 20 | video: VideoModel, |
20 | target: string, | 21 | target: string, |
21 | object: any, | 22 | object: any, |
22 | t: Transaction | 23 | t: Transaction |
23 | ) { | 24 | ): Promise<ActivityAdd> { |
24 | const videoPublic = video.privacy === VideoPrivacy.PUBLIC | 25 | const videoPublic = video.privacy === VideoPrivacy.PUBLIC |
25 | 26 | ||
26 | const { to, cc } = await getAudience(byAccount, t, videoPublic) | 27 | const { to, cc } = await getAudience(byAccount, t, videoPublic) |
27 | const activity: ActivityAdd = { | 28 | |
29 | return { | ||
28 | type: 'Add', | 30 | type: 'Add', |
29 | id: url, | 31 | id: url, |
30 | actor: byAccount.url, | 32 | actor: byAccount.url, |
@@ -33,8 +35,6 @@ async function addActivityData ( | |||
33 | object, | 35 | object, |
34 | target | 36 | target |
35 | } | 37 | } |
36 | |||
37 | return activity | ||
38 | } | 38 | } |
39 | 39 | ||
40 | // --------------------------------------------------------------------------- | 40 | // --------------------------------------------------------------------------- |
diff --git a/server/lib/activitypub/send/send-announce.ts b/server/lib/activitypub/send/send-announce.ts index 3acf604cd..e685323e8 100644 --- a/server/lib/activitypub/send/send-announce.ts +++ b/server/lib/activitypub/send/send-announce.ts | |||
@@ -1,8 +1,9 @@ | |||
1 | import { Transaction } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { ActivityAdd } from '../../../../shared/index' | 2 | import { ActivityAdd } from '../../../../shared/index' |
3 | import { ActivityAnnounce, ActivityAudience, ActivityCreate } from '../../../../shared/models/activitypub/activity' | 3 | import { ActivityAnnounce, ActivityAudience, ActivityCreate } from '../../../../shared/models/activitypub' |
4 | import { AccountInstance, VideoInstance } from '../../../models' | 4 | import { AccountModel } from '../../../models/account/account' |
5 | import { VideoChannelInstance } from '../../../models/video/video-channel-interface' | 5 | import { VideoModel } from '../../../models/video/video' |
6 | import { VideoChannelModel } from '../../../models/video/video-channel' | ||
6 | import { getAnnounceActivityPubUrl } from '../url' | 7 | import { getAnnounceActivityPubUrl } from '../url' |
7 | import { | 8 | import { |
8 | broadcastToFollowers, | 9 | broadcastToFollowers, |
@@ -17,7 +18,7 @@ import { | |||
17 | import { addActivityData } from './send-add' | 18 | import { addActivityData } from './send-add' |
18 | import { createActivityData } from './send-create' | 19 | import { createActivityData } from './send-create' |
19 | 20 | ||
20 | async function buildVideoAnnounceToFollowers (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { | 21 | async function buildVideoAnnounceToFollowers (byAccount: AccountModel, video: VideoModel, t: Transaction) { |
21 | const url = getAnnounceActivityPubUrl(video.url, byAccount) | 22 | const url = getAnnounceActivityPubUrl(video.url, byAccount) |
22 | 23 | ||
23 | const videoChannel = video.VideoChannel | 24 | const videoChannel = video.VideoChannel |
@@ -25,18 +26,16 @@ async function buildVideoAnnounceToFollowers (byAccount: AccountInstance, video: | |||
25 | 26 | ||
26 | const accountsToForwardView = await getAccountsInvolvedInVideo(video, t) | 27 | const accountsToForwardView = await getAccountsInvolvedInVideo(video, t) |
27 | const audience = getObjectFollowersAudience(accountsToForwardView) | 28 | const audience = getObjectFollowersAudience(accountsToForwardView) |
28 | const data = await announceActivityData(url, byAccount, announcedActivity, t, audience) | 29 | return announceActivityData(url, byAccount, announcedActivity, t, audience) |
29 | |||
30 | return data | ||
31 | } | 30 | } |
32 | 31 | ||
33 | async function sendVideoAnnounceToFollowers (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { | 32 | async function sendVideoAnnounceToFollowers (byAccount: AccountModel, video: VideoModel, t: Transaction) { |
34 | const data = await buildVideoAnnounceToFollowers(byAccount, video, t) | 33 | const data = await buildVideoAnnounceToFollowers(byAccount, video, t) |
35 | 34 | ||
36 | return broadcastToFollowers(data, byAccount, [ byAccount ], t) | 35 | return broadcastToFollowers(data, byAccount, [ byAccount ], t) |
37 | } | 36 | } |
38 | 37 | ||
39 | async function sendVideoAnnounceToOrigin (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { | 38 | async function sendVideoAnnounceToOrigin (byAccount: AccountModel, video: VideoModel, t: Transaction) { |
40 | const url = getAnnounceActivityPubUrl(video.url, byAccount) | 39 | const url = getAnnounceActivityPubUrl(video.url, byAccount) |
41 | 40 | ||
42 | const videoChannel = video.VideoChannel | 41 | const videoChannel = video.VideoChannel |
@@ -49,24 +48,22 @@ async function sendVideoAnnounceToOrigin (byAccount: AccountInstance, video: Vid | |||
49 | return unicastTo(data, byAccount, videoChannel.Account.sharedInboxUrl, t) | 48 | return unicastTo(data, byAccount, videoChannel.Account.sharedInboxUrl, t) |
50 | } | 49 | } |
51 | 50 | ||
52 | async function buildVideoChannelAnnounceToFollowers (byAccount: AccountInstance, videoChannel: VideoChannelInstance, t: Transaction) { | 51 | async function buildVideoChannelAnnounceToFollowers (byAccount: AccountModel, videoChannel: VideoChannelModel, t: Transaction) { |
53 | const url = getAnnounceActivityPubUrl(videoChannel.url, byAccount) | 52 | const url = getAnnounceActivityPubUrl(videoChannel.url, byAccount) |
54 | const announcedActivity = await createActivityData(url, videoChannel.Account, videoChannel.toActivityPubObject(), t) | 53 | const announcedActivity = await createActivityData(url, videoChannel.Account, videoChannel.toActivityPubObject(), t) |
55 | 54 | ||
56 | const accountsToForwardView = await getAccountsInvolvedInVideoChannel(videoChannel, t) | 55 | const accountsToForwardView = await getAccountsInvolvedInVideoChannel(videoChannel, t) |
57 | const audience = getObjectFollowersAudience(accountsToForwardView) | 56 | const audience = getObjectFollowersAudience(accountsToForwardView) |
58 | const data = await announceActivityData(url, byAccount, announcedActivity, t, audience) | 57 | return announceActivityData(url, byAccount, announcedActivity, t, audience) |
59 | |||
60 | return data | ||
61 | } | 58 | } |
62 | 59 | ||
63 | async function sendVideoChannelAnnounceToFollowers (byAccount: AccountInstance, videoChannel: VideoChannelInstance, t: Transaction) { | 60 | async function sendVideoChannelAnnounceToFollowers (byAccount: AccountModel, videoChannel: VideoChannelModel, t: Transaction) { |
64 | const data = await buildVideoChannelAnnounceToFollowers(byAccount, videoChannel, t) | 61 | const data = await buildVideoChannelAnnounceToFollowers(byAccount, videoChannel, t) |
65 | 62 | ||
66 | return broadcastToFollowers(data, byAccount, [ byAccount ], t) | 63 | return broadcastToFollowers(data, byAccount, [ byAccount ], t) |
67 | } | 64 | } |
68 | 65 | ||
69 | async function sendVideoChannelAnnounceToOrigin (byAccount: AccountInstance, videoChannel: VideoChannelInstance, t: Transaction) { | 66 | async function sendVideoChannelAnnounceToOrigin (byAccount: AccountModel, videoChannel: VideoChannelModel, t: Transaction) { |
70 | const url = getAnnounceActivityPubUrl(videoChannel.url, byAccount) | 67 | const url = getAnnounceActivityPubUrl(videoChannel.url, byAccount) |
71 | const announcedActivity = await createActivityData(url, videoChannel.Account, videoChannel.toActivityPubObject(), t) | 68 | const announcedActivity = await createActivityData(url, videoChannel.Account, videoChannel.toActivityPubObject(), t) |
72 | 69 | ||
@@ -79,16 +76,16 @@ async function sendVideoChannelAnnounceToOrigin (byAccount: AccountInstance, vid | |||
79 | 76 | ||
80 | async function announceActivityData ( | 77 | async function announceActivityData ( |
81 | url: string, | 78 | url: string, |
82 | byAccount: AccountInstance, | 79 | byAccount: AccountModel, |
83 | object: ActivityCreate | ActivityAdd, | 80 | object: ActivityCreate | ActivityAdd, |
84 | t: Transaction, | 81 | t: Transaction, |
85 | audience?: ActivityAudience | 82 | audience?: ActivityAudience |
86 | ) { | 83 | ): Promise<ActivityAnnounce> { |
87 | if (!audience) { | 84 | if (!audience) { |
88 | audience = await getAudience(byAccount, t) | 85 | audience = await getAudience(byAccount, t) |
89 | } | 86 | } |
90 | 87 | ||
91 | const activity: ActivityAnnounce = { | 88 | return { |
92 | type: 'Announce', | 89 | type: 'Announce', |
93 | to: audience.to, | 90 | to: audience.to, |
94 | cc: audience.cc, | 91 | cc: audience.cc, |
@@ -96,8 +93,6 @@ async function announceActivityData ( | |||
96 | actor: byAccount.url, | 93 | actor: byAccount.url, |
97 | object | 94 | object |
98 | } | 95 | } |
99 | |||
100 | return activity | ||
101 | } | 96 | } |
102 | 97 | ||
103 | // --------------------------------------------------------------------------- | 98 | // --------------------------------------------------------------------------- |
diff --git a/server/lib/activitypub/send/send-create.ts b/server/lib/activitypub/send/send-create.ts index a34d3776c..9fbaa8196 100644 --- a/server/lib/activitypub/send/send-create.ts +++ b/server/lib/activitypub/send/send-create.ts | |||
@@ -1,8 +1,10 @@ | |||
1 | import { Transaction } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { ActivityAudience, ActivityCreate } from '../../../../shared/models/activitypub/activity' | 2 | import { ActivityAudience, ActivityCreate } from '../../../../shared/models/activitypub' |
3 | import { getServerAccount } from '../../../helpers/utils' | 3 | import { getServerAccount } from '../../../helpers' |
4 | import { AccountInstance, VideoChannelInstance, VideoInstance } from '../../../models' | 4 | import { AccountModel } from '../../../models/account/account' |
5 | import { VideoAbuseInstance } from '../../../models/video/video-abuse-interface' | 5 | import { VideoModel } from '../../../models/video/video' |
6 | import { VideoAbuseModel } from '../../../models/video/video-abuse' | ||
7 | import { VideoChannelModel } from '../../../models/video/video-channel' | ||
6 | import { getVideoAbuseActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoViewActivityPubUrl } from '../url' | 8 | import { getVideoAbuseActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoViewActivityPubUrl } from '../url' |
7 | import { | 9 | import { |
8 | broadcastToFollowers, | 10 | broadcastToFollowers, |
@@ -13,7 +15,7 @@ import { | |||
13 | unicastTo | 15 | unicastTo |
14 | } from './misc' | 16 | } from './misc' |
15 | 17 | ||
16 | async function sendCreateVideoChannel (videoChannel: VideoChannelInstance, t: Transaction) { | 18 | async function sendCreateVideoChannel (videoChannel: VideoChannelModel, t: Transaction) { |
17 | const byAccount = videoChannel.Account | 19 | const byAccount = videoChannel.Account |
18 | 20 | ||
19 | const videoChannelObject = videoChannel.toActivityPubObject() | 21 | const videoChannelObject = videoChannel.toActivityPubObject() |
@@ -22,7 +24,7 @@ async function sendCreateVideoChannel (videoChannel: VideoChannelInstance, t: Tr | |||
22 | return broadcastToFollowers(data, byAccount, [ byAccount ], t) | 24 | return broadcastToFollowers(data, byAccount, [ byAccount ], t) |
23 | } | 25 | } |
24 | 26 | ||
25 | async function sendVideoAbuse (byAccount: AccountInstance, videoAbuse: VideoAbuseInstance, video: VideoInstance, t: Transaction) { | 27 | async function sendVideoAbuse (byAccount: AccountModel, videoAbuse: VideoAbuseModel, video: VideoModel, t: Transaction) { |
26 | const url = getVideoAbuseActivityPubUrl(videoAbuse) | 28 | const url = getVideoAbuseActivityPubUrl(videoAbuse) |
27 | 29 | ||
28 | const audience = { to: [ video.VideoChannel.Account.url ], cc: [] } | 30 | const audience = { to: [ video.VideoChannel.Account.url ], cc: [] } |
@@ -31,7 +33,7 @@ async function sendVideoAbuse (byAccount: AccountInstance, videoAbuse: VideoAbus | |||
31 | return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) | 33 | return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) |
32 | } | 34 | } |
33 | 35 | ||
34 | async function sendCreateViewToOrigin (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { | 36 | async function sendCreateViewToOrigin (byAccount: AccountModel, video: VideoModel, t: Transaction) { |
35 | const url = getVideoViewActivityPubUrl(byAccount, video) | 37 | const url = getVideoViewActivityPubUrl(byAccount, video) |
36 | const viewActivity = createViewActivityData(byAccount, video) | 38 | const viewActivity = createViewActivityData(byAccount, video) |
37 | 39 | ||
@@ -42,7 +44,7 @@ async function sendCreateViewToOrigin (byAccount: AccountInstance, video: VideoI | |||
42 | return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) | 44 | return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) |
43 | } | 45 | } |
44 | 46 | ||
45 | async function sendCreateViewToVideoFollowers (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { | 47 | async function sendCreateViewToVideoFollowers (byAccount: AccountModel, video: VideoModel, t: Transaction) { |
46 | const url = getVideoViewActivityPubUrl(byAccount, video) | 48 | const url = getVideoViewActivityPubUrl(byAccount, video) |
47 | const viewActivity = createViewActivityData(byAccount, video) | 49 | const viewActivity = createViewActivityData(byAccount, video) |
48 | 50 | ||
@@ -56,7 +58,7 @@ async function sendCreateViewToVideoFollowers (byAccount: AccountInstance, video | |||
56 | return broadcastToFollowers(data, serverAccount, accountsToForwardView, t, followersException) | 58 | return broadcastToFollowers(data, serverAccount, accountsToForwardView, t, followersException) |
57 | } | 59 | } |
58 | 60 | ||
59 | async function sendCreateDislikeToOrigin (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { | 61 | async function sendCreateDislikeToOrigin (byAccount: AccountModel, video: VideoModel, t: Transaction) { |
60 | const url = getVideoDislikeActivityPubUrl(byAccount, video) | 62 | const url = getVideoDislikeActivityPubUrl(byAccount, video) |
61 | const dislikeActivity = createDislikeActivityData(byAccount, video) | 63 | const dislikeActivity = createDislikeActivityData(byAccount, video) |
62 | 64 | ||
@@ -67,7 +69,7 @@ async function sendCreateDislikeToOrigin (byAccount: AccountInstance, video: Vid | |||
67 | return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) | 69 | return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) |
68 | } | 70 | } |
69 | 71 | ||
70 | async function sendCreateDislikeToVideoFollowers (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { | 72 | async function sendCreateDislikeToVideoFollowers (byAccount: AccountModel, video: VideoModel, t: Transaction) { |
71 | const url = getVideoDislikeActivityPubUrl(byAccount, video) | 73 | const url = getVideoDislikeActivityPubUrl(byAccount, video) |
72 | const dislikeActivity = createDislikeActivityData(byAccount, video) | 74 | const dislikeActivity = createDislikeActivityData(byAccount, video) |
73 | 75 | ||
@@ -79,12 +81,18 @@ async function sendCreateDislikeToVideoFollowers (byAccount: AccountInstance, vi | |||
79 | return broadcastToFollowers(data, byAccount, accountsToForwardView, t, followersException) | 81 | return broadcastToFollowers(data, byAccount, accountsToForwardView, t, followersException) |
80 | } | 82 | } |
81 | 83 | ||
82 | async function createActivityData (url: string, byAccount: AccountInstance, object: any, t: Transaction, audience?: ActivityAudience) { | 84 | async function createActivityData ( |
85 | url: string, | ||
86 | byAccount: AccountModel, | ||
87 | object: any, | ||
88 | t: Transaction, | ||
89 | audience?: ActivityAudience | ||
90 | ): Promise<ActivityCreate> { | ||
83 | if (!audience) { | 91 | if (!audience) { |
84 | audience = await getAudience(byAccount, t) | 92 | audience = await getAudience(byAccount, t) |
85 | } | 93 | } |
86 | 94 | ||
87 | const activity: ActivityCreate = { | 95 | return { |
88 | type: 'Create', | 96 | type: 'Create', |
89 | id: url, | 97 | id: url, |
90 | actor: byAccount.url, | 98 | actor: byAccount.url, |
@@ -92,18 +100,14 @@ async function createActivityData (url: string, byAccount: AccountInstance, obje | |||
92 | cc: audience.cc, | 100 | cc: audience.cc, |
93 | object | 101 | object |
94 | } | 102 | } |
95 | |||
96 | return activity | ||
97 | } | 103 | } |
98 | 104 | ||
99 | function createDislikeActivityData (byAccount: AccountInstance, video: VideoInstance) { | 105 | function createDislikeActivityData (byAccount: AccountModel, video: VideoModel) { |
100 | const obj = { | 106 | return { |
101 | type: 'Dislike', | 107 | type: 'Dislike', |
102 | actor: byAccount.url, | 108 | actor: byAccount.url, |
103 | object: video.url | 109 | object: video.url |
104 | } | 110 | } |
105 | |||
106 | return obj | ||
107 | } | 111 | } |
108 | 112 | ||
109 | // --------------------------------------------------------------------------- | 113 | // --------------------------------------------------------------------------- |
@@ -121,12 +125,10 @@ export { | |||
121 | 125 | ||
122 | // --------------------------------------------------------------------------- | 126 | // --------------------------------------------------------------------------- |
123 | 127 | ||
124 | function createViewActivityData (byAccount: AccountInstance, video: VideoInstance) { | 128 | function createViewActivityData (byAccount: AccountModel, video: VideoModel) { |
125 | const obj = { | 129 | return { |
126 | type: 'View', | 130 | type: 'View', |
127 | actor: byAccount.url, | 131 | actor: byAccount.url, |
128 | object: video.url | 132 | object: video.url |
129 | } | 133 | } |
130 | |||
131 | return obj | ||
132 | } | 134 | } |
diff --git a/server/lib/activitypub/send/send-delete.ts b/server/lib/activitypub/send/send-delete.ts index 8193790b3..0a45ea10f 100644 --- a/server/lib/activitypub/send/send-delete.ts +++ b/server/lib/activitypub/send/send-delete.ts | |||
@@ -1,32 +1,35 @@ | |||
1 | import { Transaction } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { ActivityDelete } from '../../../../shared/models/activitypub/activity' | 2 | import { ActivityDelete } from '../../../../shared/models/activitypub' |
3 | import { database as db } from '../../../initializers' | 3 | import { AccountModel } from '../../../models/account/account' |
4 | import { AccountInstance, VideoChannelInstance, VideoInstance } from '../../../models' | 4 | import { VideoModel } from '../../../models/video/video' |
5 | import { VideoChannelModel } from '../../../models/video/video-channel' | ||
6 | import { VideoChannelShareModel } from '../../../models/video/video-channel-share' | ||
7 | import { VideoShareModel } from '../../../models/video/video-share' | ||
5 | import { broadcastToFollowers } from './misc' | 8 | import { broadcastToFollowers } from './misc' |
6 | 9 | ||
7 | async function sendDeleteVideoChannel (videoChannel: VideoChannelInstance, t: Transaction) { | 10 | async function sendDeleteVideoChannel (videoChannel: VideoChannelModel, t: Transaction) { |
8 | const byAccount = videoChannel.Account | 11 | const byAccount = videoChannel.Account |
9 | 12 | ||
10 | const data = deleteActivityData(videoChannel.url, byAccount) | 13 | const data = deleteActivityData(videoChannel.url, byAccount) |
11 | 14 | ||
12 | const accountsInvolved = await db.VideoChannelShare.loadAccountsByShare(videoChannel.id, t) | 15 | const accountsInvolved = await VideoChannelShareModel.loadAccountsByShare(videoChannel.id, t) |
13 | accountsInvolved.push(byAccount) | 16 | accountsInvolved.push(byAccount) |
14 | 17 | ||
15 | return broadcastToFollowers(data, byAccount, accountsInvolved, t) | 18 | return broadcastToFollowers(data, byAccount, accountsInvolved, t) |
16 | } | 19 | } |
17 | 20 | ||
18 | async function sendDeleteVideo (video: VideoInstance, t: Transaction) { | 21 | async function sendDeleteVideo (video: VideoModel, t: Transaction) { |
19 | const byAccount = video.VideoChannel.Account | 22 | const byAccount = video.VideoChannel.Account |
20 | 23 | ||
21 | const data = deleteActivityData(video.url, byAccount) | 24 | const data = deleteActivityData(video.url, byAccount) |
22 | 25 | ||
23 | const accountsInvolved = await db.VideoShare.loadAccountsByShare(video.id, t) | 26 | const accountsInvolved = await VideoShareModel.loadAccountsByShare(video.id, t) |
24 | accountsInvolved.push(byAccount) | 27 | accountsInvolved.push(byAccount) |
25 | 28 | ||
26 | return broadcastToFollowers(data, byAccount, accountsInvolved, t) | 29 | return broadcastToFollowers(data, byAccount, accountsInvolved, t) |
27 | } | 30 | } |
28 | 31 | ||
29 | async function sendDeleteAccount (account: AccountInstance, t: Transaction) { | 32 | async function sendDeleteAccount (account: AccountModel, t: Transaction) { |
30 | const data = deleteActivityData(account.url, account) | 33 | const data = deleteActivityData(account.url, account) |
31 | 34 | ||
32 | return broadcastToFollowers(data, account, [ account ], t) | 35 | return broadcastToFollowers(data, account, [ account ], t) |
@@ -42,12 +45,10 @@ export { | |||
42 | 45 | ||
43 | // --------------------------------------------------------------------------- | 46 | // --------------------------------------------------------------------------- |
44 | 47 | ||
45 | function deleteActivityData (url: string, byAccount: AccountInstance) { | 48 | function deleteActivityData (url: string, byAccount: AccountModel): ActivityDelete { |
46 | const activity: ActivityDelete = { | 49 | return { |
47 | type: 'Delete', | 50 | type: 'Delete', |
48 | id: url, | 51 | id: url, |
49 | actor: byAccount.url | 52 | actor: byAccount.url |
50 | } | 53 | } |
51 | |||
52 | return activity | ||
53 | } | 54 | } |
diff --git a/server/lib/activitypub/send/send-follow.ts b/server/lib/activitypub/send/send-follow.ts index 8fba1b6b5..51735ddfd 100644 --- a/server/lib/activitypub/send/send-follow.ts +++ b/server/lib/activitypub/send/send-follow.ts | |||
@@ -1,11 +1,11 @@ | |||
1 | import { Transaction } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { ActivityFollow } from '../../../../shared/models/activitypub/activity' | 2 | import { ActivityFollow } from '../../../../shared/models/activitypub' |
3 | import { AccountInstance } from '../../../models' | 3 | import { AccountModel } from '../../../models/account/account' |
4 | import { AccountFollowInstance } from '../../../models/account/account-follow-interface' | 4 | import { AccountFollowModel } from '../../../models/account/account-follow' |
5 | import { getAccountFollowActivityPubUrl } from '../url' | 5 | import { getAccountFollowActivityPubUrl } from '../url' |
6 | import { unicastTo } from './misc' | 6 | import { unicastTo } from './misc' |
7 | 7 | ||
8 | function sendFollow (accountFollow: AccountFollowInstance, t: Transaction) { | 8 | function sendFollow (accountFollow: AccountFollowModel, t: Transaction) { |
9 | const me = accountFollow.AccountFollower | 9 | const me = accountFollow.AccountFollower |
10 | const following = accountFollow.AccountFollowing | 10 | const following = accountFollow.AccountFollowing |
11 | 11 | ||
@@ -15,15 +15,13 @@ function sendFollow (accountFollow: AccountFollowInstance, t: Transaction) { | |||
15 | return unicastTo(data, me, following.inboxUrl, t) | 15 | return unicastTo(data, me, following.inboxUrl, t) |
16 | } | 16 | } |
17 | 17 | ||
18 | function followActivityData (url: string, byAccount: AccountInstance, targetAccount: AccountInstance) { | 18 | function followActivityData (url: string, byAccount: AccountModel, targetAccount: AccountModel): ActivityFollow { |
19 | const activity: ActivityFollow = { | 19 | return { |
20 | type: 'Follow', | 20 | type: 'Follow', |
21 | id: url, | 21 | id: url, |
22 | actor: byAccount.url, | 22 | actor: byAccount.url, |
23 | object: targetAccount.url | 23 | object: targetAccount.url |
24 | } | 24 | } |
25 | |||
26 | return activity | ||
27 | } | 25 | } |
28 | 26 | ||
29 | // --------------------------------------------------------------------------- | 27 | // --------------------------------------------------------------------------- |
diff --git a/server/lib/activitypub/send/send-like.ts b/server/lib/activitypub/send/send-like.ts index 0c464b2d3..1a35d0db0 100644 --- a/server/lib/activitypub/send/send-like.ts +++ b/server/lib/activitypub/send/send-like.ts | |||
@@ -1,6 +1,7 @@ | |||
1 | import { Transaction } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { ActivityAudience, ActivityLike } from '../../../../shared/models/activitypub/activity' | 2 | import { ActivityAudience, ActivityLike } from '../../../../shared/models/activitypub' |
3 | import { AccountInstance, VideoInstance } from '../../../models' | 3 | import { AccountModel } from '../../../models/account/account' |
4 | import { VideoModel } from '../../../models/video/video' | ||
4 | import { getVideoLikeActivityPubUrl } from '../url' | 5 | import { getVideoLikeActivityPubUrl } from '../url' |
5 | import { | 6 | import { |
6 | broadcastToFollowers, | 7 | broadcastToFollowers, |
@@ -11,7 +12,7 @@ import { | |||
11 | unicastTo | 12 | unicastTo |
12 | } from './misc' | 13 | } from './misc' |
13 | 14 | ||
14 | async function sendLikeToOrigin (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { | 15 | async function sendLikeToOrigin (byAccount: AccountModel, video: VideoModel, t: Transaction) { |
15 | const url = getVideoLikeActivityPubUrl(byAccount, video) | 16 | const url = getVideoLikeActivityPubUrl(byAccount, video) |
16 | 17 | ||
17 | const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t) | 18 | const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t) |
@@ -21,7 +22,7 @@ async function sendLikeToOrigin (byAccount: AccountInstance, video: VideoInstanc | |||
21 | return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) | 22 | return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) |
22 | } | 23 | } |
23 | 24 | ||
24 | async function sendLikeToVideoFollowers (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { | 25 | async function sendLikeToVideoFollowers (byAccount: AccountModel, video: VideoModel, t: Transaction) { |
25 | const url = getVideoLikeActivityPubUrl(byAccount, video) | 26 | const url = getVideoLikeActivityPubUrl(byAccount, video) |
26 | 27 | ||
27 | const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t) | 28 | const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t) |
@@ -34,16 +35,16 @@ async function sendLikeToVideoFollowers (byAccount: AccountInstance, video: Vide | |||
34 | 35 | ||
35 | async function likeActivityData ( | 36 | async function likeActivityData ( |
36 | url: string, | 37 | url: string, |
37 | byAccount: AccountInstance, | 38 | byAccount: AccountModel, |
38 | video: VideoInstance, | 39 | video: VideoModel, |
39 | t: Transaction, | 40 | t: Transaction, |
40 | audience?: ActivityAudience | 41 | audience?: ActivityAudience |
41 | ) { | 42 | ): Promise<ActivityLike> { |
42 | if (!audience) { | 43 | if (!audience) { |
43 | audience = await getAudience(byAccount, t) | 44 | audience = await getAudience(byAccount, t) |
44 | } | 45 | } |
45 | 46 | ||
46 | const activity: ActivityLike = { | 47 | return { |
47 | type: 'Like', | 48 | type: 'Like', |
48 | id: url, | 49 | id: url, |
49 | actor: byAccount.url, | 50 | actor: byAccount.url, |
@@ -51,8 +52,6 @@ async function likeActivityData ( | |||
51 | cc: audience.cc, | 52 | cc: audience.cc, |
52 | object: video.url | 53 | object: video.url |
53 | } | 54 | } |
54 | |||
55 | return activity | ||
56 | } | 55 | } |
57 | 56 | ||
58 | // --------------------------------------------------------------------------- | 57 | // --------------------------------------------------------------------------- |
diff --git a/server/lib/activitypub/send/send-undo.ts b/server/lib/activitypub/send/send-undo.ts index 015f02b35..699f920f0 100644 --- a/server/lib/activitypub/send/send-undo.ts +++ b/server/lib/activitypub/send/send-undo.ts | |||
@@ -5,10 +5,10 @@ import { | |||
5 | ActivityFollow, | 5 | ActivityFollow, |
6 | ActivityLike, | 6 | ActivityLike, |
7 | ActivityUndo | 7 | ActivityUndo |
8 | } from '../../../../shared/models/activitypub/activity' | 8 | } from '../../../../shared/models/activitypub' |
9 | import { AccountInstance } from '../../../models' | 9 | import { AccountModel } from '../../../models/account/account' |
10 | import { AccountFollowInstance } from '../../../models/account/account-follow-interface' | 10 | import { AccountFollowModel } from '../../../models/account/account-follow' |
11 | import { VideoInstance } from '../../../models/video/video-interface' | 11 | import { VideoModel } from '../../../models/video/video' |
12 | import { getAccountFollowActivityPubUrl, getUndoActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from '../url' | 12 | import { getAccountFollowActivityPubUrl, getUndoActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from '../url' |
13 | import { | 13 | import { |
14 | broadcastToFollowers, | 14 | broadcastToFollowers, |
@@ -22,7 +22,7 @@ import { createActivityData, createDislikeActivityData } from './send-create' | |||
22 | import { followActivityData } from './send-follow' | 22 | import { followActivityData } from './send-follow' |
23 | import { likeActivityData } from './send-like' | 23 | import { likeActivityData } from './send-like' |
24 | 24 | ||
25 | async function sendUndoFollow (accountFollow: AccountFollowInstance, t: Transaction) { | 25 | async function sendUndoFollow (accountFollow: AccountFollowModel, t: Transaction) { |
26 | const me = accountFollow.AccountFollower | 26 | const me = accountFollow.AccountFollower |
27 | const following = accountFollow.AccountFollowing | 27 | const following = accountFollow.AccountFollowing |
28 | 28 | ||
@@ -35,7 +35,7 @@ async function sendUndoFollow (accountFollow: AccountFollowInstance, t: Transact | |||
35 | return unicastTo(data, me, following.inboxUrl, t) | 35 | return unicastTo(data, me, following.inboxUrl, t) |
36 | } | 36 | } |
37 | 37 | ||
38 | async function sendUndoLikeToOrigin (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { | 38 | async function sendUndoLikeToOrigin (byAccount: AccountModel, video: VideoModel, t: Transaction) { |
39 | const likeUrl = getVideoLikeActivityPubUrl(byAccount, video) | 39 | const likeUrl = getVideoLikeActivityPubUrl(byAccount, video) |
40 | const undoUrl = getUndoActivityPubUrl(likeUrl) | 40 | const undoUrl = getUndoActivityPubUrl(likeUrl) |
41 | 41 | ||
@@ -47,7 +47,7 @@ async function sendUndoLikeToOrigin (byAccount: AccountInstance, video: VideoIns | |||
47 | return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) | 47 | return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) |
48 | } | 48 | } |
49 | 49 | ||
50 | async function sendUndoLikeToVideoFollowers (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { | 50 | async function sendUndoLikeToVideoFollowers (byAccount: AccountModel, video: VideoModel, t: Transaction) { |
51 | const likeUrl = getVideoLikeActivityPubUrl(byAccount, video) | 51 | const likeUrl = getVideoLikeActivityPubUrl(byAccount, video) |
52 | const undoUrl = getUndoActivityPubUrl(likeUrl) | 52 | const undoUrl = getUndoActivityPubUrl(likeUrl) |
53 | 53 | ||
@@ -60,7 +60,7 @@ async function sendUndoLikeToVideoFollowers (byAccount: AccountInstance, video: | |||
60 | return broadcastToFollowers(data, byAccount, toAccountsFollowers, t, followersException) | 60 | return broadcastToFollowers(data, byAccount, toAccountsFollowers, t, followersException) |
61 | } | 61 | } |
62 | 62 | ||
63 | async function sendUndoDislikeToOrigin (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { | 63 | async function sendUndoDislikeToOrigin (byAccount: AccountModel, video: VideoModel, t: Transaction) { |
64 | const dislikeUrl = getVideoDislikeActivityPubUrl(byAccount, video) | 64 | const dislikeUrl = getVideoDislikeActivityPubUrl(byAccount, video) |
65 | const undoUrl = getUndoActivityPubUrl(dislikeUrl) | 65 | const undoUrl = getUndoActivityPubUrl(dislikeUrl) |
66 | 66 | ||
@@ -74,7 +74,7 @@ async function sendUndoDislikeToOrigin (byAccount: AccountInstance, video: Video | |||
74 | return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) | 74 | return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) |
75 | } | 75 | } |
76 | 76 | ||
77 | async function sendUndoDislikeToVideoFollowers (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { | 77 | async function sendUndoDislikeToVideoFollowers (byAccount: AccountModel, video: VideoModel, t: Transaction) { |
78 | const dislikeUrl = getVideoDislikeActivityPubUrl(byAccount, video) | 78 | const dislikeUrl = getVideoDislikeActivityPubUrl(byAccount, video) |
79 | const undoUrl = getUndoActivityPubUrl(dislikeUrl) | 79 | const undoUrl = getUndoActivityPubUrl(dislikeUrl) |
80 | 80 | ||
@@ -103,16 +103,16 @@ export { | |||
103 | 103 | ||
104 | async function undoActivityData ( | 104 | async function undoActivityData ( |
105 | url: string, | 105 | url: string, |
106 | byAccount: AccountInstance, | 106 | byAccount: AccountModel, |
107 | object: ActivityFollow | ActivityLike | ActivityCreate, | 107 | object: ActivityFollow | ActivityLike | ActivityCreate, |
108 | t: Transaction, | 108 | t: Transaction, |
109 | audience?: ActivityAudience | 109 | audience?: ActivityAudience |
110 | ) { | 110 | ): Promise<ActivityUndo> { |
111 | if (!audience) { | 111 | if (!audience) { |
112 | audience = await getAudience(byAccount, t) | 112 | audience = await getAudience(byAccount, t) |
113 | } | 113 | } |
114 | 114 | ||
115 | const activity: ActivityUndo = { | 115 | return { |
116 | type: 'Undo', | 116 | type: 'Undo', |
117 | id: url, | 117 | id: url, |
118 | actor: byAccount.url, | 118 | actor: byAccount.url, |
@@ -120,6 +120,4 @@ async function undoActivityData ( | |||
120 | cc: audience.cc, | 120 | cc: audience.cc, |
121 | object | 121 | object |
122 | } | 122 | } |
123 | |||
124 | return activity | ||
125 | } | 123 | } |
diff --git a/server/lib/activitypub/send/send-update.ts b/server/lib/activitypub/send/send-update.ts index 59524e523..9baf13a87 100644 --- a/server/lib/activitypub/send/send-update.ts +++ b/server/lib/activitypub/send/send-update.ts | |||
@@ -1,31 +1,34 @@ | |||
1 | import { Transaction } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { ActivityUpdate } from '../../../../shared/models/activitypub/activity' | 2 | import { ActivityUpdate } from '../../../../shared/models/activitypub' |
3 | import { database as db } from '../../../initializers' | 3 | import { AccountModel } from '../../../models/account/account' |
4 | import { AccountInstance, VideoChannelInstance, VideoInstance } from '../../../models' | 4 | import { VideoModel } from '../../../models/video/video' |
5 | import { VideoChannelModel } from '../../../models/video/video-channel' | ||
6 | import { VideoChannelShareModel } from '../../../models/video/video-channel-share' | ||
7 | import { VideoShareModel } from '../../../models/video/video-share' | ||
5 | import { getUpdateActivityPubUrl } from '../url' | 8 | import { getUpdateActivityPubUrl } from '../url' |
6 | import { broadcastToFollowers, getAudience } from './misc' | 9 | import { broadcastToFollowers, getAudience } from './misc' |
7 | 10 | ||
8 | async function sendUpdateVideoChannel (videoChannel: VideoChannelInstance, t: Transaction) { | 11 | async function sendUpdateVideoChannel (videoChannel: VideoChannelModel, t: Transaction) { |
9 | const byAccount = videoChannel.Account | 12 | const byAccount = videoChannel.Account |
10 | 13 | ||
11 | const url = getUpdateActivityPubUrl(videoChannel.url, videoChannel.updatedAt.toISOString()) | 14 | const url = getUpdateActivityPubUrl(videoChannel.url, videoChannel.updatedAt.toISOString()) |
12 | const videoChannelObject = videoChannel.toActivityPubObject() | 15 | const videoChannelObject = videoChannel.toActivityPubObject() |
13 | const data = await updateActivityData(url, byAccount, videoChannelObject, t) | 16 | const data = await updateActivityData(url, byAccount, videoChannelObject, t) |
14 | 17 | ||
15 | const accountsInvolved = await db.VideoChannelShare.loadAccountsByShare(videoChannel.id, t) | 18 | const accountsInvolved = await VideoChannelShareModel.loadAccountsByShare(videoChannel.id, t) |
16 | accountsInvolved.push(byAccount) | 19 | accountsInvolved.push(byAccount) |
17 | 20 | ||
18 | return broadcastToFollowers(data, byAccount, accountsInvolved, t) | 21 | return broadcastToFollowers(data, byAccount, accountsInvolved, t) |
19 | } | 22 | } |
20 | 23 | ||
21 | async function sendUpdateVideo (video: VideoInstance, t: Transaction) { | 24 | async function sendUpdateVideo (video: VideoModel, t: Transaction) { |
22 | const byAccount = video.VideoChannel.Account | 25 | const byAccount = video.VideoChannel.Account |
23 | 26 | ||
24 | const url = getUpdateActivityPubUrl(video.url, video.updatedAt.toISOString()) | 27 | const url = getUpdateActivityPubUrl(video.url, video.updatedAt.toISOString()) |
25 | const videoObject = video.toActivityPubObject() | 28 | const videoObject = video.toActivityPubObject() |
26 | const data = await updateActivityData(url, byAccount, videoObject, t) | 29 | const data = await updateActivityData(url, byAccount, videoObject, t) |
27 | 30 | ||
28 | const accountsInvolved = await db.VideoShare.loadAccountsByShare(video.id, t) | 31 | const accountsInvolved = await VideoShareModel.loadAccountsByShare(video.id, t) |
29 | accountsInvolved.push(byAccount) | 32 | accountsInvolved.push(byAccount) |
30 | 33 | ||
31 | return broadcastToFollowers(data, byAccount, accountsInvolved, t) | 34 | return broadcastToFollowers(data, byAccount, accountsInvolved, t) |
@@ -40,9 +43,9 @@ export { | |||
40 | 43 | ||
41 | // --------------------------------------------------------------------------- | 44 | // --------------------------------------------------------------------------- |
42 | 45 | ||
43 | async function updateActivityData (url: string, byAccount: AccountInstance, object: any, t: Transaction) { | 46 | async function updateActivityData (url: string, byAccount: AccountModel, object: any, t: Transaction): Promise<ActivityUpdate> { |
44 | const { to, cc } = await getAudience(byAccount, t) | 47 | const { to, cc } = await getAudience(byAccount, t) |
45 | const activity: ActivityUpdate = { | 48 | return { |
46 | type: 'Update', | 49 | type: 'Update', |
47 | id: url, | 50 | id: url, |
48 | actor: byAccount.url, | 51 | actor: byAccount.url, |
@@ -50,6 +53,4 @@ async function updateActivityData (url: string, byAccount: AccountInstance, obje | |||
50 | cc, | 53 | cc, |
51 | object | 54 | object |
52 | } | 55 | } |
53 | |||
54 | return activity | ||
55 | } | 56 | } |
diff --git a/server/lib/activitypub/share.ts b/server/lib/activitypub/share.ts index e14b0f50c..5bec61c05 100644 --- a/server/lib/activitypub/share.ts +++ b/server/lib/activitypub/share.ts | |||
@@ -1,14 +1,15 @@ | |||
1 | import { Transaction } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { getServerAccount } from '../../helpers/utils' | 2 | import { getServerAccount } from '../../helpers' |
3 | import { database as db } from '../../initializers' | 3 | import { VideoModel } from '../../models/video/video' |
4 | import { VideoChannelInstance } from '../../models/index' | 4 | import { VideoChannelModel } from '../../models/video/video-channel' |
5 | import { VideoInstance } from '../../models/video/video-interface' | 5 | import { VideoChannelShareModel } from '../../models/video/video-channel-share' |
6 | import { sendVideoAnnounceToFollowers, sendVideoChannelAnnounceToFollowers } from './send/send-announce' | 6 | import { VideoShareModel } from '../../models/video/video-share' |
7 | import { sendVideoAnnounceToFollowers, sendVideoChannelAnnounceToFollowers } from './send' | ||
7 | 8 | ||
8 | async function shareVideoChannelByServer (videoChannel: VideoChannelInstance, t: Transaction) { | 9 | async function shareVideoChannelByServer (videoChannel: VideoChannelModel, t: Transaction) { |
9 | const serverAccount = await getServerAccount() | 10 | const serverAccount = await getServerAccount() |
10 | 11 | ||
11 | await db.VideoChannelShare.create({ | 12 | await VideoChannelShareModel.create({ |
12 | accountId: serverAccount.id, | 13 | accountId: serverAccount.id, |
13 | videoChannelId: videoChannel.id | 14 | videoChannelId: videoChannel.id |
14 | }, { transaction: t }) | 15 | }, { transaction: t }) |
@@ -16,10 +17,10 @@ async function shareVideoChannelByServer (videoChannel: VideoChannelInstance, t: | |||
16 | return sendVideoChannelAnnounceToFollowers(serverAccount, videoChannel, t) | 17 | return sendVideoChannelAnnounceToFollowers(serverAccount, videoChannel, t) |
17 | } | 18 | } |
18 | 19 | ||
19 | async function shareVideoByServer (video: VideoInstance, t: Transaction) { | 20 | async function shareVideoByServer (video: VideoModel, t: Transaction) { |
20 | const serverAccount = await getServerAccount() | 21 | const serverAccount = await getServerAccount() |
21 | 22 | ||
22 | await db.VideoShare.create({ | 23 | await VideoShareModel.create({ |
23 | accountId: serverAccount.id, | 24 | accountId: serverAccount.id, |
24 | videoId: video.id | 25 | videoId: video.id |
25 | }, { transaction: t }) | 26 | }, { transaction: t }) |
diff --git a/server/lib/activitypub/url.ts b/server/lib/activitypub/url.ts index 6475c4218..00b4e8852 100644 --- a/server/lib/activitypub/url.ts +++ b/server/lib/activitypub/url.ts | |||
@@ -1,15 +1,15 @@ | |||
1 | import { CONFIG } from '../../initializers/constants' | 1 | import { CONFIG } from '../../initializers' |
2 | import { VideoInstance } from '../../models/video/video-interface' | 2 | import { AccountModel } from '../../models/account/account' |
3 | import { VideoChannelInstance } from '../../models/video/video-channel-interface' | 3 | import { AccountFollowModel } from '../../models/account/account-follow' |
4 | import { VideoAbuseInstance } from '../../models/video/video-abuse-interface' | 4 | import { VideoModel } from '../../models/video/video' |
5 | import { AccountFollowInstance } from '../../models/account/account-follow-interface' | 5 | import { VideoAbuseModel } from '../../models/video/video-abuse' |
6 | import { AccountInstance } from '../../models/account/account-interface' | 6 | import { VideoChannelModel } from '../../models/video/video-channel' |
7 | 7 | ||
8 | function getVideoActivityPubUrl (video: VideoInstance) { | 8 | function getVideoActivityPubUrl (video: VideoModel) { |
9 | return CONFIG.WEBSERVER.URL + '/videos/watch/' + video.uuid | 9 | return CONFIG.WEBSERVER.URL + '/videos/watch/' + video.uuid |
10 | } | 10 | } |
11 | 11 | ||
12 | function getVideoChannelActivityPubUrl (videoChannel: VideoChannelInstance) { | 12 | function getVideoChannelActivityPubUrl (videoChannel: VideoChannelModel) { |
13 | return CONFIG.WEBSERVER.URL + '/video-channels/' + videoChannel.uuid | 13 | return CONFIG.WEBSERVER.URL + '/video-channels/' + videoChannel.uuid |
14 | } | 14 | } |
15 | 15 | ||
@@ -17,37 +17,37 @@ function getAccountActivityPubUrl (accountName: string) { | |||
17 | return CONFIG.WEBSERVER.URL + '/account/' + accountName | 17 | return CONFIG.WEBSERVER.URL + '/account/' + accountName |
18 | } | 18 | } |
19 | 19 | ||
20 | function getVideoAbuseActivityPubUrl (videoAbuse: VideoAbuseInstance) { | 20 | function getVideoAbuseActivityPubUrl (videoAbuse: VideoAbuseModel) { |
21 | return CONFIG.WEBSERVER.URL + '/admin/video-abuses/' + videoAbuse.id | 21 | return CONFIG.WEBSERVER.URL + '/admin/video-abuses/' + videoAbuse.id |
22 | } | 22 | } |
23 | 23 | ||
24 | function getVideoViewActivityPubUrl (byAccount: AccountInstance, video: VideoInstance) { | 24 | function getVideoViewActivityPubUrl (byAccount: AccountModel, video: VideoModel) { |
25 | return video.url + '/views/' + byAccount.uuid + '/' + new Date().toISOString() | 25 | return video.url + '/views/' + byAccount.uuid + '/' + new Date().toISOString() |
26 | } | 26 | } |
27 | 27 | ||
28 | function getVideoLikeActivityPubUrl (byAccount: AccountInstance, video: VideoInstance) { | 28 | function getVideoLikeActivityPubUrl (byAccount: AccountModel, video: VideoModel) { |
29 | return byAccount.url + '/likes/' + video.id | 29 | return byAccount.url + '/likes/' + video.id |
30 | } | 30 | } |
31 | 31 | ||
32 | function getVideoDislikeActivityPubUrl (byAccount: AccountInstance, video: VideoInstance) { | 32 | function getVideoDislikeActivityPubUrl (byAccount: AccountModel, video: VideoModel) { |
33 | return byAccount.url + '/dislikes/' + video.id | 33 | return byAccount.url + '/dislikes/' + video.id |
34 | } | 34 | } |
35 | 35 | ||
36 | function getAccountFollowActivityPubUrl (accountFollow: AccountFollowInstance) { | 36 | function getAccountFollowActivityPubUrl (accountFollow: AccountFollowModel) { |
37 | const me = accountFollow.AccountFollower | 37 | const me = accountFollow.AccountFollower |
38 | const following = accountFollow.AccountFollowing | 38 | const following = accountFollow.AccountFollowing |
39 | 39 | ||
40 | return me.url + '/follows/' + following.id | 40 | return me.url + '/follows/' + following.id |
41 | } | 41 | } |
42 | 42 | ||
43 | function getAccountFollowAcceptActivityPubUrl (accountFollow: AccountFollowInstance) { | 43 | function getAccountFollowAcceptActivityPubUrl (accountFollow: AccountFollowModel) { |
44 | const follower = accountFollow.AccountFollower | 44 | const follower = accountFollow.AccountFollower |
45 | const me = accountFollow.AccountFollowing | 45 | const me = accountFollow.AccountFollowing |
46 | 46 | ||
47 | return follower.url + '/accepts/follows/' + me.id | 47 | return follower.url + '/accepts/follows/' + me.id |
48 | } | 48 | } |
49 | 49 | ||
50 | function getAnnounceActivityPubUrl (originalUrl: string, byAccount: AccountInstance) { | 50 | function getAnnounceActivityPubUrl (originalUrl: string, byAccount: AccountModel) { |
51 | return originalUrl + '/announces/' + byAccount.id | 51 | return originalUrl + '/announces/' + byAccount.id |
52 | } | 52 | } |
53 | 53 | ||
diff --git a/server/lib/activitypub/video-channels.ts b/server/lib/activitypub/video-channels.ts index 7339d79f9..c05a46f95 100644 --- a/server/lib/activitypub/video-channels.ts +++ b/server/lib/activitypub/video-channels.ts | |||
@@ -1,14 +1,13 @@ | |||
1 | import { VideoChannelObject } from '../../../shared/models/activitypub/objects/video-channel-object' | 1 | import { VideoChannelObject } from '../../../shared/models/activitypub/objects' |
2 | import { isVideoChannelObjectValid } from '../../helpers/custom-validators/activitypub/video-channels' | 2 | import { doRequest, logger } from '../../helpers' |
3 | import { logger } from '../../helpers/logger' | 3 | import { isVideoChannelObjectValid } from '../../helpers/custom-validators/activitypub' |
4 | import { doRequest } from '../../helpers/requests' | 4 | import { ACTIVITY_PUB } from '../../initializers' |
5 | import { database as db } from '../../initializers' | 5 | import { AccountModel } from '../../models/account/account' |
6 | import { ACTIVITY_PUB } from '../../initializers/constants' | 6 | import { VideoChannelModel } from '../../models/video/video-channel' |
7 | import { AccountInstance } from '../../models/account/account-interface' | ||
8 | import { videoChannelActivityObjectToDBAttributes } from './process/misc' | 7 | import { videoChannelActivityObjectToDBAttributes } from './process/misc' |
9 | 8 | ||
10 | async function getOrCreateVideoChannel (ownerAccount: AccountInstance, videoChannelUrl: string) { | 9 | async function getOrCreateVideoChannel (ownerAccount: AccountModel, videoChannelUrl: string) { |
11 | let videoChannel = await db.VideoChannel.loadByUrl(videoChannelUrl) | 10 | let videoChannel = await VideoChannelModel.loadByUrl(videoChannelUrl) |
12 | 11 | ||
13 | // We don't have this account in our database, fetch it on remote | 12 | // We don't have this account in our database, fetch it on remote |
14 | if (!videoChannel) { | 13 | if (!videoChannel) { |
@@ -22,7 +21,7 @@ async function getOrCreateVideoChannel (ownerAccount: AccountInstance, videoChan | |||
22 | return videoChannel | 21 | return videoChannel |
23 | } | 22 | } |
24 | 23 | ||
25 | async function fetchRemoteVideoChannel (ownerAccount: AccountInstance, videoChannelUrl: string) { | 24 | async function fetchRemoteVideoChannel (ownerAccount: AccountModel, videoChannelUrl: string) { |
26 | const options = { | 25 | const options = { |
27 | uri: videoChannelUrl, | 26 | uri: videoChannelUrl, |
28 | method: 'GET', | 27 | method: 'GET', |
@@ -48,7 +47,7 @@ async function fetchRemoteVideoChannel (ownerAccount: AccountInstance, videoChan | |||
48 | } | 47 | } |
49 | 48 | ||
50 | const videoChannelAttributes = videoChannelActivityObjectToDBAttributes(videoChannelJSON, ownerAccount) | 49 | const videoChannelAttributes = videoChannelActivityObjectToDBAttributes(videoChannelJSON, ownerAccount) |
51 | const videoChannel = db.VideoChannel.build(videoChannelAttributes) | 50 | const videoChannel = new VideoChannelModel(videoChannelAttributes) |
52 | videoChannel.Account = ownerAccount | 51 | videoChannel.Account = ownerAccount |
53 | 52 | ||
54 | return videoChannel | 53 | return videoChannel |
diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts index 6b82f12d5..14c07fec0 100644 --- a/server/lib/activitypub/videos.ts +++ b/server/lib/activitypub/videos.ts | |||
@@ -2,21 +2,22 @@ import { join } from 'path' | |||
2 | import * as request from 'request' | 2 | import * as request from 'request' |
3 | import { Transaction } from 'sequelize' | 3 | import { Transaction } from 'sequelize' |
4 | import { ActivityIconObject } from '../../../shared/index' | 4 | import { ActivityIconObject } from '../../../shared/index' |
5 | import { doRequest, doRequestAndSaveToFile } from '../../helpers/requests' | 5 | import { doRequest, doRequestAndSaveToFile } from '../../helpers' |
6 | import { CONFIG, REMOTE_SCHEME, STATIC_PATHS } from '../../initializers/constants' | 6 | import { CONFIG, REMOTE_SCHEME, STATIC_PATHS } from '../../initializers' |
7 | import { AccountInstance } from '../../models/account/account-interface' | 7 | import { AccountModel } from '../../models/account/account' |
8 | import { VideoInstance } from '../../models/video/video-interface' | 8 | import { VideoModel } from '../../models/video/video' |
9 | import { sendLikeToOrigin } from './index' | ||
10 | import { sendCreateDislikeToOrigin, sendCreateDislikeToVideoFollowers } from './send/send-create' | ||
11 | import { sendLikeToVideoFollowers } from './send/send-like' | ||
12 | import { | 9 | import { |
10 | sendCreateDislikeToOrigin, | ||
11 | sendCreateDislikeToVideoFollowers, | ||
12 | sendLikeToOrigin, | ||
13 | sendLikeToVideoFollowers, | ||
13 | sendUndoDislikeToOrigin, | 14 | sendUndoDislikeToOrigin, |
14 | sendUndoDislikeToVideoFollowers, | 15 | sendUndoDislikeToVideoFollowers, |
15 | sendUndoLikeToOrigin, | 16 | sendUndoLikeToOrigin, |
16 | sendUndoLikeToVideoFollowers | 17 | sendUndoLikeToVideoFollowers |
17 | } from './send/send-undo' | 18 | } from './send' |
18 | 19 | ||
19 | function fetchRemoteVideoPreview (video: VideoInstance) { | 20 | function fetchRemoteVideoPreview (video: VideoModel) { |
20 | // FIXME: use url | 21 | // FIXME: use url |
21 | const host = video.VideoChannel.Account.Server.host | 22 | const host = video.VideoChannel.Account.Server.host |
22 | const path = join(STATIC_PATHS.PREVIEWS, video.getPreviewName()) | 23 | const path = join(STATIC_PATHS.PREVIEWS, video.getPreviewName()) |
@@ -24,7 +25,7 @@ function fetchRemoteVideoPreview (video: VideoInstance) { | |||
24 | return request.get(REMOTE_SCHEME.HTTP + '://' + host + path) | 25 | return request.get(REMOTE_SCHEME.HTTP + '://' + host + path) |
25 | } | 26 | } |
26 | 27 | ||
27 | async function fetchRemoteVideoDescription (video: VideoInstance) { | 28 | async function fetchRemoteVideoDescription (video: VideoModel) { |
28 | // FIXME: use url | 29 | // FIXME: use url |
29 | const host = video.VideoChannel.Account.Server.host | 30 | const host = video.VideoChannel.Account.Server.host |
30 | const path = video.getDescriptionPath() | 31 | const path = video.getDescriptionPath() |
@@ -37,7 +38,7 @@ async function fetchRemoteVideoDescription (video: VideoInstance) { | |||
37 | return body.description ? body.description : '' | 38 | return body.description ? body.description : '' |
38 | } | 39 | } |
39 | 40 | ||
40 | function generateThumbnailFromUrl (video: VideoInstance, icon: ActivityIconObject) { | 41 | function generateThumbnailFromUrl (video: VideoModel, icon: ActivityIconObject) { |
41 | const thumbnailName = video.getThumbnailName() | 42 | const thumbnailName = video.getThumbnailName() |
42 | const thumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, thumbnailName) | 43 | const thumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, thumbnailName) |
43 | 44 | ||
@@ -49,8 +50,8 @@ function generateThumbnailFromUrl (video: VideoInstance, icon: ActivityIconObjec | |||
49 | } | 50 | } |
50 | 51 | ||
51 | async function sendVideoRateChangeToFollowers ( | 52 | async function sendVideoRateChangeToFollowers ( |
52 | account: AccountInstance, | 53 | account: AccountModel, |
53 | video: VideoInstance, | 54 | video: VideoModel, |
54 | likes: number, | 55 | likes: number, |
55 | dislikes: number, | 56 | dislikes: number, |
56 | t: Transaction | 57 | t: Transaction |
@@ -69,8 +70,8 @@ async function sendVideoRateChangeToFollowers ( | |||
69 | } | 70 | } |
70 | 71 | ||
71 | async function sendVideoRateChangeToOrigin ( | 72 | async function sendVideoRateChangeToOrigin ( |
72 | account: AccountInstance, | 73 | account: AccountModel, |
73 | video: VideoInstance, | 74 | video: VideoModel, |
74 | likes: number, | 75 | likes: number, |
75 | dislikes: number, | 76 | dislikes: number, |
76 | t: Transaction | 77 | t: Transaction |