From 571389d43b8fc8aaf27e77c06f19b320b08dbbc9 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 10 Nov 2017 17:27:49 +0100 Subject: Make it compile at least --- server/models/account/account-interface.ts | 4 ++-- server/models/account/account.ts | 17 ++++++++++------- 2 files changed, 12 insertions(+), 9 deletions(-) (limited to 'server/models/account') diff --git a/server/models/account/account-interface.ts b/server/models/account/account-interface.ts index 2ef3e2246..a662eb992 100644 --- a/server/models/account/account-interface.ts +++ b/server/models/account/account-interface.ts @@ -13,8 +13,8 @@ export namespace AccountMethods { export type LoadAccountByPodAndUUID = (uuid: string, podId: number, transaction: Sequelize.Transaction) => Bluebird export type LoadLocalAccountByName = (name: string) => Bluebird export type ListOwned = () => Bluebird - export type ListFollowerUrlsForApi = (name: string, start: number, count: number) => Promise< ResultList > - export type ListFollowingUrlsForApi = (name: string, start: number, count: number) => Promise< ResultList > + export type ListFollowerUrlsForApi = (name: string, start: number, count?: number) => Promise< ResultList > + export type ListFollowingUrlsForApi = (name: string, start: number, count?: number) => Promise< ResultList > export type ToActivityPubObject = (this: AccountInstance) => ActivityPubActor export type IsOwned = (this: AccountInstance) => boolean diff --git a/server/models/account/account.ts b/server/models/account/account.ts index 00c0aefd4..a79e13880 100644 --- a/server/models/account/account.ts +++ b/server/models/account/account.ts @@ -268,14 +268,15 @@ function afterDestroy (account: AccountInstance) { uuid: account.uuid } - return removeVideoAccountToFriends(removeVideoAccountToFriendsParams) + // FIXME: remove account in followers + // return removeVideoAccountToFriends(removeVideoAccountToFriendsParams) } return undefined } toActivityPubObject = function (this: AccountInstance) { - const type = this.podId ? 'Application' : 'Person' + const type = this.podId ? 'Application' as 'Application' : 'Person' as 'Person' const json = { type, @@ -346,11 +347,11 @@ listOwned = function () { return Account.findAll(query) } -listFollowerUrlsForApi = function (name: string, start: number, count: number) { +listFollowerUrlsForApi = function (name: string, start: number, count?: number) { return createListFollowForApiQuery('followers', name, start, count) } -listFollowingUrlsForApi = function (name: string, start: number, count: number) { +listFollowingUrlsForApi = function (name: string, start: number, count?: number) { return createListFollowForApiQuery('following', name, start, count) } @@ -405,7 +406,7 @@ loadAccountByPodAndUUID = function (uuid: string, podId: number, transaction: Se // ------------------------------ UTILS ------------------------------ -async function createListFollowForApiQuery (type: 'followers' | 'following', name: string, start: number, count: number) { +async function createListFollowForApiQuery (type: 'followers' | 'following', name: string, start: number, count?: number) { let firstJoin: string let secondJoin: string @@ -421,11 +422,13 @@ async function createListFollowForApiQuery (type: 'followers' | 'following', nam const tasks: Promise[] = [] for (const selection of selections) { - const query = 'SELECT ' + selection + ' FROM "Account" ' + + let query = 'SELECT ' + selection + ' FROM "Account" ' + 'INNER JOIN "AccountFollower" ON "AccountFollower"."' + firstJoin + '" = "Account"."id" ' + 'INNER JOIN "Account" AS "Followers" ON "Followers"."id" = "AccountFollower"."' + secondJoin + '" ' + 'WHERE "Account"."name" = \'$name\' ' + - 'LIMIT ' + start + ', ' + count + 'LIMIT ' + start + + if (count !== undefined) query += ', ' + count const options = { bind: { name }, -- cgit v1.2.3