diff --git a/src/app/module/chat/data/data-source/message/message-local-data-source.service.ts b/src/app/module/chat/data/data-source/message/message-local-data-source.service.ts index 9e0305e12..34e42a5af 100644 --- a/src/app/module/chat/data/data-source/message/message-local-data-source.service.ts +++ b/src/app/module/chat/data/data-source/message/message-local-data-source.service.ts @@ -80,6 +80,17 @@ export class MessageLocalDataSourceService { // }) } + async setAllSenderToFalse() { + try { + await messageDataSource.transaction('rw', messageDataSource.message, async () => { + // Perform the update operation within the transaction + await messageDataSource.message.toCollection().modify({ sending: false }); + }); + console.log('All messages updated successfully.'); + } catch (error) { + console.error('Error updating messages:', error); + } + } async getLastMessageByRoomId(roomId: string): Promise> { try { 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 e8034b2e5..c00f7f5a7 100644 --- a/src/app/module/chat/data/repository/message-respository.service.ts +++ b/src/app/module/chat/data/repository/message-respository.service.ts @@ -41,6 +41,7 @@ export class MessageRepositoryService { const requestId = InstanceId +'@'+ uuidv4(); const roomId = entity.roomId + entity.sending = true const localActionResult = await this.messageLocalDataSourceService.sendMessage(entity) if(localActionResult.isOk()) { 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 7b1035e35..fb2823575 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 @@ -18,7 +18,10 @@ export class SyncMessageRepositoryService { private messageLiveDataSourceService: MessageLiveDataSourceService, private messageLiveSignalRDataSourceService: SignalRService, private messageLocalDataSourceService: MessageLocalDataSourceService - ) { } + ) { + + // this.messageLocalDataSourceService.setAllSenderToFalse(); + } async sendLocalMessages() { const messages = await this.messageLocalDataSourceService.getOfflineMessages() @@ -26,8 +29,12 @@ export class SyncMessageRepositoryService { if(messages.length >= 1) { for(const message of messages) { + + console.log('to upload', messages) const requestId = InstanceId +'@'+ uuidv4(); const DTO = MessageMapper.fromDomain(message, requestId) + + await this.messageLocalDataSourceService.update({sending: true, $id: message.$id}) const sendMessageResult = await this.messageLiveSignalRDataSourceService.sendMessage(DTO) if(sendMessageResult.isOk()) {