mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-21 13:55:51 +00:00
fixslow send
This commit is contained in:
@@ -106,78 +106,96 @@ export class MessageCreateUseCaseService {
|
||||
message.sendAttemp++;
|
||||
|
||||
message.requestId = InstanceId +'@'+ uuidv4();
|
||||
message.sending = true;
|
||||
|
||||
const createMessageLocally = await this.messageLocalDataSourceService.insert(message)
|
||||
const createMessageLocally = this.messageLocalDataSourceService.insert(message)
|
||||
|
||||
if(createMessageLocally.isOk()) {
|
||||
createMessageLocally.then((value) => {
|
||||
if(value.isOk()) {
|
||||
|
||||
message.$id = createMessageLocally.value
|
||||
console.log("set image")
|
||||
message.$id = value.value
|
||||
|
||||
if(message.hasAttachment) {
|
||||
if(message.hasAttachment) {
|
||||
|
||||
for (const attachment of message.attachments) {
|
||||
for (const attachment of message.attachments) {
|
||||
|
||||
if(attachment.source != MessageAttachmentSource.Webtrix) {
|
||||
if(attachment.source != MessageAttachmentSource.Webtrix) {
|
||||
|
||||
this.AttachmentLocalRepositoryService.insert({
|
||||
$messageId: createMessageLocally.value,
|
||||
file: createBlobFromBase64(attachment.file, attachment.mimeType),
|
||||
fileType: attachment.fileType,
|
||||
source: attachment.source,
|
||||
fileName: attachment.fileName,
|
||||
applicationId: attachment.applicationId,
|
||||
docId: attachment.docId,
|
||||
mimeType: attachment.mimeType,
|
||||
base64: 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) +'...'
|
||||
})
|
||||
}
|
||||
this.AttachmentLocalRepositoryService.insert({
|
||||
$messageId: value.value,
|
||||
file: createBlobFromBase64(attachment.file, attachment.mimeType),
|
||||
fileType: attachment.fileType,
|
||||
source: attachment.source,
|
||||
fileName: attachment.fileName,
|
||||
applicationId: attachment.applicationId,
|
||||
docId: attachment.docId,
|
||||
mimeType: attachment.mimeType,
|
||||
base64: 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)
|
||||
attachment.safeFile = createDataURL(attachment.file, attachment.mimeType)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//====================
|
||||
message.sending = true
|
||||
|
||||
let sendMessageResult: Result<MessageOutPutDataDTO, any>
|
||||
if(messageEnum == RoomType.Group) {
|
||||
const DTO = MessageMapper.fromDomain(message, message.requestId)
|
||||
sendMessageResult = await this.messageSocketRepositoryService.sendGroupMessage(DTO)
|
||||
} else {
|
||||
const DTO = MessageMapper.fromDomain(message, message.requestId)
|
||||
delete DTO.roomId
|
||||
sendMessageResult = await this.messageSocketRepositoryService.sendDirectMessage(DTO)
|
||||
Logger.error('failed to insert locally', {
|
||||
error: value.error.message
|
||||
})
|
||||
}
|
||||
|
||||
// return this sendMessageResult
|
||||
});
|
||||
|
||||
if(sendMessageResult.isOk()) {
|
||||
//====================
|
||||
message.sending = true
|
||||
|
||||
message.id = sendMessageResult.value.id
|
||||
let sendMessageResult!: Result<MessageOutPutDataDTO, any>
|
||||
const start = performance.now(); // Capture the start time
|
||||
if(messageEnum == RoomType.Group) {
|
||||
const DTO = MessageMapper.fromDomain(message, message.requestId)
|
||||
sendMessageResult = await this.messageSocketRepositoryService.sendGroupMessage(DTO)
|
||||
} else {
|
||||
const DTO = MessageMapper.fromDomain(message, message.requestId)
|
||||
delete DTO.roomId
|
||||
sendMessageResult = await this.messageSocketRepositoryService.sendDirectMessage(DTO)
|
||||
}
|
||||
|
||||
console.log('sendMessageResult', sendMessageResult.value.id)
|
||||
const end = performance.now(); // Capture the end time
|
||||
const duration = end - start; // Calculate the difference
|
||||
|
||||
if(sendMessageResult.value.sender == undefined || sendMessageResult.value.sender == null) {
|
||||
tracing.setAttribute("duration", `Execution time: ${duration}ms`);
|
||||
|
||||
delete sendMessageResult.value.sender
|
||||
}
|
||||
// return this sendMessageResult
|
||||
|
||||
if(sendMessageResult.isOk()) {
|
||||
|
||||
message.id = sendMessageResult.value.id
|
||||
|
||||
console.log('sendMessageResult', sendMessageResult.value.id)
|
||||
|
||||
if(sendMessageResult.value.sender == undefined || sendMessageResult.value.sender == null) {
|
||||
|
||||
delete sendMessageResult.value.sender
|
||||
}
|
||||
|
||||
createMessageLocally.then((value) => {
|
||||
console.log('sendMessageResult', (sendMessageResult as any).value)
|
||||
let clone: MessageTable = {
|
||||
...sendMessageResult.value,
|
||||
id: sendMessageResult.value.id,
|
||||
...(sendMessageResult as any).value,
|
||||
id: (sendMessageResult as any).value.id,
|
||||
$id : message.$id
|
||||
}
|
||||
|
||||
console.log('set update')
|
||||
this.messageLocalDataSourceService.update(message.$id, {...clone, sending: false, roomId: clone.roomId}).then((data)=> {
|
||||
if(data.isOk()) {
|
||||
|
||||
@@ -187,20 +205,16 @@ export class MessageCreateUseCaseService {
|
||||
console.log(data.error)
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
return sendMessageResult
|
||||
} else {
|
||||
Logger.error('failed to send message to the server', {
|
||||
error: sendMessageResult.error
|
||||
})
|
||||
await this.messageLocalDataSourceService.update(message.$id, {sending: false, $id: message.$id})
|
||||
return err('no connection')
|
||||
}
|
||||
|
||||
return sendMessageResult
|
||||
} else {
|
||||
Logger.error('failed to insert locally', {
|
||||
error: createMessageLocally.error.message
|
||||
Logger.error('failed to send message to the server', {
|
||||
error: sendMessageResult.error
|
||||
})
|
||||
await this.messageLocalDataSourceService.update(message.$id, {sending: false, $id: message.$id})
|
||||
return err('no connection')
|
||||
}
|
||||
} else {
|
||||
|
||||
|
||||
@@ -4,6 +4,9 @@ import { ValidateSchema } from 'src/app/services/decorators/validate-schema.deco
|
||||
import { MessageRemoteDataSourceService } from '../../../../module/chat/data/repository/message/message-remote-data-source.service';
|
||||
import { MessageSocketRepositoryService } from '../../../../module/chat/data/repository/message/message-live-signalr-data-source.service';
|
||||
import { IMessageSocketRepository } from '../../repository/message/message-socket-repository';
|
||||
import { zodSafeValidation } from 'src/app/utils/zodValidation';
|
||||
import { Logger } from 'src/app/services/logger/main/service';
|
||||
import { TracingType, XTracerAsync } from 'src/app/services/monitoring/opentelemetry/tracer';
|
||||
|
||||
|
||||
const MessageUpdateInputDTOSchema = z.object({
|
||||
@@ -26,9 +29,23 @@ export class MessageUpdateUseCaseService {
|
||||
public repository: IMessageSocketRepository
|
||||
) { }
|
||||
|
||||
@ValidateSchema(MessageUpdateInputDTOSchema)
|
||||
execute(input: MessageUpdateInput) {
|
||||
return this.repository.updateMessage(input);
|
||||
|
||||
@XTracerAsync({name:'MessageUpdateUseCaseService', module:'chat', bugPrint: true, waitNThrow: 5000})
|
||||
async execute(input: MessageUpdateInput, tracing?: TracingType) {
|
||||
console.log('MessageUpdateUseCaseService', input)
|
||||
const validation = zodSafeValidation<MessageUpdateInput>(MessageUpdateInputDTOSchema, input)
|
||||
|
||||
if(validation.isOk()) {
|
||||
|
||||
} else {
|
||||
tracing.hasError('failed to update message, validation failed')
|
||||
Logger.error('failed to update message, validation failed', {
|
||||
zodErrorList: validation.error.errors,
|
||||
data: input
|
||||
})
|
||||
}
|
||||
|
||||
return await this.repository.updateMessage(input);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ export class HttpService {
|
||||
|
||||
const httpOptions = {
|
||||
params: httpParams,
|
||||
headers: options?.headers || new HttpHeaders(),
|
||||
headers: options?.headers as any || new HttpHeaders(),
|
||||
responseType: options?.responseType || 'json' as any,
|
||||
};
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ export function APIReturn(schema: z.ZodTypeAny, path: string) {
|
||||
tracing?.setAttribute?.('map.error.schema-'+i, JSON.stringify(schema))
|
||||
}
|
||||
|
||||
tracing.log('API return '+ path, {
|
||||
tracing?.log?.('API return '+ path, {
|
||||
data: result?.value,
|
||||
issues: error?.errors
|
||||
})
|
||||
@@ -79,7 +79,7 @@ export function APINODReturn(schema: z.ZodTypeAny, data , path: string, tracing?
|
||||
tracing?.setAttribute('map.error.schema-'+i, JSON.stringify(schema))
|
||||
}
|
||||
|
||||
tracing?.log('API return '+ path, {
|
||||
tracing?.log?.('API return '+ path, {
|
||||
data,
|
||||
issues: error?.errors
|
||||
})
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<button *ngIf="roomType == EnumRoomType.Group" (click)="leaveGroup()" class="btn-cancel mt-10-em" shape="round">Sair do Grupo</button>
|
||||
<button *ngIf="isAdmin && roomType == EnumRoomType.Group" (click)="openChangeGroupName()" class="btn-cancel btn-cancel mt-10" shape="round" style="min-width: 192px;">Alterar
|
||||
nome do grupo</button>
|
||||
<button *ngIf="isAdmin && roomType == EnumRoomType.Group" (click)="setRoomOwner()" class="btn-cancel mt-10-em" shape="round">Adicionar admin</button>
|
||||
<button *ngIf="isAdmin && roomType == EnumRoomType.Group" (click)="setRoomOwner({})" class="btn-cancel mt-10-em" shape="round">Adicionar administrador</button>
|
||||
<div class="solid"></div>
|
||||
<button (click)="close('cancel')" full class="btn-cancel mobile-only mt-10-em" shape="round">Cancelar</button>
|
||||
<button (click)="deleteGroup()" class="btn-delete mt-10-em" shape="round">Apagar grupo</button>
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ModalController, NavParams, PopoverController } from '@ionic/angular';
|
||||
import { ToastService } from 'src/app/services/toast.service';
|
||||
import { ThemeService } from 'src/app/services/theme.service'
|
||||
import { ThemeService } from 'src/app/services/theme.service';
|
||||
import { SetRoomOwnerPage } from 'src/app/ui/chat/modal/set-room-owner/set-room-owner.page';
|
||||
import { SessionStore } from 'src/app/store/session.service';
|
||||
import { ZodError } from 'zod';
|
||||
import { MemberListLocalRepository } from 'src/app/module/chat/data/repository/member/member-list-local-repository.service'
|
||||
import { MemberListLocalRepository } from 'src/app/module/chat/data/repository/member/member-list-local-repository.service';
|
||||
import { ChatServiceService } from 'src/app/module/chat/domain/chat-service.service'
|
||||
import { RoomInfoPage } from '../room-info/room-info.page';
|
||||
import { RoomType } from 'src/app/core/chat/entity/group';
|
||||
import { isHttpResponse } from 'src/app/infra/http/http.service';
|
||||
|
||||
|
||||
|
||||
interface ISetRoomOwner {
|
||||
addAdminBeforeLeave: null | boolean
|
||||
addAdminBeforeLeave?: null | boolean
|
||||
}
|
||||
|
||||
@Component({
|
||||
|
||||
Reference in New Issue
Block a user