diff options
author | Chocobozzz <me@florianbigard.com> | 2018-01-18 10:53:54 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-01-18 15:42:20 +0100 |
commit | f05a1c30c15d2ae35c11e241ca039a72eeb7d6ad (patch) | |
tree | 6d90c0de5dd3ad506e738d447e4f396951ed5624 /server/lib | |
parent | 1174a8479ab9ee47b3305d668fe757435057a298 (diff) | |
download | PeerTube-f05a1c30c15d2ae35c11e241ca039a72eeb7d6ad.tar.gz PeerTube-f05a1c30c15d2ae35c11e241ca039a72eeb7d6ad.tar.zst PeerTube-f05a1c30c15d2ae35c11e241ca039a72eeb7d6ad.zip |
Don't show videos of remote instance after unfollow
Diffstat (limited to 'server/lib')
-rw-r--r-- | server/lib/activitypub/actor.ts | 5 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-delete.ts | 9 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-delete.ts | 5 | ||||
-rw-r--r-- | server/lib/activitypub/videos.ts | 3 | ||||
-rw-r--r-- | server/lib/user.ts | 12 |
5 files changed, 22 insertions, 12 deletions
diff --git a/server/lib/activitypub/actor.ts b/server/lib/activitypub/actor.ts index 2e0f3cfc2..a39b4e137 100644 --- a/server/lib/activitypub/actor.ts +++ b/server/lib/activitypub/actor.ts | |||
@@ -309,7 +309,10 @@ async function refreshActorIfNeeded (actor: ActorModel) { | |||
309 | 309 | ||
310 | const actorUrl = await getUrlFromWebfinger(actor.preferredUsername, actor.getHost()) | 310 | const actorUrl = await getUrlFromWebfinger(actor.preferredUsername, actor.getHost()) |
311 | const result = await fetchRemoteActor(actorUrl) | 311 | const result = await fetchRemoteActor(actorUrl) |
312 | if (result === undefined) throw new Error('Cannot fetch remote actor in refresh actor.') | 312 | if (result === undefined) { |
313 | logger.warn('Cannot fetch remote actor in refresh actor.') | ||
314 | return actor | ||
315 | } | ||
313 | 316 | ||
314 | return sequelizeTypescript.transaction(async t => { | 317 | return sequelizeTypescript.transaction(async t => { |
315 | updateInstanceWithAnother(actor, result.actor) | 318 | updateInstanceWithAnother(actor, result.actor) |
diff --git a/server/lib/activitypub/process/process-delete.ts b/server/lib/activitypub/process/process-delete.ts index 07e6a0075..03eadcbfc 100644 --- a/server/lib/activitypub/process/process-delete.ts +++ b/server/lib/activitypub/process/process-delete.ts | |||
@@ -10,21 +10,26 @@ import { VideoCommentModel } from '../../../models/video/video-comment' | |||
10 | import { getOrCreateActorAndServerAndModel } from '../actor' | 10 | import { getOrCreateActorAndServerAndModel } from '../actor' |
11 | 11 | ||
12 | async function processDeleteActivity (activity: ActivityDelete) { | 12 | async function processDeleteActivity (activity: ActivityDelete) { |
13 | const actor = await getOrCreateActorAndServerAndModel(activity.actor) | ||
14 | const objectUrl = typeof activity.object === 'string' ? activity.object : activity.object.id | 13 | const objectUrl = typeof activity.object === 'string' ? activity.object : activity.object.id |
15 | 14 | ||
16 | if (actor.url === objectUrl) { | 15 | if (activity.actor === objectUrl) { |
16 | let actor = await ActorModel.loadByUrl(activity.actor) | ||
17 | if (!actor) return | ||
18 | |||
17 | if (actor.type === 'Person') { | 19 | if (actor.type === 'Person') { |
18 | if (!actor.Account) throw new Error('Actor ' + actor.url + ' is a person but we cannot find it in database.') | 20 | if (!actor.Account) throw new Error('Actor ' + actor.url + ' is a person but we cannot find it in database.') |
19 | 21 | ||
22 | actor.Account.Actor = await actor.Account.$get('Actor') as ActorModel | ||
20 | return processDeleteAccount(actor.Account) | 23 | return processDeleteAccount(actor.Account) |
21 | } else if (actor.type === 'Group') { | 24 | } else if (actor.type === 'Group') { |
22 | if (!actor.VideoChannel) throw new Error('Actor ' + actor.url + ' is a group but we cannot find it in database.') | 25 | if (!actor.VideoChannel) throw new Error('Actor ' + actor.url + ' is a group but we cannot find it in database.') |
23 | 26 | ||
27 | actor.VideoChannel.Actor = await actor.VideoChannel.$get('Actor') as ActorModel | ||
24 | return processDeleteVideoChannel(actor.VideoChannel) | 28 | return processDeleteVideoChannel(actor.VideoChannel) |
25 | } | 29 | } |
26 | } | 30 | } |
27 | 31 | ||
32 | const actor = await getOrCreateActorAndServerAndModel(activity.actor) | ||
28 | { | 33 | { |
29 | const videoCommentInstance = await VideoCommentModel.loadByUrlAndPopulateAccount(objectUrl) | 34 | const videoCommentInstance = await VideoCommentModel.loadByUrlAndPopulateAccount(objectUrl) |
30 | if (videoCommentInstance) { | 35 | if (videoCommentInstance) { |
diff --git a/server/lib/activitypub/send/send-delete.ts b/server/lib/activitypub/send/send-delete.ts index 995a534a6..9f1ea3bd0 100644 --- a/server/lib/activitypub/send/send-delete.ts +++ b/server/lib/activitypub/send/send-delete.ts | |||
@@ -23,7 +23,10 @@ async function sendDeleteActor (byActor: ActorModel, t: Transaction) { | |||
23 | const url = getDeleteActivityPubUrl(byActor.url) | 23 | const url = getDeleteActivityPubUrl(byActor.url) |
24 | const data = deleteActivityData(url, byActor.url, byActor) | 24 | const data = deleteActivityData(url, byActor.url, byActor) |
25 | 25 | ||
26 | return broadcastToFollowers(data, byActor, [ byActor ], t) | 26 | const actorsInvolved = await VideoShareModel.loadActorsByVideoOwner(byActor.id, t) |
27 | actorsInvolved.push(byActor) | ||
28 | |||
29 | return broadcastToFollowers(data, byActor, actorsInvolved, t) | ||
27 | } | 30 | } |
28 | 31 | ||
29 | async function sendDeleteVideoComment (videoComment: VideoCommentModel, t: Transaction) { | 32 | async function sendDeleteVideoComment (videoComment: VideoCommentModel, t: Transaction) { |
diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts index 5b429709f..1d2d46cbc 100644 --- a/server/lib/activitypub/videos.ts +++ b/server/lib/activitypub/videos.ts | |||
@@ -20,17 +20,16 @@ import { VideoShareModel } from '../../models/video/video-share' | |||
20 | import { getOrCreateActorAndServerAndModel } from './actor' | 20 | import { getOrCreateActorAndServerAndModel } from './actor' |
21 | 21 | ||
22 | function fetchRemoteVideoPreview (video: VideoModel, reject: Function) { | 22 | function fetchRemoteVideoPreview (video: VideoModel, reject: Function) { |
23 | // FIXME: use url | ||
24 | const host = video.VideoChannel.Account.Actor.Server.host | 23 | const host = video.VideoChannel.Account.Actor.Server.host |
25 | const path = join(STATIC_PATHS.PREVIEWS, video.getPreviewName()) | 24 | const path = join(STATIC_PATHS.PREVIEWS, video.getPreviewName()) |
26 | 25 | ||
26 | // We need to provide a callback, if no we could have an uncaught exception | ||
27 | return request.get(REMOTE_SCHEME.HTTP + '://' + host + path, err => { | 27 | return request.get(REMOTE_SCHEME.HTTP + '://' + host + path, err => { |
28 | if (err) reject(err) | 28 | if (err) reject(err) |
29 | }) | 29 | }) |
30 | } | 30 | } |
31 | 31 | ||
32 | async function fetchRemoteVideoDescription (video: VideoModel) { | 32 | async function fetchRemoteVideoDescription (video: VideoModel) { |
33 | // FIXME: use url | ||
34 | const host = video.VideoChannel.Account.Actor.Server.host | 33 | const host = video.VideoChannel.Account.Actor.Server.host |
35 | const path = video.getDescriptionPath() | 34 | const path = video.getDescriptionPath() |
36 | const options = { | 35 | const options = { |
diff --git a/server/lib/user.ts b/server/lib/user.ts index ec1466c6f..aa029cce7 100644 --- a/server/lib/user.ts +++ b/server/lib/user.ts | |||
@@ -6,15 +6,15 @@ import { UserModel } from '../models/account/user' | |||
6 | import { buildActorInstance, getAccountActivityPubUrl, setAsyncActorKeys } from './activitypub' | 6 | import { buildActorInstance, getAccountActivityPubUrl, setAsyncActorKeys } from './activitypub' |
7 | import { createVideoChannel } from './video-channel' | 7 | import { createVideoChannel } from './video-channel' |
8 | 8 | ||
9 | async function createUserAccountAndChannel (user: UserModel, validateUser = true) { | 9 | async function createUserAccountAndChannel (userToCreate: UserModel, validateUser = true) { |
10 | const { account, videoChannel } = await sequelizeTypescript.transaction(async t => { | 10 | const { user, account, videoChannel } = await sequelizeTypescript.transaction(async t => { |
11 | const userOptions = { | 11 | const userOptions = { |
12 | transaction: t, | 12 | transaction: t, |
13 | validate: validateUser | 13 | validate: validateUser |
14 | } | 14 | } |
15 | 15 | ||
16 | const userCreated = await user.save(userOptions) | 16 | const userCreated = await userToCreate.save(userOptions) |
17 | const accountCreated = await createLocalAccountWithoutKeys(user.username, user.id, null, t) | 17 | const accountCreated = await createLocalAccountWithoutKeys(userToCreate.username, userToCreate.id, null, t) |
18 | 18 | ||
19 | const videoChannelName = `Default ${userCreated.username} channel` | 19 | const videoChannelName = `Default ${userCreated.username} channel` |
20 | const videoChannelInfo = { | 20 | const videoChannelInfo = { |
@@ -22,13 +22,13 @@ async function createUserAccountAndChannel (user: UserModel, validateUser = true | |||
22 | } | 22 | } |
23 | const videoChannel = await createVideoChannel(videoChannelInfo, accountCreated, t) | 23 | const videoChannel = await createVideoChannel(videoChannelInfo, accountCreated, t) |
24 | 24 | ||
25 | return { account: accountCreated, videoChannel } | 25 | return { user: userCreated, account: accountCreated, videoChannel } |
26 | }) | 26 | }) |
27 | 27 | ||
28 | account.Actor = await setAsyncActorKeys(account.Actor) | 28 | account.Actor = await setAsyncActorKeys(account.Actor) |
29 | videoChannel.Actor = await setAsyncActorKeys(videoChannel.Actor) | 29 | videoChannel.Actor = await setAsyncActorKeys(videoChannel.Actor) |
30 | 30 | ||
31 | return { account, videoChannel } | 31 | return { user, account, videoChannel } |
32 | } | 32 | } |
33 | 33 | ||
34 | async function createLocalAccountWithoutKeys ( | 34 | async function createLocalAccountWithoutKeys ( |