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 87dbbd3fd7943fbef55860bc7f14f0c2caaa9d0e..f2349930fcde64f85bfd555f0460b88bb08abfd9 100644 --- a/src/app/components/shared/comment-list/comment-list.component.ts +++ b/src/app/components/shared/comment-list/comment-list.component.ts @@ -423,9 +423,9 @@ export class CommentListComponent implements OnInit, OnDestroy { case this.owner: return c.creatorId === this.user.id; case this.moderator: - return c.creatorId === this.user.id && (this.user.role === 2 || this.user.role === 1); + return this.moderatorIds.includes(c.creatorId); case this.lecturer: - return c.creatorId === this.user.id && this.user.role === 3; + return c.createdFromLecturer; } }); this.hideCommentsList = true; diff --git a/src/app/components/shared/comment/comment.component.ts b/src/app/components/shared/comment/comment.component.ts index 328d4675cace367e40b1723b276c7e9dbd39a044..76f7e91fabbe963999dcf967fdebed8b270e1494 100644 --- a/src/app/components/shared/comment/comment.component.ts +++ b/src/app/components/shared/comment/comment.component.ts @@ -64,6 +64,7 @@ export class CommentComponent implements OnInit, AfterViewInit { isExpandable = false; selectedKeyword = ''; filterProfanityForModerators = false; + createdBy; constructor(protected authenticationService: AuthenticationService, private route: ActivatedRoute, diff --git a/src/app/models/comment.ts b/src/app/models/comment.ts index 42a2fb55f86e291fb2d3599372f516d0ee7cfb4a..18b77b83d0c11f57a30cf254c2cf7d80337b62db 100644 --- a/src/app/models/comment.ts +++ b/src/app/models/comment.ts @@ -26,6 +26,7 @@ export class Comment { upvotes: number; downvotes: number; language: Language; + createdBy; constructor(roomId: string = '', creatorId: string = '', @@ -46,7 +47,8 @@ export class Comment { keywordsFromSpacy: SpacyKeyword[] = [], upvotes = 0, downvotes = 0, - language = Language.auto) { + language = Language.auto, + createdBy?: any) { this.id = ''; this.roomId = roomId; this.creatorId = creatorId; @@ -69,6 +71,7 @@ export class Comment { this.upvotes = upvotes; this.downvotes = downvotes; this.language = language; + this.createdBy = createdBy; } static mapModelToLanguage(model: Model): Language { diff --git a/src/app/services/http/comment.service.ts b/src/app/services/http/comment.service.ts index b92ecdd14da0249c69d83df9e6fd5cc067227104..266fdcf8105e25b2aeb10ee2a8a8a744f9f2b336 100644 --- a/src/app/services/http/comment.service.ts +++ b/src/app/services/http/comment.service.ts @@ -105,7 +105,7 @@ export class CommentService extends BaseHttpService { getAckComments(roomId: string): Observable<Comment[]> { const connectionUrl = this.apiUrl.base + this.apiUrl.comment + this.apiUrl.find; return this.http.post<Comment[]>(connectionUrl, { - properties: { roomId: roomId, ack: true }, + properties: { roomId, ack: true }, externalFilters: {} }, httpOptions).pipe( map(commentList => commentList.map(comment => this.parseComment(comment))), @@ -117,12 +117,10 @@ export class CommentService extends BaseHttpService { getRejectedComments(roomId: string): Observable<Comment[]> { const connectionUrl = this.apiUrl.base + this.apiUrl.comment + this.apiUrl.find; return this.http.post<Comment[]>(connectionUrl, { - properties: { roomId: roomId, ack: false }, + properties: { roomId, ack: false }, externalFilters: {} }, httpOptions).pipe( - map(commentList => { - return commentList.map(comment => this.parseComment(comment)); - }), + map(commentList => commentList.map(comment => this.parseComment(comment))), tap(_ => ''), catchError(this.handleError<Comment[]>('getComments', [])) ); @@ -131,12 +129,10 @@ export class CommentService extends BaseHttpService { getComments(roomId: string): Observable<Comment[]> { const connectionUrl = this.apiUrl.base + this.apiUrl.comment + this.apiUrl.find; return this.http.post<Comment[]>(connectionUrl, { - properties: { roomId: roomId }, + properties: { roomId }, externalFilters: {} }, httpOptions).pipe( - map(commentList => { - return commentList.map(comment => this.parseComment(comment)); - }), + map(commentList => commentList.map(comment => this.parseComment(comment))), tap(_ => ''), catchError(this.handleError<Comment[]>('getComments', [])) ); @@ -175,6 +171,14 @@ export class CommentService extends BaseHttpService { ); } + role(comment: Comment) { + const connectionUrl = this.apiUrl.base + this.apiUrl.comment + '/' + comment.id + '/role'; + return this.http.patch(connectionUrl, httpOptions).pipe( + tap(_ => ''), + catchError(this.handleError<any>('roleComment')) + ); + } + deleteCommentsByRoomId(roomId: string): Observable<Comment> { const connectionUrl = `${this.apiUrl.base + this.apiUrl.comment}/byRoom?roomId=${roomId}`; return this.http.delete<Comment>(connectionUrl, httpOptions).pipe( @@ -186,7 +190,7 @@ export class CommentService extends BaseHttpService { countByRoomId(roomId: string, ack: boolean): Observable<number> { const connectionUrl = this.apiUrl.base + this.apiUrl.comment + this.apiUrl.find + this.apiUrl.count; return this.http.post<number>(connectionUrl, { - properties: { roomId: roomId, ack: ack }, + properties: { roomId, ack }, externalFilters: {} }, httpOptions).pipe( tap(_ => ''), @@ -231,6 +235,7 @@ export class CommentService extends BaseHttpService { comment.keywordsFromQuestioner = comment.keywordsFromQuestioner ? JSON.parse(comment.keywordsFromQuestioner as unknown as string) : null; comment.keywordsFromSpacy = comment.keywordsFromSpacy ? JSON.parse(comment.keywordsFromSpacy as unknown as string) : null; + console.log(comment); return comment; }