diff options
author | Chocobozzz <me@florianbigard.com> | 2019-02-11 11:52:34 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-02-11 11:52:34 +0100 |
commit | 88108880bbdba473cfe36ecbebc1c3c4f972e102 (patch) | |
tree | b242efb3b4f0d7e49d88f2d1f2063b5b3b0489c0 /server/models/utils.ts | |
parent | 53a94c7cfa8368da4cd248d65df8346905938f0c (diff) | |
parent | 9b712a2017e4ab3cf12cd6bd58278905520159d0 (diff) | |
download | PeerTube-88108880bbdba473cfe36ecbebc1c3c4f972e102.tar.gz PeerTube-88108880bbdba473cfe36ecbebc1c3c4f972e102.tar.zst PeerTube-88108880bbdba473cfe36ecbebc1c3c4f972e102.zip |
Merge branch 'develop' into pr/1217
Diffstat (limited to 'server/models/utils.ts')
-rw-r--r-- | server/models/utils.ts | 22 |
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 | ||
35 | function getSortOnModel (model: any, value: string, lastSort: string[] = [ 'id', 'ASC' ]) { | 39 | function 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 | ||
71 | function 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 | ||
69 | export { | 88 | export { |
89 | buildBlockedAccountSQL, | ||
70 | SortType, | 90 | SortType, |
71 | getSort, | 91 | getSort, |
72 | getVideoSort, | 92 | getVideoSort, |