+import { AvatarModel } from '../avatar/avatar'
+import { VideoPlaylistModel } from '../video/video-playlist'
+import { CONSTRAINTS_FIELDS, SERVER_ACTOR_NAME, WEBSERVER } from '../../initializers/constants'
+import { FindOptions, IncludeOptions, Op, Transaction, WhereOptions } from 'sequelize'
+import { AccountBlocklistModel } from './account-blocklist'
+import { ServerBlocklistModel } from '../server/server-blocklist'
+import { ActorFollowModel } from '../activitypub/actor-follow'
+import { MAccountActor, MAccountAP, MAccountDefault, MAccountFormattable, MAccountSummaryFormattable } from '../../typings/models'
+import * as Bluebird from 'bluebird'
+import { ModelCache } from '@server/models/model-cache'
+
+export enum ScopeNames {
+ SUMMARY = 'SUMMARY'
+}
+
+export type SummaryOptions = {
+ whereActor?: WhereOptions
+ withAccountBlockerIds?: number[]
+}
+
+@DefaultScope(() => ({
+ include: [
+ {
+ model: ActorModel, // Default scope includes avatar and server
+ required: true
+ }
+ ]
+}))
+@Scopes(() => ({
+ [ScopeNames.SUMMARY]: (options: SummaryOptions = {}) => {
+ const whereActor = options.whereActor || undefined
+
+ const serverInclude: IncludeOptions = {
+ attributes: [ 'host' ],
+ model: ServerModel.unscoped(),
+ required: false
+ }
+
+ const query: FindOptions = {
+ attributes: [ 'id', 'name' ],
+ include: [
+ {
+ attributes: [ 'id', 'preferredUsername', 'url', 'serverId', 'avatarId' ],
+ model: ActorModel.unscoped(),
+ required: true,
+ where: whereActor,
+ include: [
+ serverInclude,
+
+ {
+ model: AvatarModel.unscoped(),
+ required: false
+ }
+ ]
+ }
+ ]
+ }
+
+ if (options.withAccountBlockerIds) {
+ query.include.push({
+ attributes: [ 'id' ],
+ model: AccountBlocklistModel.unscoped(),
+ as: 'BlockedAccounts',
+ required: false,
+ where: {
+ accountId: {
+ [Op.in]: options.withAccountBlockerIds
+ }
+ }
+ })
+
+ serverInclude.include = [
+ {
+ attributes: [ 'id' ],
+ model: ServerBlocklistModel.unscoped(),
+ required: false,
+ where: {
+ accountId: {
+ [Op.in]: options.withAccountBlockerIds
+ }
+ }
+ }
+ ]
+ }