]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/utils.ts
Don't call watching endpoint if history is disabled
[github/Chocobozzz/PeerTube.git] / server / models / utils.ts
index e0bf091ad0539a7e981d6d9216d5f0ace9282b89..5b4093aec40d7b2aee217810c437da749b167afd 100644 (file)
@@ -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,