From 3b10b106a2ad84ed9bc1cad251c7cb3cf75d203d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Mau=C3=9F?= <lukas.mauss@mni.thm.de> Date: Thu, 21 Mar 2019 10:46:22 +0100 Subject: [PATCH] Fix comment updating in comment-list --- .../comment-list/comment-list.component.ts | 17 +++++++++++++++++ .../shared/comment/comment.component.ts | 12 +++--------- 2 files changed, 20 insertions(+), 9 deletions(-) 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 91d4a6d78..379d71db5 100644 --- a/src/app/components/shared/comment-list/comment-list.component.ts +++ b/src/app/components/shared/comment-list/comment-list.component.ts @@ -58,7 +58,24 @@ export class CommentListComponent implements OnInit { c.id = payload.id; c.creationTimestamp = payload.timestamp; this.comments = this.comments.concat(c); + } else if (msg.type === '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)) { + console.log(value); + switch (key) { + case 'read': this.comments[i].read = value; + break; + case 'correct' : this.comments[i].correct = value; + break; + case 'favorite' : this.comments[i].favorite = value; + break; + } + } + } + } } } + } diff --git a/src/app/components/shared/comment/comment.component.ts b/src/app/components/shared/comment/comment.component.ts index fb64a3436..35776dec4 100644 --- a/src/app/components/shared/comment/comment.component.ts +++ b/src/app/components/shared/comment/comment.component.ts @@ -8,8 +8,6 @@ import { NotificationService } from '../../../services/util/notification.service import { TranslateService } from '@ngx-translate/core'; import { LanguageService } from '../../../services/util/language.service'; import { WsCommentServiceService } from '../../../services/websockets/ws-comment-service.service'; -import { RxStompService } from '@stomp/ng2-stompjs'; -import { Message } from '@stomp/stompjs'; @Component({ selector: 'app-comment', @@ -28,8 +26,7 @@ export class CommentComponent implements OnInit { private notification: NotificationService, private translateService: TranslateService, protected langService: LanguageService, - private wsCommentService: WsCommentServiceService, - private rxStompService: RxStompService) { + private wsCommentService: WsCommentServiceService) { langService.langEmitter.subscribe(lang => translateService.use(lang)); } ngOnInit() { @@ -37,9 +34,6 @@ export class CommentComponent implements OnInit { this.isCreator = true; } this.translateService.use(localStorage.getItem('currentLang')); - this.rxStompService.watch(`/topic/${this.comment.roomId}.comment.stream`).subscribe((message: Message) => { - this.parseIncomingMessage(message); - }); } setRead(comment: Comment): void { @@ -62,7 +56,7 @@ export class CommentComponent implements OnInit { this.notification.show(`Comment '${comment.body}' successfully deleted.`); }); } - + /* parseIncomingMessage(message: Message) { const msg = JSON.parse(message.body); const payload = msg.payload; @@ -78,5 +72,5 @@ export class CommentComponent implements OnInit { } } } - } + } */ } -- GitLab