fix server room duplication

This commit is contained in:
Peter Maquiran
2024-10-10 11:45:34 +01:00
parent cbe535899f
commit 7a7a60a333
3 changed files with 23 additions and 15 deletions
@@ -1,6 +1,5 @@
import { Injectable } from '@angular/core';
import { IMessage, MessageAttachmentSource, MessageEntity, MessageEntitySchema, } from '../../../../../core/chat/entity/message';
import { AttachmentLocalDataSource } from "src/app/module/chat/data/repository/attachment/attachment-local-repository.service";
import { z } from 'zod';
import { v4 as uuidv4 } from 'uuid';
import { InstanceId } from '../../chat-service.service';
@@ -11,8 +10,6 @@ import { err, Result } from 'neverthrow';
import { MessageMapper } from '../../mapper/messageMapper';
import { RoomType } from "src/app/core/chat/entity/group";
import { TracingType, XTracerAsync } from 'src/app/services/monitoring/opentelemetry/tracer';
import { MemberListLocalRepository } from 'src/app/module/chat/data/repository/member/member-list-local-repository.service'
import { SessionStore } from 'src/app/store/session.service';
import { MessageTable } from 'src/app/infra/database/dexie/instance/chat/schema/message';
import { MessageAttachmentFileType, MessageOutPutDataDTO } from 'src/app/core/chat/repository/dto/messageOutputDTO';
import { IMessageLocalRepository } from 'src/app/core/chat/repository/message/message-local-repository';
@@ -89,6 +89,9 @@ export class GetRoomListUseCaseService {
console.log({roomsToDelete, roomsToInsert, roomsToUpdate})
// sometime api return duplicated rooms
const insertedIds = []
if(roomsToInsert) {
const roomsToInsertEntity = GetRoomListMapper.toDomain(roomsToInsert)
for( const room of roomsToInsertEntity) {
@@ -109,8 +112,14 @@ export class GetRoomListUseCaseService {
}
} else {
// prevent to insert the same room due to server duplication
if(!insertedIds.find(e => room.id)) {
const createResult = this.roomLocalDataSourceService.insert(room)
insertedIds.push(room.id)
createResult.then((result) => {
if(result.isErr()) {
console.log('error', result.error)
@@ -119,6 +128,8 @@ export class GetRoomListUseCaseService {
}
}
}
}
if(roomsToUpdate.length >= 1) {
+6 -6
View File
@@ -1,11 +1,11 @@
export let versionData = {
"shortSHA": "9c65bee69",
"SHA": "9c65bee69c06222e66bc5e392de880411bff3d98",
"shortSHA": "cbe535899",
"SHA": "cbe535899f3c90deee7cfc9eddc1d4c18f3ac0be",
"branch": "feature/chat-new-api-peter",
"lastCommitAuthor": "'Peter Maquiran'",
"lastCommitTime": "'Wed Oct 9 16:28:51 2024 +0100'",
"lastCommitMessage": "add member repository",
"lastCommitNumber": "6090",
"changeStatus": "On branch feature/chat-new-api-peter\nYour branch is ahead of 'origin/feature/chat-new-api-peter' by 5 commits.\n (use \"git push\" to publish your local commits)\n\nChanges to be committed:\n (use \"git restore --staged <file>...\" to unstage)\n\tmodified: gabinete-digital-fo.code-workspace\n\tmodified: src/app/module/chat/data/repository/message/message-local-data-source.service.ts\n\tmodified: src/app/ui/chat/component/messages/messages.page.ts\n\tmodified: src/app/ui/chat/store/roomStore.ts",
"lastCommitTime": "'Thu Oct 10 11:08:32 2024 +0100'",
"lastCommitMessage": "fix message order on reconect",
"lastCommitNumber": "6091",
"changeStatus": "On branch feature/chat-new-api-peter\nYour branch is ahead of 'origin/feature/chat-new-api-peter' by 6 commits.\n (use \"git push\" to publish your local commits)\n\nChanges to be committed:\n (use \"git restore --staged <file>...\" to unstage)\n\tmodified: src/app/module/chat/domain/use-case/message/message-create-use-case.service.ts\n\tmodified: src/app/module/chat/domain/use-case/room/room-get-list-use-case.service.ts\n\tmodified: version/git-version.ts",
"changeAuthor": "peter.maquiran"
}