import { AvatarModel } from '../avatar/avatar'
import { VideoPlaylistModel } from '../video/video-playlist'
import { CONSTRAINTS_FIELDS, WEBSERVER } from '../../initializers/constants'
-import { Op, Transaction, WhereOptions } from 'sequelize'
+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'
export enum ScopeNames {
SUMMARY = 'SUMMARY'
}
+export type SummaryOptions = {
+ whereActor?: WhereOptions
+ withAccountBlockerIds?: number[]
+}
+
@DefaultScope(() => ({
include: [
{
]
}))
@Scopes(() => ({
- [ ScopeNames.SUMMARY ]: (whereActor?: WhereOptions) => {
- return {
+ [ 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: [
{
required: true,
where: whereActor,
include: [
- {
- attributes: [ 'host' ],
- model: ServerModel.unscoped(),
- required: false
- },
+ 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
+ }
+ }
+ }
+ ]
+ }
+
+ return query
}
}))
@Table({
})
VideoComments: VideoCommentModel[]
+ @HasMany(() => AccountBlocklistModel, {
+ foreignKey: {
+ name: 'targetAccountId',
+ allowNull: false
+ },
+ as: 'BlockedAccounts',
+ onDelete: 'CASCADE'
+ })
+ BlockedAccounts: AccountBlocklistModel[]
+
@BeforeDestroy
static async sendDeleteIfOwned (instance: AccountModel, options) {
if (!instance.Actor) {
instance.Actor = await instance.$get('Actor', { transaction: options.transaction }) as ActorModel
}
+ await ActorFollowModel.removeFollowsOf(instance.Actor.id, options.transaction)
if (instance.isOwned()) {
return sendDeleteActor(instance.Actor, options.transaction)
}
getDisplayName () {
return this.name
}
+
+ isBlocked () {
+ return this.BlockedAccounts && this.BlockedAccounts.length !== 0
+ }
}