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.ts21
1 files changed, 18 insertions, 3 deletions
diff --git a/server/models/utils.ts b/server/models/utils.ts
index 5b4093aec..4ebd07dab 100644
--- a/server/models/utils.ts
+++ b/server/models/utils.ts
@@ -1,4 +1,5 @@
1import { Sequelize } from 'sequelize-typescript' 1import { Sequelize } from 'sequelize-typescript'
2import * as validator from 'validator'
2 3
3type SortType = { sortModel: any, sortValue: string } 4type SortType = { sortModel: any, sortValue: string }
4 5
@@ -74,13 +75,25 @@ function buildBlockedAccountSQL (serverAccountId: number, userAccountId?: number
74 75
75 const blockerIdsString = blockerIds.join(', ') 76 const blockerIdsString = blockerIds.join(', ')
76 77
77 const query = 'SELECT "targetAccountId" AS "id" FROM "accountBlocklist" WHERE "accountId" IN (' + blockerIdsString + ')' + 78 return 'SELECT "targetAccountId" AS "id" FROM "accountBlocklist" WHERE "accountId" IN (' + blockerIdsString + ')' +
78 ' UNION ALL ' + 79 ' UNION ALL ' +
79 'SELECT "account"."id" AS "id" FROM account INNER JOIN "actor" ON account."actorId" = actor.id ' + 80 '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 'INNER JOIN "serverBlocklist" ON "actor"."serverId" = "serverBlocklist"."targetServerId" ' +
81 'WHERE "serverBlocklist"."accountId" IN (' + blockerIdsString + ')' 82 'WHERE "serverBlocklist"."accountId" IN (' + blockerIdsString + ')'
83}
84
85function buildServerIdsFollowedBy (actorId: any) {
86 const actorIdNumber = parseInt(actorId + '', 10)
87
88 return '(' +
89 'SELECT "actor"."serverId" FROM "actorFollow" ' +
90 'INNER JOIN "actor" ON actor.id = "actorFollow"."targetActorId" ' +
91 'WHERE "actorFollow"."actorId" = ' + actorIdNumber +
92 ')'
93}
82 94
83 return query 95function buildWhereIdOrUUID (id: number | string) {
96 return validator.isInt('' + id) ? { id } : { uuid: id }
84} 97}
85 98
86// --------------------------------------------------------------------------- 99// ---------------------------------------------------------------------------
@@ -93,7 +106,9 @@ export {
93 getSortOnModel, 106 getSortOnModel,
94 createSimilarityAttribute, 107 createSimilarityAttribute,
95 throwIfNotValid, 108 throwIfNotValid,
96 buildTrigramSearchIndex 109 buildServerIdsFollowedBy,
110 buildTrigramSearchIndex,
111 buildWhereIdOrUUID
97} 112}
98 113
99// --------------------------------------------------------------------------- 114// ---------------------------------------------------------------------------