aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/account
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/account')
-rw-r--r--server/models/account/account-follow-interface.ts4
-rw-r--r--server/models/account/account-follow.ts24
-rw-r--r--server/models/account/account.ts1
3 files changed, 15 insertions, 14 deletions
diff --git a/server/models/account/account-follow-interface.ts b/server/models/account/account-follow-interface.ts
index 413dad190..54baf45ed 100644
--- a/server/models/account/account-follow-interface.ts
+++ b/server/models/account/account-follow-interface.ts
@@ -10,8 +10,8 @@ export namespace AccountFollowMethods {
10 export type ListFollowingForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList<AccountInstance> > 10 export type ListFollowingForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList<AccountInstance> >
11 export type ListFollowersForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList<AccountInstance> > 11 export type ListFollowersForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList<AccountInstance> >
12 12
13 export type ListAcceptedFollowerUrlsForApi = (id: number, start: number, count?: number) => Promise< ResultList<string> > 13 export type ListAcceptedFollowerUrlsForApi = (id: number, start?: number, count?: number) => Promise< ResultList<string> >
14 export type ListAcceptedFollowingUrlsForApi = (id: number, start: number, count?: number) => Promise< ResultList<string> > 14 export type ListAcceptedFollowingUrlsForApi = (id: number, start?: number, count?: number) => Promise< ResultList<string> >
15} 15}
16 16
17export interface AccountFollowClass { 17export interface AccountFollowClass {
diff --git a/server/models/account/account-follow.ts b/server/models/account/account-follow.ts
index c940d7cd4..f457e43e9 100644
--- a/server/models/account/account-follow.ts
+++ b/server/models/account/account-follow.ts
@@ -146,17 +146,17 @@ listFollowersForApi = function (id: number, start: number, count: number, sort:
146 }) 146 })
147} 147}
148 148
149listAcceptedFollowerUrlsForApi = function (id: number, start: number, count?: number) { 149listAcceptedFollowerUrlsForApi = function (accountId: number, start?: number, count?: number) {
150 return createListAcceptedFollowForApiQuery('followers', id, start, count) 150 return createListAcceptedFollowForApiQuery('followers', accountId, start, count)
151} 151}
152 152
153listAcceptedFollowingUrlsForApi = function (id: number, start: number, count?: number) { 153listAcceptedFollowingUrlsForApi = function (accountId: number, start?: number, count?: number) {
154 return createListAcceptedFollowForApiQuery('following', id, start, count) 154 return createListAcceptedFollowForApiQuery('following', accountId, start, count)
155} 155}
156 156
157// ------------------------------ UTILS ------------------------------ 157// ------------------------------ UTILS ------------------------------
158 158
159async function createListAcceptedFollowForApiQuery (type: 'followers' | 'following', id: number, start: number, count?: number) { 159async function createListAcceptedFollowForApiQuery (type: 'followers' | 'following', accountId: number, start?: number, count?: number) {
160 let firstJoin: string 160 let firstJoin: string
161 let secondJoin: string 161 let secondJoin: string
162 162
@@ -168,20 +168,20 @@ async function createListAcceptedFollowForApiQuery (type: 'followers' | 'followi
168 secondJoin = 'targetAccountId' 168 secondJoin = 'targetAccountId'
169 } 169 }
170 170
171 const selections = [ '"Followers"."url" AS "url"', 'COUNT(*) AS "total"' ] 171 const selections = [ '"Follows"."url" AS "url"', 'COUNT(*) AS "total"' ]
172 const tasks: Promise<any>[] = [] 172 const tasks: Promise<any>[] = []
173 173
174 for (const selection of selections) { 174 for (const selection of selections) {
175 let query = 'SELECT ' + selection + ' FROM "Account" ' + 175 let query = 'SELECT ' + selection + ' FROM "Accounts" ' +
176 'INNER JOIN "AccountFollow" ON "AccountFollow"."' + firstJoin + '" = "Account"."id" ' + 176 'INNER JOIN "AccountFollows" ON "AccountFollows"."' + firstJoin + '" = "Accounts"."id" ' +
177 'INNER JOIN "Account" AS "Follows" ON "Followers"."id" = "Follows"."' + secondJoin + '" ' + 177 'INNER JOIN "Accounts" AS "Follows" ON "AccountFollows"."' + secondJoin + '" = "Follows"."id" ' +
178 'WHERE "Account"."id" = $id AND "AccountFollow"."state" = \'accepted\' ' + 178 'WHERE "Accounts"."id" = $accountId AND "AccountFollows"."state" = \'accepted\' '
179 'LIMIT ' + start
180 179
180 if (start !== undefined) query += 'LIMIT ' + start
181 if (count !== undefined) query += ', ' + count 181 if (count !== undefined) query += ', ' + count
182 182
183 const options = { 183 const options = {
184 bind: { id }, 184 bind: { accountId },
185 type: Sequelize.QueryTypes.SELECT 185 type: Sequelize.QueryTypes.SELECT
186 } 186 }
187 tasks.push(AccountFollow['sequelize'].query(query, options)) 187 tasks.push(AccountFollow['sequelize'].query(query, options))
diff --git a/server/models/account/account.ts b/server/models/account/account.ts
index 464105261..84461a2eb 100644
--- a/server/models/account/account.ts
+++ b/server/models/account/account.ts
@@ -263,6 +263,7 @@ function associate (models) {
263 name: 'targetAccountId', 263 name: 'targetAccountId',
264 allowNull: false 264 allowNull: false
265 }, 265 },
266 as: 'followers',
266 onDelete: 'cascade' 267 onDelete: 'cascade'
267 }) 268 })
268} 269}