]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/videos/+video-watch/comment/video-comment.component.ts
Add ability to delete comments
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / +video-watch / comment / video-comment.component.ts
1 import { Component, EventEmitter, Input, Output } from '@angular/core'
2 import { Account as AccountInterface } from '../../../../../../shared/models/actors'
3 import { UserRight } from '../../../../../../shared/models/users'
4 import { VideoCommentThreadTree } from '../../../../../../shared/models/videos/video-comment.model'
5 import { AuthService } from '../../../core/auth'
6 import { Account } from '../../../shared/account/account.model'
7 import { Video } from '../../../shared/video/video.model'
8 import { VideoComment } from './video-comment.model'
9
10 @Component({
11 selector: 'my-video-comment',
12 templateUrl: './video-comment.component.html',
13 styleUrls: ['./video-comment.component.scss']
14 })
15 export class VideoCommentComponent {
16 @Input() video: Video
17 @Input() comment: VideoComment
18 @Input() commentTree: VideoCommentThreadTree
19 @Input() inReplyToCommentId: number
20
21 @Output() wantedToDelete = new EventEmitter<VideoComment>()
22 @Output() wantedToReply = new EventEmitter<VideoComment>()
23 @Output() threadCreated = new EventEmitter<VideoCommentThreadTree>()
24 @Output() resetReply = new EventEmitter()
25
26 constructor (private authService: AuthService) {}
27
28 get user () {
29 return this.authService.getUser()
30 }
31
32 onCommentReplyCreated (createdComment: VideoComment) {
33 if (!this.commentTree) {
34 this.commentTree = {
35 comment: this.comment,
36 children: []
37 }
38
39 this.threadCreated.emit(this.commentTree)
40 }
41
42 this.commentTree.children.push({
43 comment: createdComment,
44 children: []
45 })
46 this.resetReply.emit()
47 }
48
49 onWantToReply (comment?: VideoComment) {
50 this.wantedToReply.emit(comment || this.comment)
51 }
52
53 onWantToDelete (comment?: VideoComment) {
54 this.wantedToDelete.emit(comment || this.comment)
55 }
56
57 isUserLoggedIn () {
58 return this.authService.isLoggedIn()
59 }
60
61 onResetReply () {
62 this.resetReply.emit()
63 }
64
65 getAvatarUrl (account: AccountInterface) {
66 return Account.GET_ACCOUNT_AVATAR_URL(account)
67 }
68
69 isRemovableByUser () {
70 return this.isUserLoggedIn() &&
71 (
72 this.user.account.id === this.comment.account.id ||
73 this.user.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT)
74 )
75 }
76 }