Files
doneit-web/src/app/module/chat/chat.module.ts
T

59 lines
1.5 KiB
TypeScript
Raw Normal View History

2024-08-07 15:23:23 +01:00
import { NgModule } from '@angular/core';
import { SignalRService } from 'src/app/module/chat/infra/socket/signal-r.service'
import { SyncMessageRepositoryService } from './data/service/sync-repository/sync-message-repository.service';
2024-08-13 10:52:35 +01:00
import { UserTypingAsyncService } from 'src/app/module/chat/data/async/socket/user-typing-async.service'
2024-08-14 15:29:16 +01:00
import { ChatServiceService } from 'src/app/module/chat/domain/chat-service.service'
2024-08-15 10:26:20 +01:00
import { skip } from 'rxjs/operators';
import { SessionStore } from 'src/app/store/session.service';
2024-08-13 10:52:35 +01:00
2024-08-07 15:23:23 +01:00
@NgModule({
imports: [
],
providers: [
SyncMessageRepositoryService
],
declarations: [],
schemas: [],
entryComponents: []
})
export class ChatModule {
constructor(
private message: SyncMessageRepositoryService,
2024-08-13 10:52:35 +01:00
private SignalRService: SignalRService,
2024-08-14 15:29:16 +01:00
private UserTypingAsyncService: UserTypingAsyncService,
2024-08-15 10:26:20 +01:00
private ChatServiceService: ChatServiceService
2024-08-07 15:23:23 +01:00
) {
2024-08-15 10:26:20 +01:00
this.syncMessage()
2024-08-07 15:23:23 +01:00
}
2024-08-15 10:26:20 +01:00
syncMessage() {
const connection = this.SignalRService.getConnectionState()
2024-08-07 15:23:23 +01:00
2024-08-15 10:26:20 +01:00
connection.pipe(
skip(1) // Skip the first value
).subscribe((value)=> {
2024-08-07 15:23:23 +01:00
if(value) {
2024-08-15 10:26:20 +01:00
// on reconnect
2024-08-14 15:29:16 +01:00
this.ChatServiceService.asyncAllRoomMessage();
2024-08-15 10:26:20 +01:00
}
});
connection.subscribe((value) => {
if(value) {
// on connect
console.log('send local image')
2024-08-07 15:23:23 +01:00
this.message.sendLocalMessages()
}
})
2024-08-15 10:26:20 +01:00
// on page reload sync
if(!(!SessionStore.user.Inactivity || !SessionStore.exist)) {
this.ChatServiceService.asyncAllRoomMessage();
}
2024-08-07 15:23:23 +01:00
}
}