diff options
author | kimsible <kimsible@users.noreply.github.com> | 2020-08-12 12:43:26 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-08-14 15:03:38 +0200 |
commit | fdd1296521354401e9927e5faeb0aa17ba810c41 (patch) | |
tree | 51a0e4db94db8736c51aec0b714c3cf0bda1ad9d /client/src/app/+videos/+video-watch/comment/video-comment-add.component.ts | |
parent | e548a7c9b0c0d8bead03dd49ea86c600515e42db (diff) | |
download | PeerTube-fdd1296521354401e9927e5faeb0aa17ba810c41.tar.gz PeerTube-fdd1296521354401e9927e5faeb0aa17ba810c41.tar.zst PeerTube-fdd1296521354401e9927e5faeb0aa17ba810c41.zip |
Small refactor comments
Diffstat (limited to 'client/src/app/+videos/+video-watch/comment/video-comment-add.component.ts')
-rw-r--r-- | client/src/app/+videos/+video-watch/comment/video-comment-add.component.ts | 41 |
1 files changed, 22 insertions, 19 deletions
diff --git a/client/src/app/+videos/+video-watch/comment/video-comment-add.component.ts b/client/src/app/+videos/+video-watch/comment/video-comment-add.component.ts index 3d0611a2d..3fa5fd623 100644 --- a/client/src/app/+videos/+video-watch/comment/video-comment-add.component.ts +++ b/client/src/app/+videos/+video-watch/comment/video-comment-add.component.ts | |||
@@ -17,11 +17,10 @@ import { I18n } from '@ngx-translate/i18n-polyfill' | |||
17 | export class VideoCommentAddComponent extends FormReactive implements OnChanges, OnInit { | 17 | export class VideoCommentAddComponent extends FormReactive implements OnChanges, OnInit { |
18 | @Input() user: User | 18 | @Input() user: User |
19 | @Input() video: Video | 19 | @Input() video: Video |
20 | @Input() parentComment: VideoComment | 20 | @Input() parentComment?: VideoComment |
21 | @Input() parentComments: VideoComment[] | 21 | @Input() parentComments?: VideoComment[] |
22 | @Input() focusOnInit = false | 22 | @Input() focusOnInit = false |
23 | @Input() textValue?: string | 23 | @Input() textValue?: string |
24 | @Input() commentThread?: boolean | ||
25 | 24 | ||
26 | @Output() commentCreated = new EventEmitter<VideoComment>() | 25 | @Output() commentCreated = new EventEmitter<VideoComment>() |
27 | @Output() cancel = new EventEmitter() | 26 | @Output() cancel = new EventEmitter() |
@@ -57,27 +56,13 @@ export class VideoCommentAddComponent extends FormReactive implements OnChanges, | |||
57 | }) | 56 | }) |
58 | 57 | ||
59 | if (this.user) { | 58 | if (this.user) { |
60 | if (this.commentThread) { | 59 | if (!this.parentComment) { |
61 | this.addingCommentButtonValue = this.i18n('Comment') | 60 | this.addingCommentButtonValue = this.i18n('Comment') |
62 | } else { | 61 | } else { |
63 | this.addingCommentButtonValue = this.i18n('Reply') | 62 | this.addingCommentButtonValue = this.i18n('Reply') |
64 | } | 63 | } |
65 | 64 | ||
66 | if (this.textValue) { | 65 | this.initTextValue() |
67 | this.patchTextValue(this.textValue, this.focusOnInit) | ||
68 | return | ||
69 | } | ||
70 | |||
71 | if (this.parentComment) { | ||
72 | const mentions = this.parentComments | ||
73 | .filter(c => c.account && c.account.id !== this.user.account.id) // Don't add mention of ourselves | ||
74 | .map(c => '@' + c.by) | ||
75 | |||
76 | const mentionsSet = new Set(mentions) | ||
77 | const mentionsText = Array.from(mentionsSet).join(' ') + ' ' | ||
78 | |||
79 | this.patchTextValue(mentionsText, this.focusOnInit) | ||
80 | } | ||
81 | } | 66 | } |
82 | } | 67 | } |
83 | 68 | ||
@@ -176,6 +161,24 @@ export class VideoCommentAddComponent extends FormReactive implements OnChanges, | |||
176 | .addCommentThread(this.video.id, commentCreate) | 161 | .addCommentThread(this.video.id, commentCreate) |
177 | } | 162 | } |
178 | 163 | ||
164 | private initTextValue () { | ||
165 | if (this.textValue) { | ||
166 | this.patchTextValue(this.textValue, this.focusOnInit) | ||
167 | return | ||
168 | } | ||
169 | |||
170 | if (this.parentComment) { | ||
171 | const mentions = this.parentComments | ||
172 | .filter(c => c.account && c.account.id !== this.user.account.id) // Don't add mention of ourselves | ||
173 | .map(c => '@' + c.by) | ||
174 | |||
175 | const mentionsSet = new Set(mentions) | ||
176 | const mentionsText = Array.from(mentionsSet).join(' ') + ' ' | ||
177 | |||
178 | this.patchTextValue(mentionsText, this.focusOnInit) | ||
179 | } | ||
180 | } | ||
181 | |||
179 | private patchTextValue (text: string, focus: boolean) { | 182 | private patchTextValue (text: string, focus: boolean) { |
180 | setTimeout(() => { | 183 | setTimeout(() => { |
181 | if (focus) { | 184 | if (focus) { |