Handle line feeds in comments
This commit is contained in:
parent
2f315e2f91
commit
5de8a55abc
4 changed files with 16 additions and 6 deletions
|
@ -88,6 +88,12 @@ function objectToFormData (obj: any, form?: FormData, namespace?: string) {
|
||||||
return fd
|
return fd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function lineFeedToHtml (obj: object, keyToNormalize: string) {
|
||||||
|
return immutableAssign(obj, {
|
||||||
|
[keyToNormalize]: obj[keyToNormalize].replace(/\r?\n|\r/g, '<br />')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
viewportHeight,
|
viewportHeight,
|
||||||
getParameterByName,
|
getParameterByName,
|
||||||
|
@ -97,5 +103,6 @@ export {
|
||||||
isInSmallView,
|
isInSmallView,
|
||||||
isInMobileView,
|
isInMobileView,
|
||||||
immutableAssign,
|
immutableAssign,
|
||||||
objectToFormData
|
objectToFormData,
|
||||||
|
lineFeedToHtml
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,7 +90,7 @@ export class VideoCommentComponent implements OnInit, OnChanges {
|
||||||
|
|
||||||
private init () {
|
private init () {
|
||||||
this.sanitizedCommentHTML = sanitizeHtml(this.comment.text, {
|
this.sanitizedCommentHTML = sanitizeHtml(this.comment.text, {
|
||||||
allowedTags: [ 'p', 'span' ]
|
allowedTags: [ 'p', 'span', 'br' ]
|
||||||
})
|
})
|
||||||
|
|
||||||
this.newParentComments = this.parentComments.concat([ this.comment ])
|
this.newParentComments = this.parentComments.concat([ this.comment ])
|
||||||
|
|
|
@ -2,6 +2,7 @@ import { HttpClient, HttpParams } from '@angular/common/http'
|
||||||
import { Injectable } from '@angular/core'
|
import { Injectable } from '@angular/core'
|
||||||
import 'rxjs/add/operator/catch'
|
import 'rxjs/add/operator/catch'
|
||||||
import 'rxjs/add/operator/map'
|
import 'rxjs/add/operator/map'
|
||||||
|
import { immutableAssign, lineFeedToHtml } from '@app/shared/misc/utils'
|
||||||
import { Observable } from 'rxjs/Observable'
|
import { Observable } from 'rxjs/Observable'
|
||||||
import { ResultList } from '../../../../../../shared/models'
|
import { ResultList } from '../../../../../../shared/models'
|
||||||
import {
|
import {
|
||||||
|
@ -26,16 +27,18 @@ export class VideoCommentService {
|
||||||
|
|
||||||
addCommentThread (videoId: number | string, comment: VideoCommentCreate) {
|
addCommentThread (videoId: number | string, comment: VideoCommentCreate) {
|
||||||
const url = VideoCommentService.BASE_VIDEO_URL + videoId + '/comment-threads'
|
const url = VideoCommentService.BASE_VIDEO_URL + videoId + '/comment-threads'
|
||||||
|
const normalizedComment = lineFeedToHtml(comment, 'text')
|
||||||
|
|
||||||
return this.authHttp.post(url, comment)
|
return this.authHttp.post(url, normalizedComment)
|
||||||
.map(data => this.extractVideoComment(data['comment']))
|
.map(data => this.extractVideoComment(data['comment']))
|
||||||
.catch(this.restExtractor.handleError)
|
.catch(this.restExtractor.handleError)
|
||||||
}
|
}
|
||||||
|
|
||||||
addCommentReply (videoId: number | string, inReplyToCommentId: number, comment: VideoCommentCreate) {
|
addCommentReply (videoId: number | string, inReplyToCommentId: number, comment: VideoCommentCreate) {
|
||||||
const url = VideoCommentService.BASE_VIDEO_URL + videoId + '/comments/' + inReplyToCommentId
|
const url = VideoCommentService.BASE_VIDEO_URL + videoId + '/comments/' + inReplyToCommentId
|
||||||
|
const normalizedComment = lineFeedToHtml(comment, 'text')
|
||||||
|
|
||||||
return this.authHttp.post(url, comment)
|
return this.authHttp.post(url, normalizedComment)
|
||||||
.map(data => this.extractVideoComment(data['comment']))
|
.map(data => this.extractVideoComment(data['comment']))
|
||||||
.catch(this.restExtractor.handleError)
|
.catch(this.restExtractor.handleError)
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ const addVideoCommentThreadValidator = [
|
||||||
body('text').custom(isValidVideoCommentText).not().isEmpty().withMessage('Should have a valid comment text'),
|
body('text').custom(isValidVideoCommentText).not().isEmpty().withMessage('Should have a valid comment text'),
|
||||||
|
|
||||||
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||||
logger.debug('Checking addVideoCommentThread parameters.', { parameters: req.params })
|
logger.debug('Checking addVideoCommentThread parameters.', { parameters: req.params, body: req.body })
|
||||||
|
|
||||||
if (areValidationErrors(req, res)) return
|
if (areValidationErrors(req, res)) return
|
||||||
if (!await isVideoExist(req.params.videoId, res)) return
|
if (!await isVideoExist(req.params.videoId, res)) return
|
||||||
|
@ -59,7 +59,7 @@ const addVideoCommentReplyValidator = [
|
||||||
body('text').custom(isValidVideoCommentText).not().isEmpty().withMessage('Should have a valid comment text'),
|
body('text').custom(isValidVideoCommentText).not().isEmpty().withMessage('Should have a valid comment text'),
|
||||||
|
|
||||||
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||||
logger.debug('Checking addVideoCommentReply parameters.', { parameters: req.params })
|
logger.debug('Checking addVideoCommentReply parameters.', { parameters: req.params, body: req.body })
|
||||||
|
|
||||||
if (areValidationErrors(req, res)) return
|
if (areValidationErrors(req, res)) return
|
||||||
if (!await isVideoExist(req.params.videoId, res)) return
|
if (!await isVideoExist(req.params.videoId, res)) return
|
||||||
|
|
Loading…
Add table
Reference in a new issue