+function buildBlockedAccountSQL (serverAccountId: number, userAccountId?: number) {
+ const blockerIds = [ serverAccountId ]
+ if (userAccountId) blockerIds.push(userAccountId)
+
+ const blockerIdsString = blockerIds.join(', ')
+
+ return '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 + ')'
+}
+
+function buildServerIdsFollowedBy (actorId: any) {
+ const actorIdNumber = parseInt(actorId + '', 10)
+
+ return '(' +
+ 'SELECT "actor"."serverId" FROM "actorFollow" ' +
+ 'INNER JOIN "actor" ON actor.id = "actorFollow"."targetActorId" ' +
+ 'WHERE "actorFollow"."actorId" = ' + actorIdNumber +
+ ')'
+}
+
+function buildWhereIdOrUUID (id: number | string) {
+ return validator.isInt('' + id) ? { id } : { uuid: id }
+}
+
+function parseAggregateResult (result: any) {
+ if (!result) return 0
+
+ const total = parseInt(result + '', 10)
+ if (isNaN(total)) return 0
+
+ return total
+}
+