From 46531a0abdd5c860a1a8cdb4b636b9c55bfb115b Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 29 Jan 2018 10:52:19 +0100 Subject: Add id to likes/dislikes/comments/shares collections --- server/models/video/video.ts | 65 +++++++++++++++++++++++++++++++++----------- 1 file changed, 49 insertions(+), 16 deletions(-) (limited to 'server/models') 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 { VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../initializers' +import { + getVideoCommentsActivityPubUrl, + getVideoDislikesActivityPubUrl, + getVideoLikesActivityPubUrl, + getVideoSharesActivityPubUrl +} from '../../lib/activitypub' import { sendDeleteVideo } from '../../lib/activitypub/send' import { AccountModel } from '../account/account' import { AccountVideoRateModel } from '../account/account-video-rate' @@ -958,30 +964,19 @@ export class VideoModel extends Model { } } - likesObject = activityPubCollection(likes) - dislikesObject = activityPubCollection(dislikes) + const res = this.toRatesActivityPubObjects() + likesObject = res.likesObject + dislikesObject = res.dislikesObject } let sharesObject if (Array.isArray(this.VideoShares)) { - const shares: string[] = [] - - for (const videoShare of this.VideoShares) { - shares.push(videoShare.url) - } - - sharesObject = activityPubCollection(shares) + sharesObject = this.toAnnouncesActivityPubObject() } let commentsObject if (Array.isArray(this.VideoComments)) { - const comments: string[] = [] - - for (const videoComment of this.VideoComments) { - comments.push(videoComment.url) - } - - commentsObject = activityPubCollection(comments) + commentsObject = this.toCommentsActivityPubObject() } const url = [] @@ -1058,6 +1053,44 @@ export class VideoModel extends Model { } } + toAnnouncesActivityPubObject () { + const shares: string[] = [] + + for (const videoShare of this.VideoShares) { + shares.push(videoShare.url) + } + + return activityPubCollection(getVideoSharesActivityPubUrl(this), shares) + } + + toCommentsActivityPubObject () { + const comments: string[] = [] + + for (const videoComment of this.VideoComments) { + comments.push(videoComment.url) + } + + return activityPubCollection(getVideoCommentsActivityPubUrl(this), comments) + } + + toRatesActivityPubObjects () { + const likes: string[] = [] + const dislikes: string[] = [] + + for (const rate of this.AccountVideoRates) { + if (rate.type === 'like') { + likes.push(rate.Account.Actor.url) + } else if (rate.type === 'dislike') { + dislikes.push(rate.Account.Actor.url) + } + } + + const likesObject = activityPubCollection(getVideoLikesActivityPubUrl(this), likes) + const dislikesObject = activityPubCollection(getVideoDislikesActivityPubUrl(this), dislikes) + + return { likesObject, dislikesObject } + } + getTruncatedDescription () { if (!this.description) return null -- cgit v1.2.3