import {
- AfterDestroy,
- AllowNull,
- BelongsTo,
- Column,
- CreatedAt,
- DefaultScope,
- ForeignKey,
- HasMany,
- Is,
- Model,
- Scopes,
- Table,
- UpdatedAt
+ AllowNull, BeforeDestroy, BelongsTo, Column, CreatedAt, DefaultScope, ForeignKey, HasMany, Is, Model, Scopes, Table,
+ UpdatedAt, Default
} from 'sequelize-typescript'
import { ActivityPubActor } from '../../../shared/models/activitypub'
-import { isVideoChannelDescriptionValid, isVideoChannelNameValid } from '../../helpers/custom-validators/video-channels'
+import { VideoChannel } from '../../../shared/models/videos'
+import {
+ isVideoChannelDescriptionValid, isVideoChannelNameValid,
+ isVideoChannelSupportValid
+} from '../../helpers/custom-validators/video-channels'
+import { logger } from '../../helpers/logger'
import { sendDeleteActor } from '../../lib/activitypub/send'
import { AccountModel } from '../account/account'
import { ActorModel } from '../activitypub/actor'
name: string
@AllowNull(true)
+ @Default(null)
@Is('VideoChannelDescription', value => throwIfNotValid(value, isVideoChannelDescriptionValid, 'description'))
@Column
description: string
+ @AllowNull(true)
+ @Default(null)
+ @Is('VideoChannelSupport', value => throwIfNotValid(value, isVideoChannelSupportValid, 'support'))
+ @Column
+ support: string
+
@CreatedAt
createdAt: Date
name: 'channelId',
allowNull: false
},
- onDelete: 'CASCADE'
+ onDelete: 'CASCADE',
+ hooks: true
})
Videos: VideoModel[]
- @AfterDestroy
- static sendDeleteIfOwned (instance: VideoChannelModel) {
+ @BeforeDestroy
+ static async sendDeleteIfOwned (instance: VideoChannelModel, options) {
+ if (!instance.Actor) {
+ instance.Actor = await instance.$get('Actor', { transaction: options.transaction }) as ActorModel
+ }
+
if (instance.Actor.isOwned()) {
- return sendDeleteActor(instance.Actor, undefined)
+ logger.debug('Sending delete of actor of video channel %s.', instance.Actor.url)
+
+ return sendDeleteActor(instance.Actor, options.transaction)
}
return undefined
const query = {
offset: start,
limit: count,
- order: [ getSort(sort) ]
+ order: getSort(sort)
}
return VideoChannelModel
static listByAccount (accountId: number) {
const query = {
- order: [ getSort('createdAt') ],
+ order: getSort('createdAt'),
include: [
{
model: AccountModel,
.findById(id, options)
}
- toFormattedJSON () {
+ toFormattedJSON (): VideoChannel {
const actor = this.Actor.toFormattedJSON()
const account = {
id: this.id,
displayName: this.name,
description: this.description,
+ support: this.support,
isLocal: this.Actor.isOwned(),
createdAt: this.createdAt,
updatedAt: this.updatedAt
return Object.assign(obj, {
summary: this.description,
+ support: this.support,
attributedTo: [
{
type: 'Person' as 'Person',