code refactor

This commit is contained in:
Peter Maquiran
2024-08-18 15:40:43 +01:00
parent ef12ff439d
commit 29d0a9b55e
39 changed files with 191 additions and 464 deletions
+40 -14
View File
@@ -1,34 +1,61 @@
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';
import { UserTypingAsyncService } from 'src/app/module/chat/data/async/socket/user-typing-async.service'
import { ChatServiceService } from 'src/app/module/chat/domain/chat-service.service'
import { skip } from 'rxjs/operators';
import { skip, switchMap } from 'rxjs/operators';
import { SessionStore } from 'src/app/store/session.service';
import { Subject, timer } from 'rxjs';
import { UserTypingLocalRepository } from './data/repository/user-typing-local-data-source.service';
@NgModule({
imports: [
],
providers: [
SyncMessageRepositoryService
],
imports: [],
providers: [],
declarations: [],
schemas: [],
entryComponents: []
})
export class ChatModule {
typingCallback: {[key: string]: Subject<any> } = {}
constructor(
private message: SyncMessageRepositoryService,
private SignalRService: SignalRService,
private UserTypingAsyncService: UserTypingAsyncService,
private ChatServiceService: ChatServiceService
private ChatServiceService: ChatServiceService,
private signalR: SignalRService,
private localDataSource: UserTypingLocalRepository,
) {
this.syncMessage()
this.listenToTyping()
}
async listenToTyping() {
this.signalR.getTyping().subscribe(async (e) => {
if(e?.roomId) {
// this.memoryDataSource.dispatch(removeUserTyping({data: {...e} as any}))
// this.memoryDataSource.dispatch(addUserTyping({data: {...e} as any}))
//
const value = await this.localDataSource.addUserTyping(e);
const id = e.roomId + '@' + e.userName
if(!this.typingCallback[id]) {
this.typingCallback[id] = new Subject()
this.typingCallback[id].pipe(
switchMap(() => timer(2000)),
).subscribe(() => {
console.log('111111==============')
// this.memoryDataSource.dispatch(removeUserTyping({data: {...e} as any}))
this.localDataSource.removeUserTyping(e)
})
} else {
this.typingCallback[id].next()
}
} else {
console.log('e--', e)
}
})
}
async syncMessage() {
const connection = this.SignalRService.getConnectionState()
@@ -45,8 +72,7 @@ export class ChatModule {
connection.subscribe((value) => {
if(value) {
// on connect
console.log('send local image')
this.message.sendLocalMessages()
this.ChatServiceService.sendLocalMessages()
}
})