+ .then(res => res.map(r => r.Actor))
+ }
+
+ static loadActorsWhoSharedVideosOf (actorOwnerId: number, t: Transaction): Bluebird<ActorModel[]> {
+ const query = {
+ attributes: [],
+ include: [
+ {
+ model: ActorModel,
+ required: true
+ },
+ {
+ attributes: [],
+ model: VideoModel,
+ required: true,
+ include: [
+ {
+ attributes: [],
+ model: VideoChannelModel.unscoped(),
+ required: true,
+ include: [
+ {
+ attributes: [],
+ model: AccountModel.unscoped(),
+ required: true,
+ where: {
+ actorId: actorOwnerId
+ }
+ }
+ ]
+ }
+ ]
+ }
+ ],
+ transaction: t
+ }
+
+ return VideoShareModel.scope(ScopeNames.FULL).findAll(query)
+ .then(res => res.map(r => r.Actor))
+ }
+
+ static loadActorsByVideoChannel (videoChannelId: number, t: Transaction): Bluebird<ActorModel[]> {
+ 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))
+ }
+
+ static listAndCountByVideoId (videoId: number, start: number, count: number, t?: Transaction) {
+ const query = {
+ offset: start,
+ limit: count,
+ where: {
+ videoId
+ },
+ transaction: t
+ }
+
+ return VideoShareModel.findAndCountAll(query)
+ }
+
+ static cleanOldSharesOf (videoId: number, beforeUpdatedAt: Date) {
+ const query = {
+ where: {
+ updatedAt: {
+ [Op.lt]: beforeUpdatedAt
+ },
+ videoId,
+ actorId: {
+ [Op.notIn]: buildLocalActorIdsIn()
+ }
+ }
+ }
+
+ return VideoShareModel.destroy(query)