aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video/video.ts')
-rw-r--r--server/models/video/video.ts48
1 files changed, 45 insertions, 3 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 052fc0ae8..592fc2d59 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -47,6 +47,7 @@ import { VideoFileInstance, VideoFileModel } from './video-file-interface'
47import { VideoAttributes, VideoInstance, VideoMethods } from './video-interface' 47import { VideoAttributes, VideoInstance, VideoMethods } from './video-interface'
48import { sendDeleteVideo } from '../../lib/index' 48import { sendDeleteVideo } from '../../lib/index'
49import * as Bluebird from 'bluebird' 49import * as Bluebird from 'bluebird'
50import { activityPubCollection } from '../../helpers/activitypub'
50 51
51const Buffer = safeBuffer.Buffer 52const Buffer = safeBuffer.Buffer
52 53
@@ -359,6 +360,14 @@ function associate (models) {
359 }, 360 },
360 onDelete: 'cascade' 361 onDelete: 'cascade'
361 }) 362 })
363
364 Video.hasMany(models.AccountVideoRate, {
365 foreignKey: {
366 name: 'videoId',
367 allowNull: false
368 },
369 onDelete: 'cascade'
370 })
362} 371}
363 372
364function afterDestroy (video: VideoInstance) { 373function afterDestroy (video: VideoInstance) {
@@ -575,6 +584,25 @@ toActivityPubObject = function (this: VideoInstance) {
575 } 584 }
576 } 585 }
577 586
587 let likesObject
588 let dislikesObject
589
590 if (Array.isArray(this.AccountVideoRates)) {
591 const likes: string[] = []
592 const dislikes: string[] = []
593
594 for (const rate of this.AccountVideoRates) {
595 if (rate.type === 'like') {
596 likes.push(rate.Account.url)
597 } else if (rate.type === 'dislike') {
598 dislikes.push(rate.Account.url)
599 }
600 }
601
602 likesObject = activityPubCollection(likes)
603 dislikesObject = activityPubCollection(dislikes)
604 }
605
578 const url = [] 606 const url = []
579 for (const file of this.VideoFiles) { 607 for (const file of this.VideoFiles) {
580 url.push({ 608 url.push({
@@ -630,7 +658,9 @@ toActivityPubObject = function (this: VideoInstance) {
630 width: THUMBNAILS_SIZE.width, 658 width: THUMBNAILS_SIZE.width,
631 height: THUMBNAILS_SIZE.height 659 height: THUMBNAILS_SIZE.height
632 }, 660 },
633 url // FIXME: needed? 661 url,
662 likes: likesObject,
663 dislikes: dislikesObject
634 } 664 }
635 665
636 return videoObject 666 return videoObject
@@ -845,8 +875,12 @@ listAllAndSharedByAccountForOutbox = function (accountId: number, start: number,
845 } 875 }
846 ] 876 ]
847 }, 877 },
848 Video['sequelize'].models.Tag, 878 {
849 Video['sequelize'].models.VideoFile 879 model: Video['sequelize'].models.AccountVideoRate,
880 include: [ Video['sequelize'].models.Account ]
881 },
882 Video['sequelize'].models.VideoFile,
883 Video['sequelize'].models.Tag
850 ] 884 ]
851 } 885 }
852 886
@@ -1106,6 +1140,10 @@ loadAndPopulateAccountAndServerAndTags = function (id: number) {
1106 } 1140 }
1107 ] 1141 ]
1108 }, 1142 },
1143 {
1144 model: Video['sequelize'].models.AccountVideoRate,
1145 include: [ Video['sequelize'].models.Account ]
1146 },
1109 Video['sequelize'].models.Tag, 1147 Video['sequelize'].models.Tag,
1110 Video['sequelize'].models.VideoFile 1148 Video['sequelize'].models.VideoFile
1111 ] 1149 ]
@@ -1129,6 +1167,10 @@ loadByUUIDAndPopulateAccountAndServerAndTags = function (uuid: string) {
1129 } 1167 }
1130 ] 1168 ]
1131 }, 1169 },
1170 {
1171 model: Video['sequelize'].models.AccountVideoRate,
1172 include: [ Video['sequelize'].models.Account ]
1173 },
1132 Video['sequelize'].models.Tag, 1174 Video['sequelize'].models.Tag,
1133 Video['sequelize'].models.VideoFile 1175 Video['sequelize'].models.VideoFile
1134 ] 1176 ]