From be69f06541833ceb4daaf7af4ef7ae9a23e84320 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Mau=C3=9F?= <lukas.mauss@gmx.de> Date: Sun, 18 Apr 2021 14:09:15 +0200 Subject: [PATCH] Show questions created by lecturer or moderator first, no matter which sorting is active --- .../comment-list/comment-list.component.ts | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 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 be3df74fd..913caf5a8 100644 --- a/src/app/components/shared/comment-list/comment-list.component.ts +++ b/src/app/components/shared/comment-list/comment-list.component.ts @@ -28,6 +28,7 @@ import { TagsComponent } from '../../creator/_dialogs/tags/tags.component'; import { DeleteCommentsComponent } from '../../creator/_dialogs/delete-comments/delete-comments.component'; import { Export } from '../../../models/export'; import { BonusTokenService } from '../../../services/http/bonus-token.service'; +import { ModeratorService } from '../../../services/http/moderator.service'; export enum Period { FROMNOW = 'from-now', @@ -94,6 +95,7 @@ export class CommentListComponent implements OnInit, OnDestroy { headerInterface = null; period: Period = Period.TWOWEEKS; fromNow: number; + moderatorIds: string[]; constructor( private commentService: CommentService, @@ -111,7 +113,8 @@ export class CommentListComponent implements OnInit, OnDestroy { private router: Router, private titleService: TitleService, private translationService: TranslateService, - private bonusTokenService: BonusTokenService + private bonusTokenService: BonusTokenService, + private moderatorService: ModeratorService ) { langService.langEmitter.subscribe(lang => translateService.use(lang)); } @@ -217,6 +220,7 @@ export class CommentListComponent implements OnInit, OnDestroy { this.roomService.addToHistory(this.room.id); this.authenticationService.setAccess(this.shortId, UserRole.PARTICIPANT); } + this.getModeratorIds(); this.subscribeCommentStream(); this.commentService.getAckComments(this.room.id) .subscribe(comments => { @@ -241,6 +245,13 @@ export class CommentListComponent implements OnInit, OnDestroy { }); } + getModeratorIds() { + this.moderatorService.get(this.roomId).subscribe(list => { + this.moderatorIds = list.map(m => m.accountId); + this.moderatorIds.push(this.room.ownerId); + }); + } + ngOnDestroy() { if (!this.freeze && this.commentStream) { this.commentStream.unsubscribe(); @@ -493,7 +504,7 @@ export class CommentListComponent implements OnInit, OnDestroy { } sort(array: any[], type: string): any[] { - return array.sort((a, b) => { + const sortedArray = array.sort((a, b) => { if (type === this.voteasc) { return (a.score > b.score) ? 1 : (b.score > a.score) ? -1 : 0; } else if (type === this.votedesc) { @@ -503,6 +514,13 @@ export class CommentListComponent implements OnInit, OnDestroy { return (+dateB > +dateA) ? 1 : (+dateA > +dateB) ? -1 : 0; } }); + return sortedArray.sort((a, b) => { + return this.isCreatedByModeratorOrCreator(a) ? -1 : this.isCreatedByModeratorOrCreator(b) ? 1 : 0; + }); + } + + isCreatedByModeratorOrCreator(comment: Comment): boolean { + return this.moderatorIds.indexOf(comment.creatorId) > -1; } sortComments(type: string): void { -- GitLab