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