diff --git a/src/app/components/shared/comment-list/comment-list.component.ts b/src/app/components/shared/comment-list/comment-list.component.ts index a5dd22ad4e704624b925e02bdfa4ae587cd7b09d..801eacc3e5a002ee9a6ff91fca48235f02f66a87 100644 --- a/src/app/components/shared/comment-list/comment-list.component.ts +++ b/src/app/components/shared/comment-list/comment-list.component.ts @@ -19,9 +19,9 @@ export class CommentListComponent implements OnInit { filteredComments: Comment[]; constructor(private commentService: CommentService, - private translateService: TranslateService, - protected langService: LanguageService, - private rxStompService: RxStompService) { + private translateService: TranslateService, + protected langService: LanguageService, + private rxStompService: RxStompService) { langService.langEmitter.subscribe(lang => translateService.use(lang)); } @@ -51,28 +51,36 @@ export class CommentListComponent implements OnInit { parseIncomingMessage(message: Message) { const msg = JSON.parse(message.body); const payload = msg.payload; - if (msg.type === 'CommentCreated') { - const c = new Comment(); - c.roomId = this.roomId; - c.body = payload.body; - c.id = payload.id; - c.creationTimestamp = payload.timestamp; - this.comments = this.comments.concat(c); - } else if (msg.type === 'CommentPatched') { + switch (msg.type) { + case 'CommentCreated': + const c = new Comment(); + c.roomId = this.roomId; + c.body = payload.body; + c.id = payload.id; + c.creationTimestamp = payload.timestamp; + this.comments = this.comments.concat(c); + break; + case 'CommentPatched': for (let i = 0; i < this.comments.length; i++) { if (payload.id === this.comments[i].id) { for (const [key, value] of Object.entries(payload.changes)) { switch (key) { - case 'read': this.comments[i].read = <boolean>value; - break; - case 'correct' : this.comments[i].correct = <boolean>value; - break; - case 'favorite' : this.comments[i].favorite = <boolean>value; - break; + case 'read': + this.comments[i].read = <boolean>value; + break; + case 'correct' : + this.comments[i].correct = <boolean>value; + break; + case 'favorite' : + this.comments[i].favorite = <boolean>value; + break; + case 'score' : + this.comments[i].score = <number>value; + break; } } } - } + } } } } diff --git a/src/app/components/shared/comment/comment.component.ts b/src/app/components/shared/comment/comment.component.ts index b6290b6d07a3346248fdf52d6909a2707079c476..a689be35d03728a381c5a58c06e2e58cdefab56c 100644 --- a/src/app/components/shared/comment/comment.component.ts +++ b/src/app/components/shared/comment/comment.component.ts @@ -51,6 +51,14 @@ export class CommentComponent implements OnInit { this.comment = this.wsCommentService.toggleFavorite(comment); } + voteUp(comment: Comment): void { + this.wsCommentService.voteUp(comment); + } + + voteDown(comment: Comment): void { + this.wsCommentService.voteDown(comment); + } + delete(comment: Comment): void { this.commentService.deleteComment(comment.id).subscribe(room => { this.notification.show(`Comment '${comment.body}' successfully deleted.`);