From d7e70384a360cda51fe23712331110a5c8b1124c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 5 Jan 2018 11:19:25 +0100 Subject: Add mentions to comments --- .../+video-watch/comment/video-comment-add.component.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'client/src/app/videos/+video-watch/comment/video-comment-add.component.ts') 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 27655eca7..3e064efcb 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 @@ -2,7 +2,7 @@ import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } import { FormBuilder, FormGroup } from '@angular/forms' import { NotificationsService } from 'angular2-notifications' import { Observable } from 'rxjs/Observable' -import { VideoCommentCreate } from '../../../../../../shared/models/videos/video-comment.model' +import { VideoCommentCreate, VideoCommentThreadTree } from '../../../../../../shared/models/videos/video-comment.model' import { FormReactive } from '../../../shared' import { VIDEO_COMMENT_TEXT } from '../../../shared/forms/form-validators/video-comment' import { User } from '../../../shared/users' @@ -19,6 +19,7 @@ export class VideoCommentAddComponent extends FormReactive implements OnInit { @Input() user: User @Input() video: Video @Input() parentComment: VideoComment + @Input() parentComments: VideoComment[] @Input() focusOnInit = false @Output() commentCreated = new EventEmitter() @@ -55,6 +56,17 @@ export class VideoCommentAddComponent extends FormReactive implements OnInit { if (this.focusOnInit === true) { this.textareaElement.nativeElement.focus() } + + if (this.parentComment) { + const mentions = this.parentComments + .filter(c => c.account.id !== this.user.account.id) + .map(c => '@' + c.account.name) + + const mentionsSet = new Set(mentions) + const mentionsText = Array.from(mentionsSet).join(' ') + ' ' + + this.form.patchValue({ text: mentionsText }) + } } formValidated () { -- cgit v1.2.3