]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/videos/+video-watch/comment/video-comments.component.ts
Use server error message on login
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / +video-watch / comment / video-comments.component.ts
CommitLineData
4635f59d
C
1import { Component, Input, OnInit } from '@angular/core'
2import { NotificationsService } from 'angular2-notifications'
3import { VideoCommentThreadTree } from '../../../../../../shared/models/videos/video-comment.model'
4import { AuthService } from '../../../core/auth'
5import { ComponentPagination } from '../../../shared/rest/component-pagination.model'
6import { User } from '../../../shared/users'
7import { SortField } from '../../../shared/video/sort-field.type'
8import { Video } from '../../../shared/video/video.model'
9import { VideoComment } from './video-comment.model'
10import { VideoCommentService } from './video-comment.service'
11
12@Component({
13 selector: 'my-video-comments',
14 templateUrl: './video-comments.component.html',
15 styleUrls: ['./video-comments.component.scss']
16})
17export class VideoCommentsComponent implements OnInit {
18 @Input() video: Video
19 @Input() user: User
20
21 comments: VideoComment[] = []
22 sort: SortField = '-createdAt'
23 componentPagination: ComponentPagination = {
24 currentPage: 1,
25 itemsPerPage: 25,
26 totalItems: null
27 }
28 inReplyToCommentId: number
29 threadComments: { [ id: number ]: VideoCommentThreadTree } = {}
30 threadLoading: { [ id: number ]: boolean } = {}
31
32 constructor (
33 private authService: AuthService,
34 private notificationsService: NotificationsService,
35 private videoCommentService: VideoCommentService
36 ) {}
37
38 ngOnInit () {
39 this.videoCommentService.getVideoCommentThreads(this.video.id, this.componentPagination, this.sort)
40 .subscribe(
41 res => {
42 this.comments = res.comments
43 this.componentPagination.totalItems = res.totalComments
44 },
45
46 err => this.notificationsService.error('Error', err.message)
47 )
48 }
49
50 viewReplies (comment: VideoComment) {
51 this.threadLoading[comment.id] = true
52
53 this.videoCommentService.getVideoThreadComments(this.video.id, comment.id)
54 .subscribe(
55 res => {
56 this.threadComments[comment.id] = res
57 this.threadLoading[comment.id] = false
58 },
59
60 err => this.notificationsService.error('Error', err.message)
61 )
62 }
63
64 onCommentThreadCreated (comment: VideoComment) {
65 this.comments.unshift(comment)
66 }
67
68 onWantedToReply (comment: VideoComment) {
69 this.inReplyToCommentId = comment.id
70 }
71
72 onResetReply () {
73 this.inReplyToCommentId = undefined
74 }
75
76 isUserLoggedIn () {
77 return this.authService.isLoggedIn()
78 }
79}