aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
Diffstat (limited to 'server/models')
-rw-r--r--server/models/account/account-video-rate-interface.ts3
-rw-r--r--server/models/video/video-interface.ts3
-rw-r--r--server/models/video/video.ts48
3 files changed, 51 insertions, 3 deletions
diff --git a/server/models/account/account-video-rate-interface.ts b/server/models/account/account-video-rate-interface.ts
index 316056246..1f395bc45 100644
--- a/server/models/account/account-video-rate-interface.ts
+++ b/server/models/account/account-video-rate-interface.ts
@@ -2,6 +2,7 @@ import * as Sequelize from 'sequelize'
2import * as Promise from 'bluebird' 2import * as Promise from 'bluebird'
3 3
4import { VideoRateType } from '../../../shared/models/videos/video-rate.type' 4import { VideoRateType } from '../../../shared/models/videos/video-rate.type'
5import { AccountInstance } from './account-interface'
5 6
6export namespace AccountVideoRateMethods { 7export namespace AccountVideoRateMethods {
7 export type Load = (accountId: number, videoId: number, transaction: Sequelize.Transaction) => Promise<AccountVideoRateInstance> 8 export type Load = (accountId: number, videoId: number, transaction: Sequelize.Transaction) => Promise<AccountVideoRateInstance>
@@ -15,6 +16,8 @@ export interface AccountVideoRateAttributes {
15 type: VideoRateType 16 type: VideoRateType
16 accountId: number 17 accountId: number
17 videoId: number 18 videoId: number
19
20 Account?: AccountInstance
18} 21}
19 22
20export interface AccountVideoRateInstance 23export interface AccountVideoRateInstance
diff --git a/server/models/video/video-interface.ts b/server/models/video/video-interface.ts
index b97f163ab..89e528acf 100644
--- a/server/models/video/video-interface.ts
+++ b/server/models/video/video-interface.ts
@@ -8,6 +8,8 @@ import { TagAttributes, TagInstance } from './tag-interface'
8import { VideoChannelInstance } from './video-channel-interface' 8import { VideoChannelInstance } from './video-channel-interface'
9import { VideoFileAttributes, VideoFileInstance } from './video-file-interface' 9import { VideoFileAttributes, VideoFileInstance } from './video-file-interface'
10import { VideoShareInstance } from './video-share-interface' 10import { VideoShareInstance } from './video-share-interface'
11import { UserVideoRate } from '../../../shared/models/videos/user-video-rate.model'
12import { AccountVideoRateInstance } from '../account/account-video-rate-interface'
11 13
12export namespace VideoMethods { 14export namespace VideoMethods {
13 export type GetThumbnailName = (this: VideoInstance) => string 15 export type GetThumbnailName = (this: VideoInstance) => string
@@ -123,6 +125,7 @@ export interface VideoAttributes {
123 Tags?: TagInstance[] 125 Tags?: TagInstance[]
124 VideoFiles?: VideoFileInstance[] 126 VideoFiles?: VideoFileInstance[]
125 VideoShares?: VideoShareInstance[] 127 VideoShares?: VideoShareInstance[]
128 AccountVideoRates?: AccountVideoRateInstance[]
126} 129}
127 130
128export interface VideoInstance extends VideoClass, VideoAttributes, Sequelize.Instance<VideoAttributes> { 131export interface VideoInstance extends VideoClass, VideoAttributes, Sequelize.Instance<VideoAttributes> {
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 ]