From 2422c46b27790d94fd29a7092170cee5a1b56008 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 15 Feb 2018 14:46:26 +0100 Subject: Implement support field in video and video channel --- server/lib/activitypub/actor.ts | 13 ++++-- server/lib/activitypub/process/process-update.ts | 52 ++++++++++++++---------- server/lib/activitypub/send/send-update.ts | 23 +++++++---- server/lib/activitypub/videos.ts | 6 +++ server/lib/video-channel.ts | 1 + 5 files changed, 63 insertions(+), 32 deletions(-) (limited to 'server/lib') diff --git a/server/lib/activitypub/actor.ts b/server/lib/activitypub/actor.ts index c3255d8ca..897acee85 100644 --- a/server/lib/activitypub/actor.ts +++ b/server/lib/activitypub/actor.ts @@ -225,12 +225,10 @@ function saveActorAndServerAndModelIfNotExist ( }) if (actorCreated.type === 'Person' || actorCreated.type === 'Application') { - const account = await saveAccount(actorCreated, result, t) - actorCreated.Account = account + actorCreated.Account = await saveAccount(actorCreated, result, t) actorCreated.Account.Actor = actorCreated } else if (actorCreated.type === 'Group') { // Video channel - const videoChannel = await saveVideoChannel(actorCreated, result, ownerActor, t) - actorCreated.VideoChannel = videoChannel + actorCreated.VideoChannel = await saveVideoChannel(actorCreated, result, ownerActor, t) actorCreated.VideoChannel.Actor = actorCreated } @@ -242,6 +240,7 @@ type FetchRemoteActorResult = { actor: ActorModel name: string summary: string + support?: string avatarName?: string attributedTo: ActivityPubAttributedTo[] } @@ -290,6 +289,7 @@ async function fetchRemoteActor (actorUrl: string): Promise { actorFieldsSave = actor.toJSON() - accountInstance = actor.Account - accountFieldsSave = actor.Account.toJSON() - await updateActorInstance(actor, accountAttributesToUpdate) + if (actorAttributesToUpdate.type === 'Group') accountOrChannelInstance = actor.VideoChannel + else accountOrChannelInstance = actor.Account + + accountOrChannelFieldsSave = accountOrChannelInstance.toJSON() + + await updateActorInstance(actor, actorAttributesToUpdate) if (avatarName !== undefined) { await updateActorAvatarInstance(actor, avatarName, t) @@ -151,18 +159,20 @@ async function updateRemoteAccount (actor: ActorModel, activity: ActivityUpdate) await actor.save({ transaction: t }) - actor.Account.set('name', accountAttributesToUpdate.name || accountAttributesToUpdate.preferredUsername) - await actor.Account.save({ transaction: t }) + accountOrChannelInstance.set('name', actorAttributesToUpdate.name || actorAttributesToUpdate.preferredUsername) + accountOrChannelInstance.set('description', actorAttributesToUpdate.summary) + accountOrChannelInstance.set('support', actorAttributesToUpdate.support) + await accountOrChannelInstance.save({ transaction: t }) }) - logger.info('Remote account with uuid %s updated', accountAttributesToUpdate.uuid) + logger.info('Remote account with uuid %s updated', actorAttributesToUpdate.uuid) } catch (err) { if (actor !== undefined && actorFieldsSave !== undefined) { resetSequelizeInstance(actor, actorFieldsSave) } - if (accountInstance !== undefined && accountFieldsSave !== undefined) { - resetSequelizeInstance(accountInstance, accountFieldsSave) + if (accountOrChannelInstance !== undefined && accountOrChannelFieldsSave !== undefined) { + resetSequelizeInstance(accountOrChannelInstance, accountOrChannelFieldsSave) } // This is just a debug because we will retry the insert diff --git a/server/lib/activitypub/send/send-update.ts b/server/lib/activitypub/send/send-update.ts index e8f11edd0..622648308 100644 --- a/server/lib/activitypub/send/send-update.ts +++ b/server/lib/activitypub/send/send-update.ts @@ -1,9 +1,10 @@ import { Transaction } from 'sequelize' import { ActivityAudience, ActivityUpdate } from '../../../../shared/models/activitypub' import { VideoPrivacy } from '../../../../shared/models/videos' -import { UserModel } from '../../../models/account/user' +import { AccountModel } from '../../../models/account/account' import { ActorModel } from '../../../models/activitypub/actor' import { VideoModel } from '../../../models/video/video' +import { VideoChannelModel } from '../../../models/video/video-channel' import { VideoShareModel } from '../../../models/video/video-share' import { getUpdateActivityPubUrl } from '../url' import { audiencify, broadcastToFollowers, getAudience } from './misc' @@ -23,15 +24,23 @@ async function sendUpdateVideo (video: VideoModel, t: Transaction) { return broadcastToFollowers(data, byActor, actorsInvolved, t) } -async function sendUpdateUser (user: UserModel, t: Transaction) { - const byActor = user.Account.Actor +async function sendUpdateActor (accountOrChannel: AccountModel | VideoChannelModel, t: Transaction) { + const byActor = accountOrChannel.Actor const url = getUpdateActivityPubUrl(byActor.url, byActor.updatedAt.toISOString()) - const accountObject = user.Account.toActivityPubObject() + const accountOrChannelObject = accountOrChannel.toActivityPubObject() const audience = await getAudience(byActor, t) - const data = await updateActivityData(url, byActor, accountObject, t, audience) + const data = await updateActivityData(url, byActor, accountOrChannelObject, t, audience) + + let actorsInvolved: ActorModel[] + if (accountOrChannel instanceof AccountModel) { + // Actors that shared my videos are involved too + actorsInvolved = await VideoShareModel.loadActorsByVideoOwner(byActor.id, t) + } else { + // Actors that shared videos of my channel are involved too + actorsInvolved = await VideoShareModel.loadActorsByVideoChannel(accountOrChannel.id, t) + } - const actorsInvolved = await VideoShareModel.loadActorsByVideoOwner(byActor.id, t) actorsInvolved.push(byActor) return broadcastToFollowers(data, byActor, actorsInvolved, t) @@ -40,7 +49,7 @@ async function sendUpdateUser (user: UserModel, t: Transaction) { // --------------------------------------------------------------------------- export { - sendUpdateUser, + sendUpdateActor, sendUpdateVideo } diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts index 40e9318e3..e65362190 100644 --- a/server/lib/activitypub/videos.ts +++ b/server/lib/activitypub/videos.ts @@ -83,6 +83,11 @@ async function videoActivityObjectToDBAttributes (videoChannel: VideoChannelMode description = videoObject.content } + let support = null + if (videoObject.support) { + support = videoObject.support + } + return { name: videoObject.name, uuid: videoObject.uuid, @@ -91,6 +96,7 @@ async function videoActivityObjectToDBAttributes (videoChannel: VideoChannelMode licence, language, description, + support, nsfw: videoObject.sensitive, commentsEnabled: videoObject.commentsEnabled, channelId: videoChannel.id, diff --git a/server/lib/video-channel.ts b/server/lib/video-channel.ts index 569b8f29d..9f7ed9297 100644 --- a/server/lib/video-channel.ts +++ b/server/lib/video-channel.ts @@ -16,6 +16,7 @@ async function createVideoChannel (videoChannelInfo: VideoChannelCreate, account const videoChannelData = { name: videoChannelInfo.name, description: videoChannelInfo.description, + support: videoChannelInfo.support, accountId: account.id, actorId: actorInstanceCreated.id } -- cgit v1.2.3