From efc32059d980c51793e8e9ac0fb6a885a8026f94 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 16 Nov 2017 11:08:25 +0100 Subject: Send server announce when users upload a video --- server/models/account/account-follow-interface.ts | 6 +++-- server/models/account/account-follow.ts | 30 ++++++++++++++++------- server/models/video/video-channel.ts | 4 +-- server/models/video/video.ts | 6 ++--- 4 files changed, 30 insertions(+), 16 deletions(-) (limited to 'server/models') diff --git a/server/models/account/account-follow-interface.ts b/server/models/account/account-follow-interface.ts index 54baf45ed..21fda98ce 100644 --- a/server/models/account/account-follow-interface.ts +++ b/server/models/account/account-follow-interface.ts @@ -10,8 +10,9 @@ export namespace AccountFollowMethods { export type ListFollowingForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList > export type ListFollowersForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList > - export type ListAcceptedFollowerUrlsForApi = (id: number, start?: number, count?: number) => Promise< ResultList > - export type ListAcceptedFollowingUrlsForApi = (id: number, start?: number, count?: number) => Promise< ResultList > + export type ListAcceptedFollowerUrlsForApi = (accountId: number[], start?: number, count?: number) => Promise< ResultList > + export type ListAcceptedFollowingUrlsForApi = (accountId: number[], start?: number, count?: number) => Promise< ResultList > + export type ListAcceptedFollowerSharedInboxUrls = (accountId: number[]) => Promise< ResultList > } export interface AccountFollowClass { @@ -21,6 +22,7 @@ export interface AccountFollowClass { listAcceptedFollowerUrlsForApi: AccountFollowMethods.ListAcceptedFollowerUrlsForApi listAcceptedFollowingUrlsForApi: AccountFollowMethods.ListAcceptedFollowingUrlsForApi + listAcceptedFollowerSharedInboxUrls: AccountFollowMethods.ListAcceptedFollowerSharedInboxUrls } export interface AccountFollowAttributes { diff --git a/server/models/account/account-follow.ts b/server/models/account/account-follow.ts index f457e43e9..8a7474c9d 100644 --- a/server/models/account/account-follow.ts +++ b/server/models/account/account-follow.ts @@ -11,6 +11,7 @@ let listFollowingForApi: AccountFollowMethods.ListFollowingForApi let listFollowersForApi: AccountFollowMethods.ListFollowersForApi let listAcceptedFollowerUrlsForApi: AccountFollowMethods.ListAcceptedFollowerUrlsForApi let listAcceptedFollowingUrlsForApi: AccountFollowMethods.ListAcceptedFollowingUrlsForApi +let listAcceptedFollowerSharedInboxUrls: AccountFollowMethods.ListAcceptedFollowerSharedInboxUrls export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { AccountFollow = sequelize.define('AccountFollow', @@ -42,7 +43,8 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da listFollowingForApi, listFollowersForApi, listAcceptedFollowerUrlsForApi, - listAcceptedFollowingUrlsForApi + listAcceptedFollowingUrlsForApi, + listAcceptedFollowerSharedInboxUrls ] addMethodsToModel(AccountFollow, classMethods) @@ -146,17 +148,27 @@ listFollowersForApi = function (id: number, start: number, count: number, sort: }) } -listAcceptedFollowerUrlsForApi = function (accountId: number, start?: number, count?: number) { - return createListAcceptedFollowForApiQuery('followers', accountId, start, count) +listAcceptedFollowerUrlsForApi = function (accountIds: number[], start?: number, count?: number) { + return createListAcceptedFollowForApiQuery('followers', accountIds, start, count) } -listAcceptedFollowingUrlsForApi = function (accountId: number, start?: number, count?: number) { - return createListAcceptedFollowForApiQuery('following', accountId, start, count) +listAcceptedFollowerSharedInboxUrls = function (accountIds: number[]) { + return createListAcceptedFollowForApiQuery('followers', accountIds, undefined, undefined, 'sharedInboxUrl') +} + +listAcceptedFollowingUrlsForApi = function (accountIds: number[], start?: number, count?: number) { + return createListAcceptedFollowForApiQuery('following', accountIds, start, count) } // ------------------------------ UTILS ------------------------------ -async function createListAcceptedFollowForApiQuery (type: 'followers' | 'following', accountId: number, start?: number, count?: number) { +async function createListAcceptedFollowForApiQuery ( + type: 'followers' | 'following', + accountIds: number[], + start?: number, + count?: number, + columnUrl = 'url' +) { let firstJoin: string let secondJoin: string @@ -168,20 +180,20 @@ async function createListAcceptedFollowForApiQuery (type: 'followers' | 'followi secondJoin = 'targetAccountId' } - const selections = [ '"Follows"."url" AS "url"', 'COUNT(*) AS "total"' ] + const selections = [ '"Follows"."' + columnUrl + '" AS "url"', 'COUNT(*) AS "total"' ] const tasks: Promise[] = [] for (const selection of selections) { let query = 'SELECT ' + selection + ' FROM "Accounts" ' + 'INNER JOIN "AccountFollows" ON "AccountFollows"."' + firstJoin + '" = "Accounts"."id" ' + 'INNER JOIN "Accounts" AS "Follows" ON "AccountFollows"."' + secondJoin + '" = "Follows"."id" ' + - 'WHERE "Accounts"."id" = $accountId AND "AccountFollows"."state" = \'accepted\' ' + 'WHERE "Accounts"."id" IN ($accountIds) AND "AccountFollows"."state" = \'accepted\' ' if (start !== undefined) query += 'LIMIT ' + start if (count !== undefined) query += ', ' + count const options = { - bind: { accountId }, + bind: { accountIds: accountIds.join(',') }, type: Sequelize.QueryTypes.SELECT } tasks.push(AccountFollow['sequelize'].query(query, options)) diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index 3cb4a33b9..1f4604f1d 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts @@ -153,8 +153,8 @@ toActivityPubObject = function (this: VideoChannelInstance) { uuid: this.uuid, content: this.description, name: this.name, - published: this.createdAt, - updated: this.updatedAt + published: this.createdAt.toISOString(), + updated: this.updatedAt.toISOString() } return json diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 480e54276..64ee7ae34 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -558,7 +558,7 @@ toActivityPubObject = function (this: VideoInstance) { for (const file of this.VideoFiles) { url.push({ type: 'Link', - mimeType: 'video/' + file.extname, + mimeType: 'video/' + file.extname.replace('.', ''), url: getVideoFileUrl(this, file, baseUrlHttp), width: file.resolution, size: file.size @@ -601,8 +601,8 @@ toActivityPubObject = function (this: VideoInstance) { }, views: this.views, nsfw: this.nsfw, - published: this.createdAt, - updated: this.updatedAt, + published: this.createdAt.toISOString(), + updated: this.updatedAt.toISOString(), mediaType: 'text/markdown', content: this.getTruncatedDescription(), icon: { -- cgit v1.2.3