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.ts6
-rw-r--r--server/models/account/account-follow.ts30
2 files changed, 25 insertions, 11 deletions
diff --git a/server/models/account/account-follow-interface.ts b/server/models/account/account-follow-interface.ts
index 54baf45ed..21fda98ce 100644
--- a/server/models/account/account-follow-interface.ts
+++ b/server/models/account/account-follow-interface.ts
@@ -10,8 +10,9 @@ 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 = (accountId: 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 = (accountId: number[], start?: number, count?: number) => Promise< ResultList<string> >
15 export type ListAcceptedFollowerSharedInboxUrls = (accountId: number[]) => Promise< ResultList<string> >
15} 16}
16 17
17export interface AccountFollowClass { 18export interface AccountFollowClass {
@@ -21,6 +22,7 @@ export interface AccountFollowClass {
21 22
22 listAcceptedFollowerUrlsForApi: AccountFollowMethods.ListAcceptedFollowerUrlsForApi 23 listAcceptedFollowerUrlsForApi: AccountFollowMethods.ListAcceptedFollowerUrlsForApi
23 listAcceptedFollowingUrlsForApi: AccountFollowMethods.ListAcceptedFollowingUrlsForApi 24 listAcceptedFollowingUrlsForApi: AccountFollowMethods.ListAcceptedFollowingUrlsForApi
25 listAcceptedFollowerSharedInboxUrls: AccountFollowMethods.ListAcceptedFollowerSharedInboxUrls
24} 26}
25 27
26export interface AccountFollowAttributes { 28export interface AccountFollowAttributes {
diff --git a/server/models/account/account-follow.ts b/server/models/account/account-follow.ts
index f457e43e9..8a7474c9d 100644
--- a/server/models/account/account-follow.ts
+++ b/server/models/account/account-follow.ts
@@ -11,6 +11,7 @@ let listFollowingForApi: AccountFollowMethods.ListFollowingForApi
11let listFollowersForApi: AccountFollowMethods.ListFollowersForApi 11let listFollowersForApi: AccountFollowMethods.ListFollowersForApi
12let listAcceptedFollowerUrlsForApi: AccountFollowMethods.ListAcceptedFollowerUrlsForApi 12let listAcceptedFollowerUrlsForApi: AccountFollowMethods.ListAcceptedFollowerUrlsForApi
13let listAcceptedFollowingUrlsForApi: AccountFollowMethods.ListAcceptedFollowingUrlsForApi 13let listAcceptedFollowingUrlsForApi: AccountFollowMethods.ListAcceptedFollowingUrlsForApi
14let listAcceptedFollowerSharedInboxUrls: AccountFollowMethods.ListAcceptedFollowerSharedInboxUrls
14 15
15export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { 16export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
16 AccountFollow = sequelize.define<AccountFollowInstance, AccountFollowAttributes>('AccountFollow', 17 AccountFollow = sequelize.define<AccountFollowInstance, AccountFollowAttributes>('AccountFollow',
@@ -42,7 +43,8 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
42 listFollowingForApi, 43 listFollowingForApi,
43 listFollowersForApi, 44 listFollowersForApi,
44 listAcceptedFollowerUrlsForApi, 45 listAcceptedFollowerUrlsForApi,
45 listAcceptedFollowingUrlsForApi 46 listAcceptedFollowingUrlsForApi,
47 listAcceptedFollowerSharedInboxUrls
46 ] 48 ]
47 addMethodsToModel(AccountFollow, classMethods) 49 addMethodsToModel(AccountFollow, classMethods)
48 50
@@ -146,17 +148,27 @@ listFollowersForApi = function (id: number, start: number, count: number, sort:
146 }) 148 })
147} 149}
148 150
149listAcceptedFollowerUrlsForApi = function (accountId: number, start?: number, count?: number) { 151listAcceptedFollowerUrlsForApi = function (accountIds: number[], start?: number, count?: number) {
150 return createListAcceptedFollowForApiQuery('followers', accountId, start, count) 152 return createListAcceptedFollowForApiQuery('followers', accountIds, start, count)
151} 153}
152 154
153listAcceptedFollowingUrlsForApi = function (accountId: number, start?: number, count?: number) { 155listAcceptedFollowerSharedInboxUrls = function (accountIds: number[]) {
154 return createListAcceptedFollowForApiQuery('following', accountId, start, count) 156 return createListAcceptedFollowForApiQuery('followers', accountIds, undefined, undefined, 'sharedInboxUrl')
157}
158
159listAcceptedFollowingUrlsForApi = function (accountIds: number[], start?: number, count?: number) {
160 return createListAcceptedFollowForApiQuery('following', accountIds, start, count)
155} 161}
156 162
157// ------------------------------ UTILS ------------------------------ 163// ------------------------------ UTILS ------------------------------
158 164
159async function createListAcceptedFollowForApiQuery (type: 'followers' | 'following', accountId: number, start?: number, count?: number) { 165async function createListAcceptedFollowForApiQuery (
166 type: 'followers' | 'following',
167 accountIds: number[],
168 start?: number,
169 count?: number,
170 columnUrl = 'url'
171) {
160 let firstJoin: string 172 let firstJoin: string
161 let secondJoin: string 173 let secondJoin: string
162 174
@@ -168,20 +180,20 @@ async function createListAcceptedFollowForApiQuery (type: 'followers' | 'followi
168 secondJoin = 'targetAccountId' 180 secondJoin = 'targetAccountId'
169 } 181 }
170 182
171 const selections = [ '"Follows"."url" AS "url"', 'COUNT(*) AS "total"' ] 183 const selections = [ '"Follows"."' + columnUrl + '" AS "url"', 'COUNT(*) AS "total"' ]
172 const tasks: Promise<any>[] = [] 184 const tasks: Promise<any>[] = []
173 185
174 for (const selection of selections) { 186 for (const selection of selections) {
175 let query = 'SELECT ' + selection + ' FROM "Accounts" ' + 187 let query = 'SELECT ' + selection + ' FROM "Accounts" ' +
176 'INNER JOIN "AccountFollows" ON "AccountFollows"."' + firstJoin + '" = "Accounts"."id" ' + 188 'INNER JOIN "AccountFollows" ON "AccountFollows"."' + firstJoin + '" = "Accounts"."id" ' +
177 'INNER JOIN "Accounts" AS "Follows" ON "AccountFollows"."' + secondJoin + '" = "Follows"."id" ' + 189 'INNER JOIN "Accounts" AS "Follows" ON "AccountFollows"."' + secondJoin + '" = "Follows"."id" ' +
178 'WHERE "Accounts"."id" = $accountId AND "AccountFollows"."state" = \'accepted\' ' 190 'WHERE "Accounts"."id" IN ($accountIds) AND "AccountFollows"."state" = \'accepted\' '
179 191
180 if (start !== undefined) query += 'LIMIT ' + start 192 if (start !== undefined) query += 'LIMIT ' + start
181 if (count !== undefined) query += ', ' + count 193 if (count !== undefined) query += ', ' + count
182 194
183 const options = { 195 const options = {
184 bind: { accountId }, 196 bind: { accountIds: accountIds.join(',') },
185 type: Sequelize.QueryTypes.SELECT 197 type: Sequelize.QueryTypes.SELECT
186 } 198 }
187 tasks.push(AccountFollow['sequelize'].query(query, options)) 199 tasks.push(AccountFollow['sequelize'].query(query, options))