From 3fd3ab2d34d512b160a5e6084d7609be7b4f4452 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 12 Dec 2017 17:53:50 +0100 Subject: Move models to typescript-sequelize --- server/lib/activitypub/send/send-announce.ts | 35 ++++++++++++---------------- 1 file changed, 15 insertions(+), 20 deletions(-) (limited to 'server/lib/activitypub/send/send-announce.ts') 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 @@ import { Transaction } from 'sequelize' import { ActivityAdd } from '../../../../shared/index' -import { ActivityAnnounce, ActivityAudience, ActivityCreate } from '../../../../shared/models/activitypub/activity' -import { AccountInstance, VideoInstance } from '../../../models' -import { VideoChannelInstance } from '../../../models/video/video-channel-interface' +import { ActivityAnnounce, ActivityAudience, ActivityCreate } from '../../../../shared/models/activitypub' +import { AccountModel } from '../../../models/account/account' +import { VideoModel } from '../../../models/video/video' +import { VideoChannelModel } from '../../../models/video/video-channel' import { getAnnounceActivityPubUrl } from '../url' import { broadcastToFollowers, @@ -17,7 +18,7 @@ import { import { addActivityData } from './send-add' import { createActivityData } from './send-create' -async function buildVideoAnnounceToFollowers (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { +async function buildVideoAnnounceToFollowers (byAccount: AccountModel, video: VideoModel, t: Transaction) { const url = getAnnounceActivityPubUrl(video.url, byAccount) const videoChannel = video.VideoChannel @@ -25,18 +26,16 @@ async function buildVideoAnnounceToFollowers (byAccount: AccountInstance, video: const accountsToForwardView = await getAccountsInvolvedInVideo(video, t) const audience = getObjectFollowersAudience(accountsToForwardView) - const data = await announceActivityData(url, byAccount, announcedActivity, t, audience) - - return data + return announceActivityData(url, byAccount, announcedActivity, t, audience) } -async function sendVideoAnnounceToFollowers (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { +async function sendVideoAnnounceToFollowers (byAccount: AccountModel, video: VideoModel, t: Transaction) { const data = await buildVideoAnnounceToFollowers(byAccount, video, t) return broadcastToFollowers(data, byAccount, [ byAccount ], t) } -async function sendVideoAnnounceToOrigin (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { +async function sendVideoAnnounceToOrigin (byAccount: AccountModel, video: VideoModel, t: Transaction) { const url = getAnnounceActivityPubUrl(video.url, byAccount) const videoChannel = video.VideoChannel @@ -49,24 +48,22 @@ async function sendVideoAnnounceToOrigin (byAccount: AccountInstance, video: Vid return unicastTo(data, byAccount, videoChannel.Account.sharedInboxUrl, t) } -async function buildVideoChannelAnnounceToFollowers (byAccount: AccountInstance, videoChannel: VideoChannelInstance, t: Transaction) { +async function buildVideoChannelAnnounceToFollowers (byAccount: AccountModel, videoChannel: VideoChannelModel, t: Transaction) { const url = getAnnounceActivityPubUrl(videoChannel.url, byAccount) const announcedActivity = await createActivityData(url, videoChannel.Account, videoChannel.toActivityPubObject(), t) const accountsToForwardView = await getAccountsInvolvedInVideoChannel(videoChannel, t) const audience = getObjectFollowersAudience(accountsToForwardView) - const data = await announceActivityData(url, byAccount, announcedActivity, t, audience) - - return data + return announceActivityData(url, byAccount, announcedActivity, t, audience) } -async function sendVideoChannelAnnounceToFollowers (byAccount: AccountInstance, videoChannel: VideoChannelInstance, t: Transaction) { +async function sendVideoChannelAnnounceToFollowers (byAccount: AccountModel, videoChannel: VideoChannelModel, t: Transaction) { const data = await buildVideoChannelAnnounceToFollowers(byAccount, videoChannel, t) return broadcastToFollowers(data, byAccount, [ byAccount ], t) } -async function sendVideoChannelAnnounceToOrigin (byAccount: AccountInstance, videoChannel: VideoChannelInstance, t: Transaction) { +async function sendVideoChannelAnnounceToOrigin (byAccount: AccountModel, videoChannel: VideoChannelModel, t: Transaction) { const url = getAnnounceActivityPubUrl(videoChannel.url, byAccount) const announcedActivity = await createActivityData(url, videoChannel.Account, videoChannel.toActivityPubObject(), t) @@ -79,16 +76,16 @@ async function sendVideoChannelAnnounceToOrigin (byAccount: AccountInstance, vid async function announceActivityData ( url: string, - byAccount: AccountInstance, + byAccount: AccountModel, object: ActivityCreate | ActivityAdd, t: Transaction, audience?: ActivityAudience -) { +): Promise { if (!audience) { audience = await getAudience(byAccount, t) } - const activity: ActivityAnnounce = { + return { type: 'Announce', to: audience.to, cc: audience.cc, @@ -96,8 +93,6 @@ async function announceActivityData ( actor: byAccount.url, object } - - return activity } // --------------------------------------------------------------------------- -- cgit v1.2.3