Skip to content
Snippets Groups Projects
Commit 77eaf923 authored by Mohammad Alayoub's avatar Mohammad Alayoub
Browse files

filter profanity after updating the room

parent 310ca52b
Branches
Tags
No related merge requests found
...@@ -43,7 +43,7 @@ export class CommentAnswerComponent implements OnInit { ...@@ -43,7 +43,7 @@ export class CommentAnswerComponent implements OnInit {
this.isStudent = false; this.isStudent = false;
} }
this.route.params.subscribe(params => { this.route.params.subscribe(params => {
this.roomDataService.getComment(params['commentId']).subscribe(comment => { this.commentService.getComment(params['commentId']).subscribe(comment => {
this.comment = comment; this.comment = comment;
this.answer = this.comment.answer; this.answer = this.comment.answer;
this.isLoading = false; this.isLoading = false;
......
...@@ -98,6 +98,12 @@ export class CommentComponent implements OnInit, AfterViewInit { ...@@ -98,6 +98,12 @@ export class CommentComponent implements OnInit, AfterViewInit {
this.inAnswerView = !this.router.url.includes('comments'); this.inAnswerView = !this.router.url.includes('comments');
} }
checkProfanity(){
if (!this.router.url.includes('moderator/comments')) {
this.roomDataService.checkProfanity(this.comment);
}
}
ngAfterViewInit(): void { ngAfterViewInit(): void {
this.isExpandable = this.commentBody.getRenderedHeight() > CommentComponent.COMMENT_MAX_HEIGHT; this.isExpandable = this.commentBody.getRenderedHeight() > CommentComponent.COMMENT_MAX_HEIGHT;
if (!this.isExpandable) { if (!this.isExpandable) {
...@@ -108,12 +114,6 @@ export class CommentComponent implements OnInit, AfterViewInit { ...@@ -108,12 +114,6 @@ export class CommentComponent implements OnInit, AfterViewInit {
} }
} }
checkProfanity(){
if (!this.router.url.includes('moderator/comments')) {
this.roomDataService.checkProfanity(this.comment);
}
}
toggleExpand(evt: MouseEvent) { toggleExpand(evt: MouseEvent) {
this.isExpanded = !this.isExpanded; this.isExpanded = !this.isExpanded;
if (this.isExpanded) { if (this.isExpanded) {
......
...@@ -8,6 +8,7 @@ import { CorrectWrong } from '../../models/correct-wrong.enum'; ...@@ -8,6 +8,7 @@ import { CorrectWrong } from '../../models/correct-wrong.enum';
import { RoomService } from '../http/room.service'; import { RoomService } from '../http/room.service';
import { TopicCloudAdminService } from './topic-cloud-admin.service'; import { TopicCloudAdminService } from './topic-cloud-admin.service';
import { ProfanityFilter, Room } from '../../models/room'; import { ProfanityFilter, Room } from '../../models/room';
import { WsRoomService } from '..//websockets/ws-room.service';
export interface UpdateInformation { export interface UpdateInformation {
type: 'CommentCreated' | 'CommentPatched' | 'CommentHighlighted' | 'CommentDeleted'; type: 'CommentCreated' | 'CommentPatched' | 'CommentHighlighted' | 'CommentDeleted';
...@@ -93,11 +94,13 @@ export class RoomDataService { ...@@ -93,11 +94,13 @@ export class RoomDataService {
private _currentRoomId: string = null; private _currentRoomId: string = null;
private _savedCommentsBeforeFilter = new Map(); private _savedCommentsBeforeFilter = new Map();
private _savedCommentsAfterFilter = new Map(); private _savedCommentsAfterFilter = new Map();
private room: Room;
constructor(private wsCommentService: WsCommentService, constructor(private wsCommentService: WsCommentService,
private commentService: CommentService, private commentService: CommentService,
private roomService: RoomService, private roomService: RoomService,
private topicCloudAdminService: TopicCloudAdminService) { private topicCloudAdminService: TopicCloudAdminService,
private wsRoomService: WsRoomService) {
} }
get currentRoomData() { get currentRoomData() {
...@@ -127,38 +130,43 @@ export class RoomDataService { ...@@ -127,38 +130,43 @@ export class RoomDataService {
return tempSubject.asObservable(); return tempSubject.asObservable();
} }
getComment(id: string): Observable<Comment> { public checkProfanity(comment: Comment){
if (!this._fastCommentAccess[id]) { const finish = new Subject<boolean>();
const comment = new Subject<Comment>(); const subscription = finish.asObservable().subscribe(_ => {
this.commentService.getComment(id).subscribe(c => { if (this.room.profanityFilter !== ProfanityFilter.deactived) {
comment.body = this._savedCommentsAfterFilter.get(comment.id);
} else {
comment.body = this._savedCommentsBeforeFilter.get(comment.id);
}
subscription.unsubscribe();
});
if (!this._savedCommentsAfterFilter.get(comment.id) || !this.room) {
if (!this.room) {
this.roomService.getRoom(localStorage.getItem('roomId')).subscribe(room => { this.roomService.getRoom(localStorage.getItem('roomId')).subscribe(room => {
if (room.profanityFilter) { this.room = room;
c.body = this.filterCommentOfProfanity(room, c); this.setCommentBody(comment);
} finish.next(true);
comment.next(c);
}); });
}); } else {
return comment.asObservable(); this.setCommentBody(comment);
finish.next(true);
}
} else { } else {
this.checkProfanity(this._fastCommentAccess[id]); finish.next(true);
return of(this._fastCommentAccess[id]);
} }
} }
public checkProfanity(comment: Comment) { private setCommentBody(comment: Comment) {
this.roomService.getRoom(localStorage.getItem('roomId')).subscribe(room => { this._savedCommentsBeforeFilter.set(comment.id, comment.body);
if (room.profanityFilter !== ProfanityFilter.deactived) { this._savedCommentsAfterFilter.set(comment.id, this.filterCommentOfProfanity(this.room, comment));
comment.body = this._savedCommentsAfterFilter.get(comment.id);
} else {
comment.body = this._savedCommentsBeforeFilter.get(comment.id);
}
});
} }
private setCommentBodies(comment: Comment) { private filterAllCommentsBodies(){
this.roomService.getRoom(localStorage.getItem('roomId')).subscribe(room => { this._currentComments.forEach(comment => {
this._savedCommentsBeforeFilter.set(comment.id, comment.body); comment.body = this._savedCommentsBeforeFilter.get(comment.id);
this._savedCommentsAfterFilter.set(comment.id, this.filterCommentOfProfanity(room, comment)); this.setCommentBody(comment);
this.checkProfanity(comment);
}); });
} }
...@@ -185,14 +193,24 @@ export class RoomDataService { ...@@ -185,14 +193,24 @@ export class RoomDataService {
this._wsCommentServiceSubscription.unsubscribe(); this._wsCommentServiceSubscription.unsubscribe();
} }
this._wsCommentServiceSubscription = this.wsCommentService.getCommentStream(roomId) this._wsCommentServiceSubscription = this.wsCommentService.getCommentStream(roomId)
.subscribe(msg => this.onMessageReceive(msg)); .subscribe(msg => this.onMessageReceive(msg));
this.commentService.getAckComments(roomId).subscribe(comments => { this.roomService.getRoom(roomId).subscribe(room => {
this._currentComments = comments; this.room = room;
for (const comment of comments) { this.commentService.getAckComments(roomId).subscribe(comments => {
this.setCommentBodies(comment); this._currentComments = comments;
this._fastCommentAccess[comment.id] = comment; for (const comment of comments) {
this.setCommentBody(comment);
this._fastCommentAccess[comment.id] = comment;
}
this.triggerUpdate(UpdateType.force, null);
});
});
this.wsRoomService.getRoomStream(roomId).subscribe(msg => {
const message = JSON.parse(msg.body);
if (message.type === 'RoomPatched') {
this.room = message.payload.changes;
this.filterAllCommentsBodies();
} }
this.triggerUpdate(UpdateType.force, null);
}); });
} }
...@@ -242,7 +260,7 @@ export class RoomDataService { ...@@ -242,7 +260,7 @@ export class RoomDataService {
this.commentService.getComment(c.id).subscribe(comment => { this.commentService.getComment(c.id).subscribe(comment => {
this._fastCommentAccess[comment.id] = comment; this._fastCommentAccess[comment.id] = comment;
this._currentComments.push(comment); this._currentComments.push(comment);
this.setCommentBodies(comment); this.setCommentBody(comment);
this.triggerUpdate(UpdateType.commentStream, { this.triggerUpdate(UpdateType.commentStream, {
type: 'CommentCreated', type: 'CommentCreated',
finished: true, finished: true,
......
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