X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Futils.ts;h=5b4093aec40d7b2aee217810c437da749b167afd;hb=e0e665f0efa98f2701dd9f5529e99989680481ae;hp=e0bf091ad0539a7e981d6d9216d5f0ace9282b89;hpb=4b54f1360ebb5b1aeb70544981f2721e9a03f0bb;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/utils.ts b/server/models/utils.ts index e0bf091ad..5b4093aec 100644 --- a/server/models/utils.ts +++ b/server/models/utils.ts @@ -29,7 +29,11 @@ function getVideoSort (value: string, lastSort: string[] = [ 'id', 'ASC' ]) { ] } - return [ [ field, direction ], lastSort ] + const firstSort = typeof field === 'string' ? + field.split('.').concat([ direction ]) : + [ field, direction ] + + return [ firstSort, lastSort ] } function getSortOnModel (model: any, value: string, lastSort: string[] = [ 'id', 'ASC' ]) { @@ -64,9 +68,25 @@ function createSimilarityAttribute (col: string, value: string) { ) } +function buildBlockedAccountSQL (serverAccountId: number, userAccountId?: number) { + const blockerIds = [ serverAccountId ] + if (userAccountId) blockerIds.push(userAccountId) + + const blockerIdsString = blockerIds.join(', ') + + const query = 'SELECT "targetAccountId" AS "id" FROM "accountBlocklist" WHERE "accountId" IN (' + blockerIdsString + ')' + + ' UNION ALL ' + + 'SELECT "account"."id" AS "id" FROM account INNER JOIN "actor" ON account."actorId" = actor.id ' + + 'INNER JOIN "serverBlocklist" ON "actor"."serverId" = "serverBlocklist"."targetServerId" ' + + 'WHERE "serverBlocklist"."accountId" IN (' + blockerIdsString + ')' + + return query +} + // --------------------------------------------------------------------------- export { + buildBlockedAccountSQL, SortType, getSort, getVideoSort,