1 import * as Sequelize from 'sequelize'
2 import { BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript'
3 import { AccountModel } from '../account/account'
4 import { ActorModel } from '../activitypub/actor'
5 import { VideoModel } from './video'
6 import { VideoChannelModel } from './video-channel'
10 WITH_ACTOR = 'WITH_ACTOR'
17 model: () => ActorModel,
21 model: () => VideoModel,
26 [ScopeNames.WITH_ACTOR]: {
29 model: () => ActorModel,
36 tableName: 'videoShare',
46 export class VideoShareModel extends Model<VideoShareModel> {
53 @ForeignKey(() => ActorModel)
57 @BelongsTo(() => ActorModel, {
65 @ForeignKey(() => VideoModel)
69 @BelongsTo(() => VideoModel, {
77 static load (actorId: number, videoId: number, t: Sequelize.Transaction) {
78 return VideoShareModel.scope(ScopeNames.WITH_ACTOR).findOne({
87 static loadActorsByShare (videoId: number, t: Sequelize.Transaction) {
101 return VideoShareModel.scope(ScopeNames.FULL).findAll(query)
102 .then(res => res.map(r => r.Actor))
105 static loadActorsByVideoOwner (actorOwnerId: number, t: Sequelize.Transaction) {
120 model: VideoChannelModel.unscoped(),
125 model: AccountModel.unscoped(),
128 actorId: actorOwnerId
139 return VideoShareModel.scope(ScopeNames.FULL).findAll(query)
140 .then(res => res.map(r => r.Actor))