diff --git a/src/app/pages/chat/chat.page.ts b/src/app/pages/chat/chat.page.ts index 4fe27b30a..e0e210b80 100644 --- a/src/app/pages/chat/chat.page.ts +++ b/src/app/pages/chat/chat.page.ts @@ -32,6 +32,8 @@ import { EventTrigger } from 'src/app/services/eventTrigger.service'; import { RochetChatConnectorService } from 'src/app/services/chat/rochet-chat-connector.service'; import { RouteService } from 'src/app/services/route.service'; import { Plugins } from '@capacitor/core'; +import { ChangeDetectorRef } from '@angular/core'; + const { App } = Plugins; @@ -128,6 +130,7 @@ export class ChatPage implements OnInit { private RochetChatConnectorService: RochetChatConnectorService, private zone: NgZone, public RouteService: RouteService, + private ChangeDetectorRef: ChangeDetectorRef ) { this.headers = new HttpHeaders();; @@ -175,8 +178,18 @@ export class ChatPage implements OnInit { } }); + this.ChatSystemService.setMainChangeDetector(()=> { + this.changeDetector() + }) + } + changeDetector = () => { + console.log('run detection') + this.ChangeDetectorRef.detectChanges() + } + + ngOnDestroy() { // this.setStatus('offline'); this.routerSubscription?.unsubscribe(); diff --git a/src/app/pages/chat/group-messages/group-messages.page.html b/src/app/pages/chat/group-messages/group-messages.page.html index 86a3a4b28..295800e6f 100644 --- a/src/app/pages/chat/group-messages/group-messages.page.html +++ b/src/app/pages/chat/group-messages/group-messages.page.html @@ -1,6 +1,6 @@ -
+
@@ -45,7 +45,7 @@ - +
@@ -277,7 +277,7 @@ - +
{ + this.changeDetector() + }) } catch (error) { setTimeout(() => { this.open() @@ -151,6 +156,12 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { } } + + changeDetector = () => { + console.log('run detection page') + this.ChangeDetectorRef.detectChanges() + } + ngOnInit() { this.loggedUser = this.loggedUserChat; diff --git a/src/app/pages/chat/messages/messages.page.ts b/src/app/pages/chat/messages/messages.page.ts index b28b048a0..fb613e750 100644 --- a/src/app/pages/chat/messages/messages.page.ts +++ b/src/app/pages/chat/messages/messages.page.ts @@ -35,6 +35,7 @@ import { NotificationsService } from 'src/app/services/notifications.service'; import { RochetChatConnectorService } from 'src/app/services/chat/rochet-chat-connector.service' import { FileValidatorService } from "src/app/services/file/file-validator.service" import { sanitize } from "sanitize-filename-ts"; +import { ChangeDetectorRef } from '@angular/core'; @@ -121,7 +122,8 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { private fileOpener: FileOpener, private router: Router, public RochetChatConnectorService: RochetChatConnectorService, - private FileValidatorService: FileValidatorService + private FileValidatorService: FileValidatorService, + private ChangeDetectorRef: ChangeDetectorRef ) { try { @@ -140,6 +142,10 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { this.ChatSystemService.getDmRoom(this.roomId).loadHistory({}) this.ChatSystemService.getDmRoom(this.roomId).scrollDown = this.scrollToBottomClicked this.ChatSystemService.openRoom(this.roomId) + this.ChatSystemService.getDmRoom(this.roomId).setChangeDetector(()=> { + + this.changeDetector() + }) setTimeout(() => { this.scrollToBottomClicked() @@ -147,8 +153,11 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { } catch (error) { //alert(error) } + } - + changeDetector = () => { + console.log('run detection page') + this.ChangeDetectorRef.detectChanges() } ngOnInit() { diff --git a/src/app/services/chat/chat-system.service.ts b/src/app/services/chat/chat-system.service.ts index 175a72db1..551d9aba8 100644 --- a/src/app/services/chat/chat-system.service.ts +++ b/src/app/services/chat/chat-system.service.ts @@ -48,6 +48,7 @@ export class ChatSystemService { loadingUsers = false onRoomsLoad = new Subscribe({ execute: false, deleteOnExecute: true }) + private mainChangeDetector: Function = () => {} constructor( @@ -66,7 +67,7 @@ export class ChatSystemService { private AttachmentsService: AttachmentsService, private NetworkServiceService: NetworkServiceService, private ViewedMessageService: ViewedMessageService, - private notificationService: NotificationsService + private notificationService: NotificationsService, ) { @@ -148,9 +149,15 @@ export class ChatSystemService { }); } } catch(error) {} + } + setMainChangeDetector(x:Function) { + this.mainChangeDetector = x + } - + runMainChangeDetector() { + console.log("change") + this.mainChangeDetector() } loadChat() { diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index 8b9f60be1..07037a32b 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -25,6 +25,7 @@ import { ChatSystemService } from './chat-system.service'; import { ViewedMessageService } from './viewed-message.service' import * as FIFOProcessQueue from 'fifo-process-queue'; import { NotificationsService } from '../notifications.service'; +import { ChangeDetectorRef } from '@angular/core'; @Injectable({ providedIn: 'root' @@ -84,6 +85,7 @@ export class RoomService { sortRoomList = () => { } chatServiceDeleteRoom = (roomId) => { } + private changeDetector: Function = () => {} constructor( public RochetChatConnectorService: RochetChatConnectorService, @@ -190,6 +192,11 @@ export class RoomService { } + setChangeDetector(x:Function) { + console.log("set change detector") + this.changeDetector = x + } + get online() { if (!this.isGroup) { @@ -372,8 +379,6 @@ export class RoomService { } this.messageUnread = true - - // this.sortRoomList() setTimeout(() => { this.scrollDown() }, 50) @@ -386,6 +391,7 @@ export class RoomService { this.name = ChatMessage.msg } + this.changeDetector() setTimeout(() => { done() }, 5) diff --git a/src/app/services/notifications.service.ts b/src/app/services/notifications.service.ts index 0ce3fde6c..750711340 100644 --- a/src/app/services/notifications.service.ts +++ b/src/app/services/notifications.service.ts @@ -14,9 +14,10 @@ import { notificationObject } from '../models/notifications'; import { Capacitor } from '@capacitor/core'; import { AngularFireMessaging } from '@angular/fire/messaging'; import { NotificationHolderService } from 'src/app/store/notification-holder.service'; - +import { ChatService } from 'src/app/services/chat.service'; import { FCM } from '@capacitor-community/fcm'; - +import { ChatSystemService } from './chat/chat-system.service'; +import {ChatController} from 'src/app/controller/chat' @Injectable({ providedIn: 'root' @@ -42,6 +43,8 @@ export class NotificationsService { notificationReceived: EventEmitter = new EventEmitter(); token = '' + ChatController = ChatController + constructor( private http: HttpClient, private storageService: StorageService, @@ -82,7 +85,7 @@ export class NotificationsService { }) .catch((error) => { console.log("Register device error", error) }) - + } catch (error) { console.log("Granted permission error", error) } @@ -199,6 +202,7 @@ export class NotificationsService { this.active = true console.log('NOtification Listener', notification) this.storenotification(notification) + this.chatNotification(notification) } @@ -206,11 +210,13 @@ export class NotificationsService { } else { this.afMessaging.messages.subscribe((notification) => { + console.log(notification) this.storenotification(notification) this.notificationReceived.emit(); this.eventtrigger.publishSomeData({ notification: "recive" }) + this.chatNotification(notification) // Handle the received message, e.g., show a notification }); } @@ -393,4 +399,13 @@ export class NotificationsService { // })() } + + chatNotification(_notification) { + const notification = this.NotificationHolderService.stractureNotificationObject(_notification) + + if (notification?.notification?.data?.Service === "chat" || notification?.Service === "chat") { + this.ChatController.ChatSystemService.runMainChangeDetector() + } + } + } diff --git a/src/app/shared/chat/group-messages/group-messages.page.ts b/src/app/shared/chat/group-messages/group-messages.page.ts index 002fca5f2..140f92715 100644 --- a/src/app/shared/chat/group-messages/group-messages.page.ts +++ b/src/app/shared/chat/group-messages/group-messages.page.ts @@ -30,7 +30,7 @@ import { SessionStore } from 'src/app/store/session.service'; import { ViewMediaPage } from 'src/app/modals/view-media/view-media.page'; import { PermissionService } from 'src/app/services/permission.service'; import { FileValidatorService } from "src/app/services/file/file-validator.service" - +import { ChangeDetectorRef } from '@angular/core'; @Component({ selector: 'app-group-messages', templateUrl: './group-messages.page.html', @@ -103,7 +103,8 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe private platform: Platform, private fileOpener: FileOpener, public p: PermissionService, - private FileValidatorService: FileValidatorService + private FileValidatorService: FileValidatorService, + private ChangeDetectorRef: ChangeDetectorRef ) { this.ChatSystemService.getUser() @@ -119,7 +120,9 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe this.ChatSystemService.openRoom(this.roomId) this.ChatSystemService.getGroupRoom(this.roomId).scrollDown = this.scrollToBottomClicked this.groupNameFormart = this.ChatSystemService.getGroupRoom(this.roomId).name.split('-').join(' ') - + this.ChatSystemService.getGroupRoom(this.roomId).setChangeDetector(()=> { + this.changeDetector() + }) this.showAvatar = false setTimeout(() => { @@ -131,6 +134,12 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe } + changeDetector = () => { + console.log('run detection shared') + this.ChangeDetectorRef.detectChanges() + } + + ngOnInit() { this.loggedUser = this.loggedUserChat; //setTimeout(() => { diff --git a/src/app/shared/chat/messages/messages.page.ts b/src/app/shared/chat/messages/messages.page.ts index 9a0cb18f1..8ef5e2ece 100644 --- a/src/app/shared/chat/messages/messages.page.ts +++ b/src/app/shared/chat/messages/messages.page.ts @@ -34,6 +34,7 @@ import { ViewMediaPage } from 'src/app/modals/view-media/view-media.page'; import { ChatMessageDebuggingPage } from 'src/app/shared/popover/chat-message-debugging/chat-message-debugging.page'; import { PermissionService } from 'src/app/services/permission.service'; import { FileValidatorService } from "src/app/services/file/file-validator.service" +import { ChangeDetectorRef } from '@angular/core'; const IMAGE_DIR = 'stored-images'; @@ -123,7 +124,8 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy private platform: Platform, private fileOpener: FileOpener, public p: PermissionService, - private FileValidatorService: FileValidatorService + private FileValidatorService: FileValidatorService, + private ChangeDetectorRef: ChangeDetectorRef ) { // update this.checkAudioPermission() @@ -138,6 +140,11 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy this.ChatSystemService.openRoom(this.roomId) + this.ChatSystemService.getDmRoom(this.roomId) + this.ChatSystemService.getDmRoom(this.roomId).setChangeDetector(()=> { + this.changeDetector() + }) + this.showAvatar = false @@ -154,6 +161,12 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy } + changeDetector = () => { + console.log('run detection shared') + this.ChangeDetectorRef.detectChanges() + } + + async ChatMessageDebuggingPage() { const modal = await this.modalController.create({ diff --git a/src/app/store/notification-holder.service.ts b/src/app/store/notification-holder.service.ts index 4748c0d5a..6d8c80049 100644 --- a/src/app/store/notification-holder.service.ts +++ b/src/app/store/notification-holder.service.ts @@ -114,6 +114,74 @@ export class NotificationHolderService { } + stractureNotificationObject(notification) { + const element = notification + let notificationObject; + + if (element.notification) { + + notificationObject = { + id: notification?.id || uuidv4(), + title: element.notification.title, + Service: element.data.Service, + Object: element.data.Object, + IdObject: element.data.IdObject, + FolderId: element.data.FolderId, + body: element.notification.body, + dateInit: this.getFormatedTime(element.data.dateInit), + dateEnd: this.getFormatedTime(element.data.dateEnd), + Location: element.data.Location, + TypeAgenda: element.data.TypeAgenda, + Role: element.data.Role, + Status: element.data.Status, + read: false, + } + + } else if (element.data) { + notificationObject = { + id: notification?.id || uuidv4(), + title: element.title, + Service: element.data.Service, + Object: element.data.Object, + IdObject: element.data.IdObject, + FolderId: element.data.FolderId, + body: element.body, + dateInit: this.getFormatedTime(element.data.dateInit), + dateEnd: this.getFormatedTime(element.data.dateEnd), + Location: element.data.Location, + TypeAgenda: element.data.TypeAgenda, + Role: element.data.Role, + Status: element.data.Status, + read: false, + } + + } else { + { + notificationObject = { + id: notification?.id || uuidv4(), + FolderId: element.FolderId, + IdObject: element.IdObject, + Location: element.Location, + Object: element.Object, + Role: element.Role, + Service: element.Service, + Status: element.Status, + TypeAgenda: element.TypeAgenda, + body: element.body, + dateEnd: element.dateEnd, + dateInit: element.dateInit, + index: element.index, + title: element.title, + read: false, + } + } + } + + notificationObject.hashCode = (SHA1(notification)).toString() + + return notificationObject + } + addNotification(notification) {