Skip to content
Snippets Groups Projects
Commit be69f065 authored by Lukas Mauß's avatar Lukas Mauß
Browse files

Show questions created by lecturer or moderator first, no matter which sorting is active

parent aac54c96
No related merge requests found
...@@ -28,6 +28,7 @@ import { TagsComponent } from '../../creator/_dialogs/tags/tags.component'; ...@@ -28,6 +28,7 @@ import { TagsComponent } from '../../creator/_dialogs/tags/tags.component';
import { DeleteCommentsComponent } from '../../creator/_dialogs/delete-comments/delete-comments.component'; import { DeleteCommentsComponent } from '../../creator/_dialogs/delete-comments/delete-comments.component';
import { Export } from '../../../models/export'; import { Export } from '../../../models/export';
import { BonusTokenService } from '../../../services/http/bonus-token.service'; import { BonusTokenService } from '../../../services/http/bonus-token.service';
import { ModeratorService } from '../../../services/http/moderator.service';
export enum Period { export enum Period {
FROMNOW = 'from-now', FROMNOW = 'from-now',
...@@ -94,6 +95,7 @@ export class CommentListComponent implements OnInit, OnDestroy { ...@@ -94,6 +95,7 @@ export class CommentListComponent implements OnInit, OnDestroy {
headerInterface = null; headerInterface = null;
period: Period = Period.TWOWEEKS; period: Period = Period.TWOWEEKS;
fromNow: number; fromNow: number;
moderatorIds: string[];
constructor( constructor(
private commentService: CommentService, private commentService: CommentService,
...@@ -111,7 +113,8 @@ export class CommentListComponent implements OnInit, OnDestroy { ...@@ -111,7 +113,8 @@ export class CommentListComponent implements OnInit, OnDestroy {
private router: Router, private router: Router,
private titleService: TitleService, private titleService: TitleService,
private translationService: TranslateService, private translationService: TranslateService,
private bonusTokenService: BonusTokenService private bonusTokenService: BonusTokenService,
private moderatorService: ModeratorService
) { ) {
langService.langEmitter.subscribe(lang => translateService.use(lang)); langService.langEmitter.subscribe(lang => translateService.use(lang));
} }
...@@ -217,6 +220,7 @@ export class CommentListComponent implements OnInit, OnDestroy { ...@@ -217,6 +220,7 @@ export class CommentListComponent implements OnInit, OnDestroy {
this.roomService.addToHistory(this.room.id); this.roomService.addToHistory(this.room.id);
this.authenticationService.setAccess(this.shortId, UserRole.PARTICIPANT); this.authenticationService.setAccess(this.shortId, UserRole.PARTICIPANT);
} }
this.getModeratorIds();
this.subscribeCommentStream(); this.subscribeCommentStream();
this.commentService.getAckComments(this.room.id) this.commentService.getAckComments(this.room.id)
.subscribe(comments => { .subscribe(comments => {
...@@ -241,6 +245,13 @@ export class CommentListComponent implements OnInit, OnDestroy { ...@@ -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() { ngOnDestroy() {
if (!this.freeze && this.commentStream) { if (!this.freeze && this.commentStream) {
this.commentStream.unsubscribe(); this.commentStream.unsubscribe();
...@@ -493,7 +504,7 @@ export class CommentListComponent implements OnInit, OnDestroy { ...@@ -493,7 +504,7 @@ export class CommentListComponent implements OnInit, OnDestroy {
} }
sort(array: any[], type: string): any[] { sort(array: any[], type: string): any[] {
return array.sort((a, b) => { const sortedArray = array.sort((a, b) => {
if (type === this.voteasc) { if (type === this.voteasc) {
return (a.score > b.score) ? 1 : (b.score > a.score) ? -1 : 0; return (a.score > b.score) ? 1 : (b.score > a.score) ? -1 : 0;
} else if (type === this.votedesc) { } else if (type === this.votedesc) {
...@@ -503,6 +514,13 @@ export class CommentListComponent implements OnInit, OnDestroy { ...@@ -503,6 +514,13 @@ export class CommentListComponent implements OnInit, OnDestroy {
return (+dateB > +dateA) ? 1 : (+dateA > +dateB) ? -1 : 0; 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 { sortComments(type: string): void {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment