From d55450ccbbd8c48eeadf009f7725ebefa400f00f Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Wed, 7 Aug 2024 15:36:15 +0100 Subject: [PATCH] send messag on reconnect --- .../repository/message-respository.service.ts | 18 +++++++++++++----- .../sync-message-repository.service.ts | 9 ++++++--- .../chat/infra/socket/signal-r.service.ts | 3 ++- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/app/module/chat/data/repository/message-respository.service.ts b/src/app/module/chat/data/repository/message-respository.service.ts index 82bdd1c07..e8034b2e5 100644 --- a/src/app/module/chat/data/repository/message-respository.service.ts +++ b/src/app/module/chat/data/repository/message-respository.service.ts @@ -12,6 +12,7 @@ import { messageListDetermineChanges } from '../async/list/rooms/messageListChan import { MessageEntity } from '../../domain/entity/message'; import { InstanceId } from '../../domain/chat-service.service'; import { MessageMapper } from '../../domain/mapper/messageMapper'; +import { MessageOutPutDataDTO } from '../dto/message/messageOutputDTO'; @Injectable({ @@ -26,6 +27,15 @@ export class MessageRepositoryService { private messageLocalDataSourceService: MessageLocalDataSourceService ) {} + + async createMessageLocally(entity: MessageEntity) { + const requestId = InstanceId +'@'+ uuidv4(); + const roomId = entity.roomId + + return await this.messageLocalDataSourceService.sendMessage(entity) + + } + async sendMessage(entity: MessageEntity) { const requestId = InstanceId +'@'+ uuidv4(); @@ -35,7 +45,7 @@ export class MessageRepositoryService { if(localActionResult.isOk()) { const DTO = MessageMapper.fromDomain(entity, requestId) - const sendMessageResult = await this.messageLiveSignalRDataSourceService.sendMessage(DTO) + const sendMessageResult = await this.messageLiveSignalRDataSourceService.sendMessage(DTO) if(sendMessageResult.isOk()) { @@ -51,11 +61,9 @@ export class MessageRepositoryService { } return this.messageLocalDataSourceService.update({...clone, sending: false, roomId: entity.roomId}) - return ok(true) } else { - console.log('no message to upload', sendMessageResult.error) - return this.messageLocalDataSourceService.update({sending: false, $id: localActionResult.value}) - return err(false) + await this.messageLocalDataSourceService.update({sending: false, $id: localActionResult.value}) + return err('no connection') } } else { diff --git a/src/app/module/chat/data/service/sync-repository/sync-message-repository.service.ts b/src/app/module/chat/data/service/sync-repository/sync-message-repository.service.ts index 621cf9b9d..7b1035e35 100644 --- a/src/app/module/chat/data/service/sync-repository/sync-message-repository.service.ts +++ b/src/app/module/chat/data/service/sync-repository/sync-message-repository.service.ts @@ -6,6 +6,7 @@ import { MessageRemoteDataSourceService } from '../../data-source/message/messag import { InstanceId } from '../../../domain/chat-service.service'; import { v4 as uuidv4 } from 'uuid' import { MessageMapper } from 'src/app/module/chat/domain/mapper/messageMapper' +import { MessageOutPutDataDTO } from '../../dto/message/messageOutputDTO'; @Injectable({ providedIn: 'root' @@ -23,11 +24,11 @@ export class SyncMessageRepositoryService { const messages = await this.messageLocalDataSourceService.getOfflineMessages() if(messages.length >= 1) { - console.log('to send '+ messages.length) + for(const message of messages) { const requestId = InstanceId +'@'+ uuidv4(); const DTO = MessageMapper.fromDomain(message, requestId) - const sendMessageResult = await this.messageLiveSignalRDataSourceService.sendMessage(DTO) + const sendMessageResult = await this.messageLiveSignalRDataSourceService.sendMessage(DTO) if(sendMessageResult.isOk()) { @@ -42,7 +43,9 @@ export class SyncMessageRepositoryService { $id : message.$id } - return this.messageLocalDataSourceService.update({...clone, sending: false, roomId: message.roomId}) + this.messageLocalDataSourceService.update({...clone, sending: false, roomId: message.roomId}) + } else { + this.messageLocalDataSourceService.update({sending: false, $id: message.$id}) } } diff --git a/src/app/module/chat/infra/socket/signal-r.service.ts b/src/app/module/chat/infra/socket/signal-r.service.ts index a0967fc0c..c8833ae8e 100644 --- a/src/app/module/chat/infra/socket/signal-r.service.ts +++ b/src/app/module/chat/infra/socket/signal-r.service.ts @@ -8,6 +8,7 @@ import { MessageOutPutDataDTO } from '../../data/dto/message/messageOutputDTO'; import { MessageDeleteInputDTO } from '../../data/dto/message/messageDeleteInputDTO'; import { object, z } from 'zod'; import { switchMap } from 'rxjs/operators'; +import { Result } from 'neverthrow'; const { App } = Plugins; @@ -145,7 +146,7 @@ export class SignalRService { return this.connectingSubject.asObservable(); } - async sendMessage(data: Object) { + async sendMessage(data: Object): Promise> { return await this.connection.sendMessage(data as any) }