]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video-share.ts
Add notification on new instance follower (server side)
[github/Chocobozzz/PeerTube.git] / server / models / video / video-share.ts
index 15dba3f7d91bd8a0495581c561d748f6eece36d7..39908156447aa672afbdb4faf91f7cd3e357dd13 100644 (file)
@@ -88,7 +88,7 @@ export class VideoShareModel extends Model<VideoShareModel> {
   })
   Video: VideoModel
 
-  static load (actorId: number, videoId: number, t: Sequelize.Transaction) {
+  static load (actorId: number, videoId: number, t?: Sequelize.Transaction) {
     return VideoShareModel.scope(ScopeNames.WITH_ACTOR).findOne({
       where: {
         actorId,
@@ -125,7 +125,7 @@ export class VideoShareModel extends Model<VideoShareModel> {
       .then(res => res.map(r => r.Actor))
   }
 
-  static loadActorsByVideoOwner (actorOwnerId: number, t: Sequelize.Transaction): Bluebird<ActorModel[]> {
+  static loadActorsWhoSharedVideosOf (actorOwnerId: number, t: Sequelize.Transaction): Bluebird<ActorModel[]> {
     const query = {
       attributes: [],
       include: [
@@ -190,8 +190,8 @@ export class VideoShareModel extends Model<VideoShareModel> {
 
   static listAndCountByVideoId (videoId: number, start: number, count: number, t?: Sequelize.Transaction) {
     const query = {
-      start,
-      count,
+      offset: start,
+      limit: count,
       where: {
         videoId
       },
@@ -200,4 +200,17 @@ export class VideoShareModel extends Model<VideoShareModel> {
 
     return VideoShareModel.findAndCountAll(query)
   }
+
+  static cleanOldSharesOf (videoId: number, beforeUpdatedAt: Date) {
+    const query = {
+      where: {
+        updatedAt: {
+          [Sequelize.Op.lt]: beforeUpdatedAt
+        },
+        videoId
+      }
+    }
+
+    return VideoShareModel.destroy(query)
+  }
 }