upload attachment

This commit is contained in:
Peter Maquiran
2024-08-13 17:05:46 +01:00
parent 251f533a68
commit d7eb6a552b
20 changed files with 436 additions and 152 deletions
@@ -0,0 +1,31 @@
import { Injectable } from '@angular/core';
import { AttachmentLocalDataSource } from 'src/app/module/chat/data/data-source/attachment/attachment-local-data-source.service'
import { AttachmentTable } from '../../infra/database/dexie/schema/attachment';
@Injectable({
providedIn: 'root'
})
export class AttachmentRepositoryService {
constructor(
private AttachmentLocalDataSourceService: AttachmentLocalDataSource
) { }
create(data: AttachmentTable) {
return this.AttachmentLocalDataSourceService.insert(data)
}
get findOne() {
return this.AttachmentLocalDataSourceService.findOne
}
get insert() {
return this.AttachmentLocalDataSourceService.insert
}
get update() {
return this.AttachmentLocalDataSourceService.update
}
}
@@ -14,8 +14,7 @@ import { MessageOutPutDataDTO } from '../dto/message/messageOutputDTO';
import { MessageTable } from 'src/app/module/chat/infra/database/dexie/schema/message';
import { MessageLocalDataSourceService } from '../data-source/message/message-local-data-source.service';
import { MessageLiveDataSourceService } from '../data-source/message/message-live-signalr-data-source.service';
import { AttachmentLocalDataSourceService } from 'src/app/module/chat/data/data-source/attachment/message-local-data-source.service'
import { Subject } from 'rxjs';
import { AttachmentLocalDataSource } from 'src/app/module/chat/data/data-source/attachment/attachment-local-data-source.service'
@Injectable({
providedIn: 'root'
@@ -27,22 +26,13 @@ export class MessageRepositoryService {
private messageLiveDataSourceService: MessageLiveDataSourceService,
private messageLiveSignalRDataSourceService: SignalRService,
private messageLocalDataSourceService: MessageLocalDataSourceService,
private AttachmentLocalDataSourceService: AttachmentLocalDataSourceService
private AttachmentLocalDataSourceService: AttachmentLocalDataSource
) {}
async createMessageLocally(entity: MessageEntity) {
const requestId = InstanceId +'@'+ uuidv4();
const roomId = entity.roomId
return await this.messageLocalDataSourceService.sendMessage(entity)
}
async createMessage(entity: MessageEntity) {
//const requestId = InstanceId +'@'+ uuidv4();
const localActionResult = await this.messageLocalDataSourceService.sendMessage(entity)
return localActionResult.map(e => {
@@ -52,42 +42,32 @@ export class MessageRepositoryService {
}
async sendMessage(entity: MessageEntity) {
const messageSubject = new Subject<MessageTable | string>();
const roomId = entity.roomId
entity.sending = true
const localActionResult = await this.messageLocalDataSourceService.sendMessage(entity)
if(localActionResult.isOk()) {
const DTO = MessageMapper.fromDomain(entity, entity.requestId)
const sendMessageResult = await this.messageLiveSignalRDataSourceService.sendMessage<MessageOutPutDataDTO>(DTO)
// return this sendMessageResult
const DTO = MessageMapper.fromDomain(entity, entity.requestId)
const sendMessageResult = await this.messageLiveSignalRDataSourceService.sendMessage<MessageOutPutDataDTO>(DTO)
// return this sendMessageResult
if(sendMessageResult.isOk()) {
if(sendMessageResult.isOk()) {
if(sendMessageResult.value.sender == undefined || sendMessageResult.value.sender == null) {
if(sendMessageResult.value.sender == undefined || sendMessageResult.value.sender == null) {
delete sendMessageResult.value.sender
}
let clone: MessageTable = {
...sendMessageResult.value,
id: sendMessageResult.value.id,
$id : localActionResult.value
}
// console.log('sendMessageResult.value', sendMessageResult.value)
// this.attachment(sendMessageResult.value.attachments[0].id)
return this.messageLocalDataSourceService.update(localActionResult.value, {...clone, sending: false, roomId: entity.roomId})
} else {
await this.messageLocalDataSourceService.update(localActionResult.value, {sending: false, $id: localActionResult.value})
return err('no connection')
delete sendMessageResult.value.sender
}
let clone: MessageTable = {
...sendMessageResult.value,
id: sendMessageResult.value.id,
$id : entity.$id
}
return this.messageLocalDataSourceService.update(entity.$id, {...clone, sending: false, roomId: entity.roomId})
} else {
// return this.messageLocalDataSourceService.update({sending: false})
await this.messageLocalDataSourceService.update(entity.$id, {sending: false, $id: entity.$id})
return err('no connection')
}
}