From cf117aaafc1e9ae1ab4c388fc5d2e5ba9349efee Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 3 Jan 2018 17:25:47 +0100 Subject: Add avatar in comments --- server/helpers/custom-validators/activitypub/actor.ts | 6 ------ server/models/video/video-comment.ts | 10 ++++++---- server/tests/api/videos/video-comments.ts | 16 +++++++++++++++- 3 files changed, 21 insertions(+), 11 deletions(-) (limited to 'server') diff --git a/server/helpers/custom-validators/activitypub/actor.ts b/server/helpers/custom-validators/activitypub/actor.ts index 8820bb2a4..e1a4b5b8f 100644 --- a/server/helpers/custom-validators/activitypub/actor.ts +++ b/server/helpers/custom-validators/activitypub/actor.ts @@ -1,8 +1,6 @@ import * as validator from 'validator' import { CONSTRAINTS_FIELDS } from '../../../initializers' -import { isAccountNameValid } from '../accounts' import { exists } from '../misc' -import { isVideoChannelNameValid } from '../video-channels' import { isActivityPubUrlValid, isBaseActivityValid, setValidAttributedTo } from './misc' function isActorEndpointsObjectValid (endpointObject: any) { @@ -32,10 +30,6 @@ function isActorPreferredUsernameValid (preferredUsername: string) { return exists(preferredUsername) && validator.matches(preferredUsername, actorNameRegExp) } -function isActorNameValid (name: string) { - return isAccountNameValid(name) || isVideoChannelNameValid(name) -} - function isActorPrivateKeyValid (privateKey: string) { return exists(privateKey) && typeof privateKey === 'string' && diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts index 63675c20b..d2d8945c3 100644 --- a/server/models/video/video-comment.ts +++ b/server/models/video/video-comment.ts @@ -9,6 +9,7 @@ import { isActivityPubUrlValid } from '../../helpers/custom-validators/activityp import { CONSTRAINTS_FIELDS } from '../../initializers' import { AccountModel } from '../account/account' import { ActorModel } from '../activitypub/actor' +import { AvatarModel } from '../avatar/avatar' import { ServerModel } from '../server/server' import { getSort, throwIfNotValid } from '../utils' import { VideoModel } from './video' @@ -46,6 +47,10 @@ enum ScopeNames { { model: () => ServerModel, required: false + }, + { + model: () => AvatarModel, + required: false } ] } @@ -243,10 +248,7 @@ export class VideoCommentModel extends Model { createdAt: this.createdAt, updatedAt: this.updatedAt, totalReplies: this.get('totalReplies') || 0, - account: { - name: this.Account.name, - host: this.Account.Actor.getHost() - } + account: this.Account.toFormattedJSON() } as VideoComment } diff --git a/server/tests/api/videos/video-comments.ts b/server/tests/api/videos/video-comments.ts index 3b6578f04..604a3027d 100644 --- a/server/tests/api/videos/video-comments.ts +++ b/server/tests/api/videos/video-comments.ts @@ -3,7 +3,11 @@ import * as chai from 'chai' import 'mocha' import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model' -import { dateIsValid, flushTests, killallServers, runServer, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../utils/index' +import { testVideoImage } from '../../utils' +import { + dateIsValid, flushTests, killallServers, runServer, ServerInfo, setAccessTokensToServers, updateMyAvatar, + uploadVideo +} from '../../utils/index' import { addVideoCommentReply, addVideoCommentThread, getVideoCommentThreads, getVideoThreadComments @@ -29,6 +33,12 @@ describe('Test video comments', function () { const res = await uploadVideo(server.url, server.accessToken, {}) videoUUID = res.body.video.uuid videoId = res.body.video.id + + await updateMyAvatar({ + url: server.url, + accessToken: server.accessToken, + fixture: 'avatar.png' + }) }) it('Should not have threads on this video', async function () { @@ -70,6 +80,10 @@ describe('Test video comments', function () { expect(comment.id).to.equal(comment.threadId) expect(comment.account.name).to.equal('root') expect(comment.account.host).to.equal('localhost:9001') + + const test = await testVideoImage(server.url, 'avatar-resized', comment.account.avatar.path, '.png') + expect(test).to.equal(true) + expect(comment.totalReplies).to.equal(0) expect(dateIsValid(comment.createdAt as string)).to.be.true expect(dateIsValid(comment.updatedAt as string)).to.be.true -- cgit v1.2.3