Skip to content
Snippets Groups Projects
Commit 2cdc9dce authored by Tom Käsler's avatar Tom Käsler
Browse files

Unsubscribe from comment stream

Refactor room pages and move attributes needed in all components to parent component.
parent de8dd1ef
Branches
Tags
No related merge requests found
...@@ -37,8 +37,6 @@ export class RoomCreatorPageComponent extends RoomPageComponent implements OnIni ...@@ -37,8 +37,6 @@ export class RoomCreatorPageComponent extends RoomPageComponent implements OnIni
moderatorCommentCounter: number; moderatorCommentCounter: number;
urlToCopy = 'https://frag.jetzt/participant/room/'; urlToCopy = 'https://frag.jetzt/participant/room/';
listenerFn: () => void;
constructor(protected roomService: RoomService, constructor(protected roomService: RoomService,
protected notification: NotificationService, protected notification: NotificationService,
protected route: ActivatedRoute, protected route: ActivatedRoute,
...@@ -51,7 +49,7 @@ export class RoomCreatorPageComponent extends RoomPageComponent implements OnIni ...@@ -51,7 +49,7 @@ export class RoomCreatorPageComponent extends RoomPageComponent implements OnIni
private liveAnnouncer: LiveAnnouncer, private liveAnnouncer: LiveAnnouncer,
private _r: Renderer2, private _r: Renderer2,
public eventService: EventService) { public eventService: EventService) {
super(roomService, route, location, wsCommentService, commentService); super(roomService, route, location, wsCommentService, commentService, eventService);
langService.langEmitter.subscribe(lang => translateService.use(lang)); langService.langEmitter.subscribe(lang => translateService.use(lang));
} }
...@@ -89,11 +87,6 @@ export class RoomCreatorPageComponent extends RoomPageComponent implements OnIni ...@@ -89,11 +87,6 @@ export class RoomCreatorPageComponent extends RoomPageComponent implements OnIni
}); });
} }
ngOnDestroy() {
this.listenerFn();
this.eventService.makeFocusOnInputFalse();
}
public announce() { public announce() {
this.liveAnnouncer.clear(); this.liveAnnouncer.clear();
this.liveAnnouncer.announce('Du befindest dich in der von dir erstellten Sitzung. ' + this.liveAnnouncer.announce('Du befindest dich in der von dir erstellten Sitzung. ' +
......
...@@ -28,8 +28,6 @@ export class RoomModeratorPageComponent extends RoomPageComponent implements OnI ...@@ -28,8 +28,6 @@ export class RoomModeratorPageComponent extends RoomPageComponent implements OnI
moderatorCommentCounter: number; moderatorCommentCounter: number;
viewModuleCount = 1; viewModuleCount = 1;
listenerFn: () => void;
constructor(protected location: Location, constructor(protected location: Location,
protected roomService: RoomService, protected roomService: RoomService,
protected route: ActivatedRoute, protected route: ActivatedRoute,
...@@ -41,7 +39,7 @@ export class RoomModeratorPageComponent extends RoomPageComponent implements OnI ...@@ -41,7 +39,7 @@ export class RoomModeratorPageComponent extends RoomPageComponent implements OnI
public eventService: EventService, public eventService: EventService,
private liveAnnouncer: LiveAnnouncer, private liveAnnouncer: LiveAnnouncer,
private _r: Renderer2) { private _r: Renderer2) {
super(roomService, route, location, wsCommentService, commentService); super(roomService, route, location, wsCommentService, commentService, eventService);
langService.langEmitter.subscribe(lang => translateService.use(lang)); langService.langEmitter.subscribe(lang => translateService.use(lang));
} }
...@@ -123,11 +121,6 @@ export class RoomModeratorPageComponent extends RoomPageComponent implements OnI ...@@ -123,11 +121,6 @@ export class RoomModeratorPageComponent extends RoomPageComponent implements OnI
}); });
} }
ngOnDestroy() {
this.listenerFn();
this.eventService.makeFocusOnInputFalse();
}
public announce() { public announce() {
this.liveAnnouncer.announce('Du befindest dich in der Sitzung in der du als Moderator gewählt wurdest. ' + this.liveAnnouncer.announce('Du befindest dich in der Sitzung in der du als Moderator gewählt wurdest. ' +
'Drücke die Taste 1 um auf die Fragen-Übersicht zu gelangen, ' + 'Drücke die Taste 1 um auf die Fragen-Übersicht zu gelangen, ' +
......
...@@ -28,8 +28,6 @@ export class RoomParticipantPageComponent extends RoomPageComponent implements O ...@@ -28,8 +28,6 @@ export class RoomParticipantPageComponent extends RoomPageComponent implements O
deviceType = localStorage.getItem('deviceType'); deviceType = localStorage.getItem('deviceType');
user: User; user: User;
listenerFn: () => void;
constructor(protected location: Location, constructor(protected location: Location,
protected roomService: RoomService, protected roomService: RoomService,
protected route: ActivatedRoute, protected route: ActivatedRoute,
...@@ -41,7 +39,7 @@ export class RoomParticipantPageComponent extends RoomPageComponent implements O ...@@ -41,7 +39,7 @@ export class RoomParticipantPageComponent extends RoomPageComponent implements O
private liveAnnouncer: LiveAnnouncer, private liveAnnouncer: LiveAnnouncer,
private _r: Renderer2, private _r: Renderer2,
public eventService: EventService) { public eventService: EventService) {
super(roomService, route, location, wsCommentService, commentService); super(roomService, route, location, wsCommentService, commentService, eventService);
langService.langEmitter.subscribe(lang => translateService.use(lang)); langService.langEmitter.subscribe(lang => translateService.use(lang));
} }
...@@ -74,11 +72,6 @@ export class RoomParticipantPageComponent extends RoomPageComponent implements O ...@@ -74,11 +72,6 @@ export class RoomParticipantPageComponent extends RoomPageComponent implements O
}); });
} }
ngOnDestroy() {
this.listenerFn();
this.eventService.makeFocusOnInputFalse();
}
public announce() { public announce() {
this.liveAnnouncer.clear(); this.liveAnnouncer.clear();
this.liveAnnouncer.announce('Du befindest dich in der Sitzung mit dem von dir eingegebenen Sitzungs-Code. ' + this.liveAnnouncer.announce('Du befindest dich in der Sitzung mit dem von dir eingegebenen Sitzungs-Code. ' +
......
import { Component, ElementRef, Input, OnInit, ViewChild } from '@angular/core'; import { Component, ElementRef, Input, OnInit, OnDestroy, ViewChild } from '@angular/core';
import { Comment } from '../../../models/comment'; import { Comment } from '../../../models/comment';
import { CommentService } from '../../../services/http/comment.service'; import { CommentService } from '../../../services/http/comment.service';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
...@@ -26,7 +26,7 @@ import { Router } from '@angular/router'; ...@@ -26,7 +26,7 @@ import { Router } from '@angular/router';
templateUrl: './comment-list.component.html', templateUrl: './comment-list.component.html',
styleUrls: ['./comment-list.component.scss'] styleUrls: ['./comment-list.component.scss']
}) })
export class CommentListComponent implements OnInit { export class CommentListComponent implements OnInit, OnDestroy {
@ViewChild('searchBox') searchField: ElementRef; @ViewChild('searchBox') searchField: ElementRef;
@Input() user: User; @Input() user: User;
@Input() roomId: string; @Input() roomId: string;
...@@ -114,6 +114,12 @@ export class CommentListComponent implements OnInit { ...@@ -114,6 +114,12 @@ export class CommentListComponent implements OnInit {
}); });
} }
ngOnDestroy() {
if (!this.freeze) {
this.commentStream.unsubscribe();
}
}
checkScroll(): void { checkScroll(): void {
const currentScroll = document.documentElement.scrollTop; const currentScroll = document.documentElement.scrollTop;
this.scroll = currentScroll >= 65; this.scroll = currentScroll >= 65;
......
import { Component, OnInit } from '@angular/core'; import { Component, OnInit, OnDestroy } from '@angular/core';
import { Room } from '../../../models/room'; import { Room } from '../../../models/room';
import { RoomService } from '../../../services/http/room.service'; import { RoomService } from '../../../services/http/room.service';
import { ActivatedRoute } from '@angular/router'; import { ActivatedRoute } from '@angular/router';
import { Location } from '@angular/common'; import { Location } from '@angular/common';
import { WsCommentServiceService } from '../../../services/websockets/ws-comment-service.service'; import { WsCommentServiceService } from '../../../services/websockets/ws-comment-service.service';
import { CommentService } from '../../../services/http/comment.service'; import { CommentService } from '../../../services/http/comment.service';
import { EventService } from '../../../services/util/event.service';
import { Message } from '@stomp/stompjs'; import { Message } from '@stomp/stompjs';
import { Subscription } from 'rxjs';
@Component({ @Component({
selector: 'app-room-page', selector: 'app-room-page',
templateUrl: './room-page.component.html', templateUrl: './room-page.component.html',
styleUrls: ['./room-page.component.scss'] styleUrls: ['./room-page.component.scss']
}) })
export class RoomPageComponent implements OnInit { export class RoomPageComponent implements OnInit, OnDestroy {
room: Room = null; room: Room = null;
isLoading = true; isLoading = true;
commentCounter: number; commentCounter: number;
protected moderationEnabled = false; protected moderationEnabled = false;
protected sub: Subscription;
protected listenerFn: () => void;
constructor(protected roomService: RoomService, constructor(protected roomService: RoomService,
protected route: ActivatedRoute, protected route: ActivatedRoute,
protected location: Location, protected location: Location,
protected wsCommentService: WsCommentServiceService, protected wsCommentService: WsCommentServiceService,
protected commentService: CommentService protected commentService: CommentService,
protected eventService: EventService
) { ) {
} }
...@@ -32,6 +37,14 @@ export class RoomPageComponent implements OnInit { ...@@ -32,6 +37,14 @@ export class RoomPageComponent implements OnInit {
}); });
} }
ngOnDestroy() {
this.listenerFn();
this.eventService.makeFocusOnInputFalse();
if (this.sub) {
this.sub.unsubscribe();
}
}
protected afterRoomLoadHook() { protected afterRoomLoadHook() {
} }
...@@ -51,7 +64,7 @@ export class RoomPageComponent implements OnInit { ...@@ -51,7 +64,7 @@ export class RoomPageComponent implements OnInit {
.subscribe(commentCounter => { .subscribe(commentCounter => {
this.commentCounter = commentCounter; this.commentCounter = commentCounter;
}); });
this.wsCommentService.getCommentStream(this.room.id).subscribe((message: Message) => { this.sub = this.wsCommentService.getCommentStream(this.room.id).subscribe((message: Message) => {
const msg = JSON.parse(message.body); const msg = JSON.parse(message.body);
const payload = msg.payload; const payload = msg.payload;
if (msg.type === 'CommentCreated') { if (msg.type === 'CommentCreated') {
......
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