mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
load messages
This commit is contained in:
@@ -3,6 +3,8 @@ import { SignalRService } from 'src/app/module/chat/infra/socket/signal-r.servic
|
||||
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 { SessionStore } from 'src/app/store/session.service';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
@@ -21,21 +23,36 @@ export class ChatModule {
|
||||
private message: SyncMessageRepositoryService,
|
||||
private SignalRService: SignalRService,
|
||||
private UserTypingAsyncService: UserTypingAsyncService,
|
||||
private ChatServiceService: ChatServiceService
|
||||
private ChatServiceService: ChatServiceService
|
||||
) {
|
||||
|
||||
this.triggerToSendOfflineMessages()
|
||||
this.syncMessage()
|
||||
}
|
||||
|
||||
|
||||
triggerToSendOfflineMessages() {
|
||||
const result = this.SignalRService.getConnectionState()
|
||||
syncMessage() {
|
||||
const connection = this.SignalRService.getConnectionState()
|
||||
|
||||
result.subscribe((value) => {
|
||||
connection.pipe(
|
||||
skip(1) // Skip the first value
|
||||
).subscribe((value)=> {
|
||||
if(value) {
|
||||
// on reconnect
|
||||
this.ChatServiceService.asyncAllRoomMessage();
|
||||
}
|
||||
});
|
||||
|
||||
connection.subscribe((value) => {
|
||||
if(value) {
|
||||
// on connect
|
||||
console.log('send local image')
|
||||
this.message.sendLocalMessages()
|
||||
}
|
||||
})
|
||||
|
||||
// on page reload sync
|
||||
if(!(!SessionStore.user.Inactivity || !SessionStore.exist)) {
|
||||
this.ChatServiceService.asyncAllRoomMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ export class MessageLocalDataSourceService extends DexieRepository<MessageTable>
|
||||
|
||||
constructor() {
|
||||
super(chatDatabase.message, MessageTableSchema)
|
||||
|
||||
this.setAllSenderToFalse();
|
||||
}
|
||||
|
||||
async setAllSenderToFalse() {
|
||||
@@ -195,6 +197,10 @@ export class MessageLocalDataSourceService extends DexieRepository<MessageTable>
|
||||
.filter(msg => typeof msg.id !== 'string' && msg.sending == false)
|
||||
.toArray();
|
||||
|
||||
|
||||
console.log("======================================================================")
|
||||
console.log({localMessage:allMessages})
|
||||
|
||||
return allMessages as MessageEntity[];
|
||||
} catch (error) {
|
||||
console.error('Error fetching messages:', error);
|
||||
|
||||
@@ -26,7 +26,7 @@ export class MessageRemoteDataSourceService {
|
||||
}
|
||||
|
||||
|
||||
@APIReturn(MessageOutPutDTOSchema, 'get/Messages')
|
||||
// @APIReturn(MessageOutPutDTOSchema, 'get/Messages')
|
||||
async getMessagesFromRoom(id: string): DataSourceReturn<MessageOutPutDTO> {
|
||||
return await this.httpService.get(`${this.baseUrl}/Room/${id}/Messages`);
|
||||
}
|
||||
|
||||
@@ -51,8 +51,12 @@ export class SyncMessageRepositoryService {
|
||||
$id : message.$id
|
||||
}
|
||||
|
||||
console.log('send message local')
|
||||
|
||||
this.messageLocalDataSourceService.update(message.$id, {...clone, sending: false, roomId: message.roomId})
|
||||
} else {
|
||||
|
||||
console.log('erro send message')
|
||||
this.messageLocalDataSourceService.update(message.$id, {sending: false})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,10 +14,12 @@ export class SyncAllRoomMessagesService {
|
||||
) { }
|
||||
|
||||
async execute() {
|
||||
|
||||
|
||||
await this.RoomRepositoryService.list()
|
||||
const allRooms: RoomTable[] = await this.RoomRepositoryService.getRoomList()
|
||||
|
||||
if(allRooms) {
|
||||
console.log('allRooms', allRooms)
|
||||
for(const room of allRooms) {
|
||||
this.MessageRepositoryService.listAllMessagesByRoomId(room.id)
|
||||
}
|
||||
|
||||
@@ -45,10 +45,10 @@ export class SignalRConnection {
|
||||
hubConnection
|
||||
.start()
|
||||
.then(() => {
|
||||
this.hubConnection = hubConnection
|
||||
this.hasConnectOnce = true
|
||||
console.log('Connection started');
|
||||
this.connectionStateSubject.next(true);
|
||||
this.hubConnection = hubConnection
|
||||
this.join()
|
||||
this.addMessageListener()
|
||||
resolve(ok(hubConnection))
|
||||
|
||||
Reference in New Issue
Block a user