let listFollowersForApi: AccountFollowMethods.ListFollowersForApi
let listAcceptedFollowerUrlsForApi: AccountFollowMethods.ListAcceptedFollowerUrlsForApi
let listAcceptedFollowingUrlsForApi: AccountFollowMethods.ListAcceptedFollowingUrlsForApi
+let listAcceptedFollowerSharedInboxUrls: AccountFollowMethods.ListAcceptedFollowerSharedInboxUrls
export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
AccountFollow = sequelize.define<AccountFollowInstance, AccountFollowAttributes>('AccountFollow',
listFollowingForApi,
listFollowersForApi,
listAcceptedFollowerUrlsForApi,
- listAcceptedFollowingUrlsForApi
+ listAcceptedFollowingUrlsForApi,
+ listAcceptedFollowerSharedInboxUrls
]
addMethodsToModel(AccountFollow, classMethods)
model: AccountFollow['sequelize'].models.Account,
as: 'AccountFollowing',
required: true,
- include: [ AccountFollow['sequelize'].models.Pod ]
+ include: [ AccountFollow['sequelize'].models.Server ]
}
]
}
model: AccountFollow[ 'sequelize' ].models.Account,
required: true,
as: 'AccountFollower',
- include: [ AccountFollow['sequelize'].models.Pod ]
+ include: [ AccountFollow['sequelize'].models.Server ]
},
{
model: AccountFollow['sequelize'].models.Account,
})
}
-listAcceptedFollowerUrlsForApi = function (id: number, start: number, count?: number) {
- return createListAcceptedFollowForApiQuery('followers', id, start, count)
+listAcceptedFollowerUrlsForApi = function (accountIds: number[], start?: number, count?: number) {
+ return createListAcceptedFollowForApiQuery('followers', accountIds, start, count)
}
-listAcceptedFollowingUrlsForApi = function (id: number, start: number, count?: number) {
- return createListAcceptedFollowForApiQuery('following', id, start, count)
+listAcceptedFollowerSharedInboxUrls = function (accountIds: number[]) {
+ return createListAcceptedFollowForApiQuery('followers', accountIds, undefined, undefined, 'sharedInboxUrl')
+}
+
+listAcceptedFollowingUrlsForApi = function (accountIds: number[], start?: number, count?: number) {
+ return createListAcceptedFollowForApiQuery('following', accountIds, start, count)
}
// ------------------------------ UTILS ------------------------------
-async function createListAcceptedFollowForApiQuery (type: 'followers' | 'following', id: number, start: number, count?: number) {
+async function createListAcceptedFollowForApiQuery (
+ type: 'followers' | 'following',
+ accountIds: number[],
+ start?: number,
+ count?: number,
+ columnUrl = 'url'
+) {
let firstJoin: string
let secondJoin: string
secondJoin = 'targetAccountId'
}
- const selections = [ '"Followers"."url" AS "url"', 'COUNT(*) AS "total"' ]
+ const selections = [ '"Follows"."' + columnUrl + '" AS "url"', 'COUNT(*) AS "total"' ]
const tasks: Promise<any>[] = []
for (const selection of selections) {
- let query = 'SELECT ' + selection + ' FROM "Account" ' +
- 'INNER JOIN "AccountFollow" ON "AccountFollow"."' + firstJoin + '" = "Account"."id" ' +
- 'INNER JOIN "Account" AS "Follows" ON "Followers"."id" = "Follows"."' + secondJoin + '" ' +
- 'WHERE "Account"."id" = $id AND "AccountFollow"."state" = \'accepted\' ' +
- 'LIMIT ' + start
+ let query = 'SELECT ' + selection + ' FROM "Accounts" ' +
+ 'INNER JOIN "AccountFollows" ON "AccountFollows"."' + firstJoin + '" = "Accounts"."id" ' +
+ 'INNER JOIN "Accounts" AS "Follows" ON "AccountFollows"."' + secondJoin + '" = "Follows"."id" ' +
+ 'WHERE "Accounts"."id" = ANY ($accountIds) AND "AccountFollows"."state" = \'accepted\' '
+ if (start !== undefined) query += 'LIMIT ' + start
if (count !== undefined) query += ', ' + count
const options = {
- bind: { id },
+ bind: { accountIds },
type: Sequelize.QueryTypes.SELECT
}
tasks.push(AccountFollow['sequelize'].query(query, options))