From 18b168b5fcc06800a9987eb33cf2eda288c3587f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20K=C3=A4sler?= <tom.kaesler@mni.thm.de> Date: Wed, 9 Oct 2019 00:36:39 +0200 Subject: [PATCH] Refactor comment userId attribute to creatorId Add snackbar notification when a users comment got favorited --- .../_dialogs/create-comment/create-comment.component.ts | 2 +- .../shared/comment-list/comment-list.component.ts | 6 ++++++ src/app/models/comment.ts | 6 +++--- src/app/services/websockets/ws-comment-service.service.ts | 2 +- src/assets/i18n/participant/de.json | 1 + src/assets/i18n/participant/en.json | 1 + 6 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/app/components/shared/_dialogs/create-comment/create-comment.component.ts b/src/app/components/shared/_dialogs/create-comment/create-comment.component.ts index 62f54c8aa..f48f539b3 100644 --- a/src/app/components/shared/_dialogs/create-comment/create-comment.component.ts +++ b/src/app/components/shared/_dialogs/create-comment/create-comment.component.ts @@ -56,7 +56,7 @@ export class CreateCommentComponent implements OnInit { const comment = new Comment(); comment.roomId = localStorage.getItem(`roomId`); comment.body = body; - comment.userId = this.user.id; + comment.creatorId = this.user.id; comment.createdFromLecturer = this.user.role === 1; this.dialogRef.close(comment); } 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 45bf1a4bc..ee5109910 100644 --- a/src/app/components/shared/comment-list/comment-list.component.ts +++ b/src/app/components/shared/comment-list/comment-list.component.ts @@ -194,6 +194,12 @@ export class CommentListComponent implements OnInit { break; case this.favorite: this.comments[i].favorite = <boolean>value; + console.log(this.comments[i]); + if (this.user.id === this.comments[i].creatorId && <boolean>value) { + this.translateService.get('comment-list.comment-got-favorited').subscribe( msg => { + this.notificationService.show(msg); + }); + } break; case 'score': this.comments[i].score = <number>value; diff --git a/src/app/models/comment.ts b/src/app/models/comment.ts index 51308497b..22062ef8c 100644 --- a/src/app/models/comment.ts +++ b/src/app/models/comment.ts @@ -3,7 +3,7 @@ import { CorrectWrong } from './correct-wrong.enum'; export class Comment { id: string; roomId: string; - userId: string; + creatorId: string; revision: string; body: string; read: boolean; @@ -16,7 +16,7 @@ export class Comment { ack: boolean; constructor(roomId: string = '', - userId: string = '', + creatorId: string = '', body: string = '', read: boolean = false, correct: CorrectWrong = CorrectWrong.NULL, @@ -28,7 +28,7 @@ export class Comment { ack: boolean = true) { this.id = ''; this.roomId = roomId; - this.userId = userId; + this.creatorId = creatorId; this.revision = ''; this.body = body; this.read = read; diff --git a/src/app/services/websockets/ws-comment-service.service.ts b/src/app/services/websockets/ws-comment-service.service.ts index 8694fe84b..4333dc741 100644 --- a/src/app/services/websockets/ws-comment-service.service.ts +++ b/src/app/services/websockets/ws-comment-service.service.ts @@ -20,7 +20,7 @@ export class WsCommentServiceService { constructor(private wsConnector: WsConnectorService) { } add(comment: Comment): void { - const message = new CreateComment(comment.roomId, comment.userId, comment.body); + const message = new CreateComment(comment.roomId, comment.creatorId, comment.body); this.wsConnector.send(`/queue/comment.command.create`, JSON.stringify(message)); } diff --git a/src/assets/i18n/participant/de.json b/src/assets/i18n/participant/de.json index 475be570c..cad6ca12b 100644 --- a/src/assets/i18n/participant/de.json +++ b/src/assets/i18n/participant/de.json @@ -28,6 +28,7 @@ "add-comment": "Stell deine Frage!", "pause-comments": "Pausiere den Fragen-Stream", "play-comments": "Starte den Fragen-Stream", + "comment-got-favorited": "Eine Frage von dir wurde favorisiert!", "comment-stream-stopped": "Der Fragen-Stream wurde gestoppt.", "comment-stream-started": "Der Fragen-Stream wurde gestartet.", "comment-sent": "Die Frage wurde veröffentlicht.", diff --git a/src/assets/i18n/participant/en.json b/src/assets/i18n/participant/en.json index bd5132264..cd14fcfe3 100644 --- a/src/assets/i18n/participant/en.json +++ b/src/assets/i18n/participant/en.json @@ -28,6 +28,7 @@ "add-comment": "Ask a question!", "pause-comments": "Pause the question stream", "play-comments": "Start the question stream", + "comment-got-favorited": "A question of yours got favorited!", "comment-stream-stopped": "Question stream has been stopped.", "comment-stream-started": "Question stream has been started.", "comment-sent": "The question has been published.", -- GitLab