diff --git a/angular.json b/angular.json index 80af72b60..cd7b53a72 100644 --- a/angular.json +++ b/angular.json @@ -68,7 +68,7 @@ ], "optimization": true, "outputHashing": "all", - "sourceMap": false, + "sourceMap": true, "namedChunks": false, "aot": true, "extractLicenses": true, diff --git a/src/app/infra/file-picker/file-picker.service.ts b/src/app/infra/file-picker/file-picker.service.ts index 44c390541..26f344b8c 100644 --- a/src/app/infra/file-picker/file-picker.service.ts +++ b/src/app/infra/file-picker/file-picker.service.ts @@ -40,7 +40,7 @@ export class FilePickerService { quality: quality, resultType: cameraResultType, source: CameraSource.Photos - }); + }) return ok(file); } catch (e) { diff --git a/src/app/module/chat/data/dto/message/messageInputDtO.ts b/src/app/module/chat/data/dto/message/messageInputDtO.ts index be05c067e..8a4fb2211 100644 --- a/src/app/module/chat/data/dto/message/messageInputDtO.ts +++ b/src/app/module/chat/data/dto/message/messageInputDtO.ts @@ -16,8 +16,8 @@ export const MessageInputDTOSchema = z.object({ source: z.nativeEnum(MessageAttachmentSource), file: base64Schema.optional(), fileName: z.string().optional(), - applicationId: z.string().optional(), - docId: z.string().optional(), + applicationId: z.number().optional(), + docId: z.number().optional(), mimeType: z.string().optional() }).optional() }); diff --git a/src/app/module/chat/data/dto/message/messageOutputDTO.ts b/src/app/module/chat/data/dto/message/messageOutputDTO.ts index 74b8dfa1e..a1001575f 100644 --- a/src/app/module/chat/data/dto/message/messageOutputDTO.ts +++ b/src/app/module/chat/data/dto/message/messageOutputDTO.ts @@ -40,7 +40,7 @@ export const MessageOutPutDataDTOSchema = z.object({ source: z.nativeEnum(MessageAttachmentSource), file: z.string().optional(), fileName: z.string().optional(), - applicationId: z.string().optional(), + applicationId: z.number().optional(), docId: z.string().optional(), id: z.string().optional() })) 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 a8b953f88..f7ed07dda 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 @@ -51,7 +51,7 @@ export class SyncMessageRepositoryService { $id : message.$id } - console.log('send message local') + console.log('send message local '+ messages.length) this.messageLocalDataSourceService.update(message.$id, {...clone, sending: false, roomId: message.roomId}) } else { diff --git a/src/app/module/chat/domain/entity/message.ts b/src/app/module/chat/domain/entity/message.ts index 8e6107c59..e8f510c33 100644 --- a/src/app/module/chat/domain/entity/message.ts +++ b/src/app/module/chat/domain/entity/message.ts @@ -25,7 +25,7 @@ export const MessageEntitySchema = z.object({ source: z.nativeEnum(MessageAttachmentSource), file: base64Schema.optional(), fileName: z.string().optional(), - applicationId: z.string().optional(), + applicationId: z.number().optional(), docId: z.string().optional(), id: z.string().optional(), mimeType: z.string().optional() @@ -60,7 +60,7 @@ export class MessageEntity implements Message { source: MessageAttachmentSource, file?: string, fileName: string, - applicationId?: string, + applicationId?: number, docId?: string, mimeType?: string, description?: string diff --git a/src/app/module/chat/domain/mapper/messageMapper.ts b/src/app/module/chat/domain/mapper/messageMapper.ts index ef1713e3a..a9598c30e 100644 --- a/src/app/module/chat/domain/mapper/messageMapper.ts +++ b/src/app/module/chat/domain/mapper/messageMapper.ts @@ -24,7 +24,7 @@ export class MessageMapper { file: e.file, fileName: e.fileName, applicationId: e.applicationId, - docId: e.docId, + docId: Number(e.docId), mimeType: e.mimeType }))[0] diff --git a/src/app/module/chat/domain/use-case/message-create-use-case.service.ts b/src/app/module/chat/domain/use-case/message-create-use-case.service.ts index 036503a44..9de7dcd4e 100644 --- a/src/app/module/chat/domain/use-case/message-create-use-case.service.ts +++ b/src/app/module/chat/domain/use-case/message-create-use-case.service.ts @@ -8,6 +8,8 @@ import { InstanceId } from '../chat-service.service'; import { createDataURL } from 'src/app/utils/ToBase64'; import { DomSanitizer } from '@angular/platform-browser'; import { zodSafeValidation } from 'src/app/utils/zodValidation'; +import { Logger } from 'src/app/services/logger/main/service'; +import { MessageAttachmentSource } from '../../data/dto/message/messageOutputDTO'; const MessageInputUseCaseSchema = z.object({ memberId: z.number(), @@ -25,7 +27,6 @@ export class MessageCreateUseCaseService { constructor( private MessageRepositoryService: MessageRepositoryService, private AttachmentRepositoryService: AttachmentRepositoryService, - private sanitizer: DomSanitizer, ) { } @@ -41,34 +42,40 @@ export class MessageCreateUseCaseService { const createMessageLocally = await this.MessageRepositoryService.createMessageLocally(message) if(createMessageLocally.isOk()) { - - console.log('==========================',message); if(message.hasAttachment) { for (const attachment of message.attachments) { - this.AttachmentRepositoryService.create({ - $messageId: createMessageLocally.value.$id, - file: createDataURL(attachment.file, attachment.mimeType) - }).then((e) => { - if(e.isErr()) { - console.log('e', e.error, createDataURL(attachment.file, attachment.mimeType)) - } - }) + console.log(attachment) + if(attachment.source != MessageAttachmentSource.Webtrix) { - attachment.safeFile = createDataURL(attachment.file, attachment.mimeType) + this.AttachmentRepositoryService.create({ + $messageId: createMessageLocally.value.$id, + file: createDataURL(attachment.file, attachment.mimeType) + }).then((e) => { + if(e.isErr()) { + Logger.error('failed to create attachment locally on send message', { + error: e.error, + data: createDataURL(attachment.file, attachment.mimeType).slice(0, 100) +'...' + }) + } + + }) + + attachment.safeFile = createDataURL(attachment.file, attachment.mimeType) + } } } const sendToServer = await this.MessageRepositoryService.sendMessage(message) - if(!sendToServer.isOk()) { - console.log('sendToServer error', sendToServer.error) + Logger.error('failed to send message to the server', { + error: sendToServer.error + }) } - return sendToServer } @@ -78,12 +85,13 @@ export class MessageCreateUseCaseService { } else { if(validation.error.formErrors.fieldErrors.attachments) { - console.log(message.attachments) - console.error('invalid attachment', validation.error.formErrors.fieldErrors.attachments) + Logger.error('failed to send message doe to invalid attachment', { + zodErrorList: validation.error.errors, + data: message.attachments + }) } } - } } diff --git a/src/app/module/chat/infra/database/dexie/schema/message.ts b/src/app/module/chat/infra/database/dexie/schema/message.ts index 05bb8c7ed..53280ee0b 100644 --- a/src/app/module/chat/infra/database/dexie/schema/message.ts +++ b/src/app/module/chat/infra/database/dexie/schema/message.ts @@ -30,7 +30,7 @@ export const MessageTableSchema = z.object({ fileType: z.nativeEnum(MessageAttachmentFileType), source: z.nativeEnum(MessageAttachmentSource), fileName: z.string().optional(), - applicationId: z.string().optional(), + applicationId: z.number().optional(), docId: z.string().optional(), id: z.string().optional(), mimeType: z.string().optional() diff --git a/src/app/pages/chat/chat.page.ts b/src/app/pages/chat/chat.page.ts index 22462981b..f5b23acdb 100644 --- a/src/app/pages/chat/chat.page.ts +++ b/src/app/pages/chat/chat.page.ts @@ -26,6 +26,7 @@ import { RoomRemoteDataSourceState } from 'src/app/module/chat/data/data-source/ import { RoomListOutPutDTO } from 'src/app/module/chat/data/dto/room/roomListOutputDTO'; import { RoomRepositoryService } from 'src/app/module/chat/data/repository/room-repository.service' import { Observable as DexieObservable } from 'Dexie'; +import { Logger } from 'src/app/services/logger/main/service'; @Component({ selector: 'app-chat', @@ -126,7 +127,6 @@ export class ChatPage implements OnInit { this.showLoader = true; this.segment = 'Grupos' - } // Fetch all items using useLiveQuery diff --git a/src/app/pages/chat/messages/messages.page.ts b/src/app/pages/chat/messages/messages.page.ts index bb5558189..040a76ac1 100644 --- a/src/app/pages/chat/messages/messages.page.ts +++ b/src/app/pages/chat/messages/messages.page.ts @@ -17,7 +17,6 @@ import { ThemeService } from 'src/app/services/theme.service' import { VoiceRecorder, GenericResponse } from 'capacitor-voice-recorder'; import { Haptics, ImpactStyle } from '@capacitor/haptics'; import { ViewEventPage } from 'src/app/modals/view-event/view-event.page'; -import { FileType } from 'src/app/models/fileType'; import { SearchPage } from 'src/app/pages/search/search.page'; import { Storage } from '@ionic/storage'; import { Camera, CameraResultType } from '@capacitor/camera'; @@ -28,7 +27,6 @@ import { File } from '@awesome-cordova-plugins/file/ngx'; import { FileOpener } from '@awesome-cordova-plugins/file-opener/ngx'; import { Filesystem, Directory } from '@capacitor/filesystem'; import { FileValidatorService } from "src/app/services/file/file-validator.service" -import { sanitize } from "sanitize-filename-ts"; import { FilePicker } from '@capawesome/capacitor-file-picker'; //====== import { Observable as DexieObservable } from 'Dexie'; @@ -49,6 +47,7 @@ import { compressImageBase64 } from 'src/app/utils/imageCompressore'; import { FilePickerService } from 'src/app/infra/file-picker/file-picker.service' import { FilePickerMobileService } from 'src/app/infra/file-picker/mobile/file-picker-mobile.service' import { RecordingData } from 'capacitor-voice-recorder'; +import { Logger } from 'src/app/services/logger/main/service'; const IMAGE_DIR = 'stored-images'; @@ -963,7 +962,9 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { } } else { - console.log(file.error) + Logger.error('failed to pick picture from the device', { + error: file.error + }) } } diff --git a/src/app/services/logger/main/service.ts b/src/app/services/logger/main/service.ts index 43be6e8f7..82966c181 100644 --- a/src/app/services/logger/main/service.ts +++ b/src/app/services/logger/main/service.ts @@ -56,9 +56,9 @@ export class Logger { console.error( `[${getCurrentTime()}] %cERROR : `, // Console Message 'color: #E53935', // CSS Style - message+', '+ + message+' '+ '\n', - (obj as any)?.error, + obj, '\n', ); } diff --git a/src/app/shared/chat/messages/messages.page.ts b/src/app/shared/chat/messages/messages.page.ts index b9b6198de..4f82695b2 100644 --- a/src/app/shared/chat/messages/messages.page.ts +++ b/src/app/shared/chat/messages/messages.page.ts @@ -864,7 +864,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy } message.attachments = [{ fileName: res.data.selected.Assunto, - source: MessageAttachmentSource.Device, + source: MessageAttachmentSource.Webtrix, fileType: MessageAttachmentFileType.Doc, applicationId: res.data.selected.ApplicationType, docId: res.data.selected.Id,