diff options
author | Chocobozzz <me@florianbigard.com> | 2018-01-04 11:19:16 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-01-04 11:19:16 +0100 |
commit | 4cb6d4578893db310297d7e118ce2fb7ecb952a3 (patch) | |
tree | a89a2e2062ba7bb91e922f07a7950ee51e090ccf /client/src/app/videos/+video-watch/comment/video-comments.component.ts | |
parent | cf117aaafc1e9ae1ab4c388fc5d2e5ba9349efee (diff) | |
download | PeerTube-4cb6d4578893db310297d7e118ce2fb7ecb952a3.tar.gz PeerTube-4cb6d4578893db310297d7e118ce2fb7ecb952a3.tar.zst PeerTube-4cb6d4578893db310297d7e118ce2fb7ecb952a3.zip |
Add ability to delete comments
Diffstat (limited to 'client/src/app/videos/+video-watch/comment/video-comments.component.ts')
-rw-r--r-- | client/src/app/videos/+video-watch/comment/video-comments.component.ts | 57 |
1 files changed, 54 insertions, 3 deletions
diff --git a/client/src/app/videos/+video-watch/comment/video-comments.component.ts b/client/src/app/videos/+video-watch/comment/video-comments.component.ts index 1230725c1..030dee9af 100644 --- a/client/src/app/videos/+video-watch/comment/video-comments.component.ts +++ b/client/src/app/videos/+video-watch/comment/video-comments.component.ts | |||
@@ -1,6 +1,7 @@ | |||
1 | import { Component, Input, OnInit } from '@angular/core' | 1 | import { Component, Input, OnInit } from '@angular/core' |
2 | import { ConfirmService } from '@app/core' | ||
2 | import { NotificationsService } from 'angular2-notifications' | 3 | import { NotificationsService } from 'angular2-notifications' |
3 | import { VideoCommentThreadTree } from '../../../../../../shared/models/videos/video-comment.model' | 4 | import { VideoComment as VideoCommentInterface, VideoCommentThreadTree } from '../../../../../../shared/models/videos/video-comment.model' |
4 | import { AuthService } from '../../../core/auth' | 5 | import { AuthService } from '../../../core/auth' |
5 | import { ComponentPagination } from '../../../shared/rest/component-pagination.model' | 6 | import { ComponentPagination } from '../../../shared/rest/component-pagination.model' |
6 | import { User } from '../../../shared/users' | 7 | import { User } from '../../../shared/users' |
@@ -32,6 +33,7 @@ export class VideoCommentsComponent implements OnInit { | |||
32 | constructor ( | 33 | constructor ( |
33 | private authService: AuthService, | 34 | private authService: AuthService, |
34 | private notificationsService: NotificationsService, | 35 | private notificationsService: NotificationsService, |
36 | private confirmService: ConfirmService, | ||
35 | private videoCommentService: VideoCommentService | 37 | private videoCommentService: VideoCommentService |
36 | ) {} | 38 | ) {} |
37 | 39 | ||
@@ -41,7 +43,7 @@ export class VideoCommentsComponent implements OnInit { | |||
41 | } | 43 | } |
42 | } | 44 | } |
43 | 45 | ||
44 | viewReplies (comment: VideoComment) { | 46 | viewReplies (comment: VideoCommentInterface) { |
45 | this.threadLoading[comment.id] = true | 47 | this.threadLoading[comment.id] = true |
46 | 48 | ||
47 | this.videoCommentService.getVideoThreadComments(this.video.id, comment.id) | 49 | this.videoCommentService.getVideoThreadComments(this.video.id, comment.id) |
@@ -79,6 +81,44 @@ export class VideoCommentsComponent implements OnInit { | |||
79 | this.inReplyToCommentId = undefined | 81 | this.inReplyToCommentId = undefined |
80 | } | 82 | } |
81 | 83 | ||
84 | onThreadCreated (commentTree: VideoCommentThreadTree) { | ||
85 | this.viewReplies(commentTree.comment) | ||
86 | } | ||
87 | |||
88 | onWantedToDelete (commentToDelete: VideoComment) { | ||
89 | let message = 'Do you really want to delete this comment?' | ||
90 | if (commentToDelete.totalReplies !== 0) message += `${commentToDelete.totalReplies} would be deleted too.` | ||
91 | |||
92 | this.confirmService.confirm(message, 'Delete').subscribe( | ||
93 | res => { | ||
94 | if (res === false) return | ||
95 | |||
96 | this.videoCommentService.deleteVideoComment(commentToDelete.videoId, commentToDelete.id) | ||
97 | .subscribe( | ||
98 | () => { | ||
99 | // Delete the comment in the tree | ||
100 | if (commentToDelete.inReplyToCommentId) { | ||
101 | const thread = this.threadComments[commentToDelete.threadId] | ||
102 | if (!thread) { | ||
103 | console.error(`Cannot find thread ${commentToDelete.threadId} of the comment to delete ${commentToDelete.id}`) | ||
104 | return | ||
105 | } | ||
106 | |||
107 | this.deleteLocalCommentThread(thread, commentToDelete) | ||
108 | return | ||
109 | } | ||
110 | |||
111 | // Delete the thread | ||
112 | this.comments = this.comments.filter(c => c.id !== commentToDelete.id) | ||
113 | this.componentPagination.totalItems-- | ||
114 | }, | ||
115 | |||
116 | err => this.notificationsService.error('Error', err.message) | ||
117 | ) | ||
118 | } | ||
119 | ) | ||
120 | } | ||
121 | |||
82 | isUserLoggedIn () { | 122 | isUserLoggedIn () { |
83 | return this.authService.isLoggedIn() | 123 | return this.authService.isLoggedIn() |
84 | } | 124 | } |
@@ -91,7 +131,7 @@ export class VideoCommentsComponent implements OnInit { | |||
91 | } | 131 | } |
92 | } | 132 | } |
93 | 133 | ||
94 | protected hasMoreComments () { | 134 | private hasMoreComments () { |
95 | // No results | 135 | // No results |
96 | if (this.componentPagination.totalItems === 0) return false | 136 | if (this.componentPagination.totalItems === 0) return false |
97 | 137 | ||
@@ -101,4 +141,15 @@ export class VideoCommentsComponent implements OnInit { | |||
101 | const maxPage = this.componentPagination.totalItems / this.componentPagination.itemsPerPage | 141 | const maxPage = this.componentPagination.totalItems / this.componentPagination.itemsPerPage |
102 | return maxPage > this.componentPagination.currentPage | 142 | return maxPage > this.componentPagination.currentPage |
103 | } | 143 | } |
144 | |||
145 | private deleteLocalCommentThread (parentComment: VideoCommentThreadTree, commentToDelete: VideoComment) { | ||
146 | for (const commentChild of parentComment.children) { | ||
147 | if (commentChild.comment.id === commentToDelete.id) { | ||
148 | parentComment.children = parentComment.children.filter(c => c.comment.id !== commentToDelete.id) | ||
149 | return | ||
150 | } | ||
151 | |||
152 | this.deleteLocalCommentThread(commentChild, commentToDelete) | ||
153 | } | ||
154 | } | ||
104 | } | 155 | } |