From f05a1c30c15d2ae35c11e241ca039a72eeb7d6ad Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 18 Jan 2018 10:53:54 +0100 Subject: Don't show videos of remote instance after unfollow --- server/lib/activitypub/actor.ts | 5 ++++- server/lib/activitypub/process/process-delete.ts | 9 +++++++-- server/lib/activitypub/send/send-delete.ts | 5 ++++- server/lib/activitypub/videos.ts | 3 +-- server/lib/user.ts | 12 ++++++------ 5 files changed, 22 insertions(+), 12 deletions(-) (limited to 'server/lib') 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) { const actorUrl = await getUrlFromWebfinger(actor.preferredUsername, actor.getHost()) const result = await fetchRemoteActor(actorUrl) - if (result === undefined) throw new Error('Cannot fetch remote actor in refresh actor.') + if (result === undefined) { + logger.warn('Cannot fetch remote actor in refresh actor.') + return actor + } return sequelizeTypescript.transaction(async t => { 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' import { getOrCreateActorAndServerAndModel } from '../actor' async function processDeleteActivity (activity: ActivityDelete) { - const actor = await getOrCreateActorAndServerAndModel(activity.actor) const objectUrl = typeof activity.object === 'string' ? activity.object : activity.object.id - if (actor.url === objectUrl) { + if (activity.actor === objectUrl) { + let actor = await ActorModel.loadByUrl(activity.actor) + if (!actor) return + if (actor.type === 'Person') { if (!actor.Account) throw new Error('Actor ' + actor.url + ' is a person but we cannot find it in database.') + actor.Account.Actor = await actor.Account.$get('Actor') as ActorModel return processDeleteAccount(actor.Account) } else if (actor.type === 'Group') { if (!actor.VideoChannel) throw new Error('Actor ' + actor.url + ' is a group but we cannot find it in database.') + actor.VideoChannel.Actor = await actor.VideoChannel.$get('Actor') as ActorModel return processDeleteVideoChannel(actor.VideoChannel) } } + const actor = await getOrCreateActorAndServerAndModel(activity.actor) { const videoCommentInstance = await VideoCommentModel.loadByUrlAndPopulateAccount(objectUrl) 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) { const url = getDeleteActivityPubUrl(byActor.url) const data = deleteActivityData(url, byActor.url, byActor) - return broadcastToFollowers(data, byActor, [ byActor ], t) + const actorsInvolved = await VideoShareModel.loadActorsByVideoOwner(byActor.id, t) + actorsInvolved.push(byActor) + + return broadcastToFollowers(data, byActor, actorsInvolved, t) } 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' import { getOrCreateActorAndServerAndModel } from './actor' function fetchRemoteVideoPreview (video: VideoModel, reject: Function) { - // FIXME: use url const host = video.VideoChannel.Account.Actor.Server.host const path = join(STATIC_PATHS.PREVIEWS, video.getPreviewName()) + // We need to provide a callback, if no we could have an uncaught exception return request.get(REMOTE_SCHEME.HTTP + '://' + host + path, err => { if (err) reject(err) }) } async function fetchRemoteVideoDescription (video: VideoModel) { - // FIXME: use url const host = video.VideoChannel.Account.Actor.Server.host const path = video.getDescriptionPath() 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' import { buildActorInstance, getAccountActivityPubUrl, setAsyncActorKeys } from './activitypub' import { createVideoChannel } from './video-channel' -async function createUserAccountAndChannel (user: UserModel, validateUser = true) { - const { account, videoChannel } = await sequelizeTypescript.transaction(async t => { +async function createUserAccountAndChannel (userToCreate: UserModel, validateUser = true) { + const { user, account, videoChannel } = await sequelizeTypescript.transaction(async t => { const userOptions = { transaction: t, validate: validateUser } - const userCreated = await user.save(userOptions) - const accountCreated = await createLocalAccountWithoutKeys(user.username, user.id, null, t) + const userCreated = await userToCreate.save(userOptions) + const accountCreated = await createLocalAccountWithoutKeys(userToCreate.username, userToCreate.id, null, t) const videoChannelName = `Default ${userCreated.username} channel` const videoChannelInfo = { @@ -22,13 +22,13 @@ async function createUserAccountAndChannel (user: UserModel, validateUser = true } const videoChannel = await createVideoChannel(videoChannelInfo, accountCreated, t) - return { account: accountCreated, videoChannel } + return { user: userCreated, account: accountCreated, videoChannel } }) account.Actor = await setAsyncActorKeys(account.Actor) videoChannel.Actor = await setAsyncActorKeys(videoChannel.Actor) - return { account, videoChannel } + return { user, account, videoChannel } } async function createLocalAccountWithoutKeys ( -- cgit v1.2.3