diff options
author | Chocobozzz <me@florianbigard.com> | 2018-01-29 10:52:19 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-01-29 10:52:19 +0100 |
commit | 46531a0abdd5c860a1a8cdb4b636b9c55bfb115b (patch) | |
tree | 9cc1aaa565985c04b12bf985e9c6f21aebf42ff3 /server/models | |
parent | c88593f72f1097cc34a091b4cb4b6d6e214d1e9f (diff) | |
download | PeerTube-46531a0abdd5c860a1a8cdb4b636b9c55bfb115b.tar.gz PeerTube-46531a0abdd5c860a1a8cdb4b636b9c55bfb115b.tar.zst PeerTube-46531a0abdd5c860a1a8cdb4b636b9c55bfb115b.zip |
Add id to likes/dislikes/comments/shares collections
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/video/video.ts | 65 |
1 files changed, 49 insertions, 16 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 8e1acdd44..4e572a16b 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -58,6 +58,12 @@ import { | |||
58 | VIDEO_LICENCES, | 58 | VIDEO_LICENCES, |
59 | VIDEO_PRIVACIES | 59 | VIDEO_PRIVACIES |
60 | } from '../../initializers' | 60 | } from '../../initializers' |
61 | import { | ||
62 | getVideoCommentsActivityPubUrl, | ||
63 | getVideoDislikesActivityPubUrl, | ||
64 | getVideoLikesActivityPubUrl, | ||
65 | getVideoSharesActivityPubUrl | ||
66 | } from '../../lib/activitypub' | ||
61 | import { sendDeleteVideo } from '../../lib/activitypub/send' | 67 | import { sendDeleteVideo } from '../../lib/activitypub/send' |
62 | import { AccountModel } from '../account/account' | 68 | import { AccountModel } from '../account/account' |
63 | import { AccountVideoRateModel } from '../account/account-video-rate' | 69 | import { AccountVideoRateModel } from '../account/account-video-rate' |
@@ -958,30 +964,19 @@ export class VideoModel extends Model<VideoModel> { | |||
958 | } | 964 | } |
959 | } | 965 | } |
960 | 966 | ||
961 | likesObject = activityPubCollection(likes) | 967 | const res = this.toRatesActivityPubObjects() |
962 | dislikesObject = activityPubCollection(dislikes) | 968 | likesObject = res.likesObject |
969 | dislikesObject = res.dislikesObject | ||
963 | } | 970 | } |
964 | 971 | ||
965 | let sharesObject | 972 | let sharesObject |
966 | if (Array.isArray(this.VideoShares)) { | 973 | if (Array.isArray(this.VideoShares)) { |
967 | const shares: string[] = [] | 974 | sharesObject = this.toAnnouncesActivityPubObject() |
968 | |||
969 | for (const videoShare of this.VideoShares) { | ||
970 | shares.push(videoShare.url) | ||
971 | } | ||
972 | |||
973 | sharesObject = activityPubCollection(shares) | ||
974 | } | 975 | } |
975 | 976 | ||
976 | let commentsObject | 977 | let commentsObject |
977 | if (Array.isArray(this.VideoComments)) { | 978 | if (Array.isArray(this.VideoComments)) { |
978 | const comments: string[] = [] | 979 | commentsObject = this.toCommentsActivityPubObject() |
979 | |||
980 | for (const videoComment of this.VideoComments) { | ||
981 | comments.push(videoComment.url) | ||
982 | } | ||
983 | |||
984 | commentsObject = activityPubCollection(comments) | ||
985 | } | 980 | } |
986 | 981 | ||
987 | const url = [] | 982 | const url = [] |
@@ -1058,6 +1053,44 @@ export class VideoModel extends Model<VideoModel> { | |||
1058 | } | 1053 | } |
1059 | } | 1054 | } |
1060 | 1055 | ||
1056 | toAnnouncesActivityPubObject () { | ||
1057 | const shares: string[] = [] | ||
1058 | |||
1059 | for (const videoShare of this.VideoShares) { | ||
1060 | shares.push(videoShare.url) | ||
1061 | } | ||
1062 | |||
1063 | return activityPubCollection(getVideoSharesActivityPubUrl(this), shares) | ||
1064 | } | ||
1065 | |||
1066 | toCommentsActivityPubObject () { | ||
1067 | const comments: string[] = [] | ||
1068 | |||
1069 | for (const videoComment of this.VideoComments) { | ||
1070 | comments.push(videoComment.url) | ||
1071 | } | ||
1072 | |||
1073 | return activityPubCollection(getVideoCommentsActivityPubUrl(this), comments) | ||
1074 | } | ||
1075 | |||
1076 | toRatesActivityPubObjects () { | ||
1077 | const likes: string[] = [] | ||
1078 | const dislikes: string[] = [] | ||
1079 | |||
1080 | for (const rate of this.AccountVideoRates) { | ||
1081 | if (rate.type === 'like') { | ||
1082 | likes.push(rate.Account.Actor.url) | ||
1083 | } else if (rate.type === 'dislike') { | ||
1084 | dislikes.push(rate.Account.Actor.url) | ||
1085 | } | ||
1086 | } | ||
1087 | |||
1088 | const likesObject = activityPubCollection(getVideoLikesActivityPubUrl(this), likes) | ||
1089 | const dislikesObject = activityPubCollection(getVideoDislikesActivityPubUrl(this), dislikes) | ||
1090 | |||
1091 | return { likesObject, dislikesObject } | ||
1092 | } | ||
1093 | |||
1061 | getTruncatedDescription () { | 1094 | getTruncatedDescription () { |
1062 | if (!this.description) return null | 1095 | if (!this.description) return null |
1063 | 1096 | ||