mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
code refactor
This commit is contained in:
@@ -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()
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user