From a226f722aaf527572b134385b5e0b8a9679f97b1 Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Fri, 30 Sep 2022 16:55:09 +0100 Subject: [PATCH] improve --- src/app/services/chat/chat-system.service.ts | 52 +++++++++---------- src/app/services/chat/room.service.ts | 2 + .../shared/chat/new-group/new-group.page.ts | 11 ++-- 3 files changed, 35 insertions(+), 30 deletions(-) diff --git a/src/app/services/chat/chat-system.service.ts b/src/app/services/chat/chat-system.service.ts index 4e27dc131..1d5272e58 100644 --- a/src/app/services/chat/chat-system.service.ts +++ b/src/app/services/chat/chat-system.service.ts @@ -38,9 +38,6 @@ export class ChatSystemService { currentRoom: RoomService = null users: chatUser[] = [] sessionStore = SessionStore - - - delete = [] constructor( @@ -180,7 +177,7 @@ export class ChatSystemService { for (let roomData of rooms.result.update) { const roomId = this.getRoomId(roomData); - + if(roomData.t == 'd') { let error = false @@ -260,7 +257,6 @@ export class ChatSystemService { } } - await this.storage.set('Rooms', rooms); setTimeout(() => { @@ -309,7 +305,7 @@ export class ChatSystemService { */ subscribeToRoomUpdate(id, roomData) { - this.defaultSubtribe(id) + this.defaultSubtribe(id); this.prepareRoom(roomData); @@ -323,27 +319,30 @@ export class ChatSystemService { * @param id room id */ private defaultSubtribe(id: any) { + + const room = this.getRoomById(id); + + if(!room.subscribeAttempt) { + room.subscribeAttempt = true; + + this.RochetChatConnectorService.streamRoomMessages(id).then((subscription) => { + room.status.receive.message = true; + }) - this.RochetChatConnectorService.streamRoomMessages(id).then((subscription) => { - const room = this.getRoomById(id); - room.status.receive.message = true; - }) + this.RochetChatConnectorService.subStreamNotifyRoom(id, 'typing', false).then((subscription) => { + room.status.receive.typing = true; + // + }) + + this.RochetChatConnectorService.subStreamNotifyRoom(id, 'readMessage', false).then((subscription) => { + room.status.receive.readMessage = true; + }) + + this.RochetChatConnectorService.streamNotifyRoomDeleteMessage(id).then((subscription) => { + room.status.receive.deleteMessage = true; + }) + } - this.RochetChatConnectorService.subStreamNotifyRoom(id, 'typing', false).then((subscription) => { - const room = this.getRoomById(id); - room.status.receive.typing = true; - // - }) - - this.RochetChatConnectorService.subStreamNotifyRoom(id, 'readMessage', false).then((subscription) => { - const room = this.getRoomById(id); - room.status.receive.readMessage = true; - }) - - this.RochetChatConnectorService.streamNotifyRoomDeleteMessage(id).then((subscription) => { - const room = this.getRoomById(id); - room.status.receive.deleteMessage = true; - }) } private fix_updatedAt(message) { @@ -396,7 +395,6 @@ export class ChatSystemService { room.chatServiceDeleteRoom = this.deleteRoom // create individual room - if(this.isIndividual(roomData)) { this.dm[roomId] = room @@ -411,6 +409,8 @@ export class ChatSystemService { this.groupCount++ } + + this.defaultSubtribe(roomId) } else { // in this case room is already present, therefor it will only be necessary, // to redefine diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index 9b6db56a1..df86d73eb 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -64,6 +64,8 @@ export class RoomService { } } + subscribeAttempt = false + scrollDown = () => { } /** diff --git a/src/app/shared/chat/new-group/new-group.page.ts b/src/app/shared/chat/new-group/new-group.page.ts index 45e5a92af..86106459e 100644 --- a/src/app/shared/chat/new-group/new-group.page.ts +++ b/src/app/shared/chat/new-group/new-group.page.ts @@ -51,10 +51,13 @@ export class NewGroupPage implements OnInit{ ngOnInit() { this.task = this.dataService.get("task"); - this.groupName = this.task.Folio; - this.documents = this.dataService.get("documents"); - console.log(this.dataService.data); - this.dataService.set("newGroup", false); + if(this.task) { + this.groupName = this.task.Folio; + this.documents = this.dataService.get("documents"); + console.log(this.dataService.data); + this.dataService.set("newGroup", false); + } + } _ionChange(event) {