aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/utils.ts')
-rw-r--r--server/models/utils.ts22
1 files changed, 21 insertions, 1 deletions
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' ]) {
29 ] 29 ]
30 } 30 }
31 31
32 return [ [ field, direction ], lastSort ] 32 const firstSort = typeof field === 'string' ?
33 field.split('.').concat([ direction ]) :
34 [ field, direction ]
35
36 return [ firstSort, lastSort ]
33} 37}
34 38
35function getSortOnModel (model: any, value: string, lastSort: string[] = [ 'id', 'ASC' ]) { 39function getSortOnModel (model: any, value: string, lastSort: string[] = [ 'id', 'ASC' ]) {
@@ -64,9 +68,25 @@ function createSimilarityAttribute (col: string, value: string) {
64 ) 68 )
65} 69}
66 70
71function buildBlockedAccountSQL (serverAccountId: number, userAccountId?: number) {
72 const blockerIds = [ serverAccountId ]
73 if (userAccountId) blockerIds.push(userAccountId)
74
75 const blockerIdsString = blockerIds.join(', ')
76
77 const query = 'SELECT "targetAccountId" AS "id" FROM "accountBlocklist" WHERE "accountId" IN (' + blockerIdsString + ')' +
78 ' UNION ALL ' +
79 'SELECT "account"."id" AS "id" FROM account INNER JOIN "actor" ON account."actorId" = actor.id ' +
80 'INNER JOIN "serverBlocklist" ON "actor"."serverId" = "serverBlocklist"."targetServerId" ' +
81 'WHERE "serverBlocklist"."accountId" IN (' + blockerIdsString + ')'
82
83 return query
84}
85
67// --------------------------------------------------------------------------- 86// ---------------------------------------------------------------------------
68 87
69export { 88export {
89 buildBlockedAccountSQL,
70 SortType, 90 SortType,
71 getSort, 91 getSort,
72 getVideoSort, 92 getVideoSort,