X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fvideo-share.ts;h=602cc69b90f1d09b9480e7e1c935268aada22a2b;hb=a4f99a766bd07851a37dd7ff8fed7acc2a3ef021;hp=48ba68a4aabfbdc6b77918221d8fa9a6768fd6dc;hpb=4ba3b8ea1be85d95a508ac479f26b96ceea15971;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/video-share.ts b/server/models/video/video-share.ts index 48ba68a4a..602cc69b9 100644 --- a/server/models/video/video-share.ts +++ b/server/models/video/video-share.ts @@ -1,4 +1,5 @@ import * as Sequelize from 'sequelize' +import * as Bluebird from 'bluebird' import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' import { CONSTRAINTS_FIELDS } from '../../initializers' @@ -97,6 +98,15 @@ export class VideoShareModel extends Model { }) } + static loadByUrl (url: string, t: Sequelize.Transaction) { + return VideoShareModel.scope(ScopeNames.WITH_ACTOR).findOne({ + where: { + url + }, + transaction: t + }) + } + static loadActorsByShare (videoId: number, t: Sequelize.Transaction) { const query = { where: { @@ -115,7 +125,7 @@ export class VideoShareModel extends Model { .then(res => res.map(r => r.Actor)) } - static loadActorsByVideoOwner (actorOwnerId: number, t: Sequelize.Transaction) { + static loadActorsByVideoOwner (actorOwnerId: number, t: Sequelize.Transaction): Bluebird { const query = { attributes: [], include: [ @@ -152,4 +162,29 @@ export class VideoShareModel extends Model { return VideoShareModel.scope(ScopeNames.FULL).findAll(query) .then(res => res.map(r => r.Actor)) } + + static loadActorsByVideoChannel (videoChannelId: number, t: Sequelize.Transaction): Bluebird { + const query = { + attributes: [], + include: [ + { + model: ActorModel, + required: true + }, + { + attributes: [], + model: VideoModel, + required: true, + where: { + channelId: videoChannelId + } + } + ], + transaction: t + } + + return VideoShareModel.scope(ScopeNames.FULL) + .findAll(query) + .then(res => res.map(r => r.Actor)) + } }