add contact page

This commit is contained in:
Peter Maquiran
2024-08-16 17:17:32 +01:00
parent 6072a2456b
commit 9d441a3e5b
10 changed files with 241 additions and 252 deletions
@@ -0,0 +1,38 @@
import { Injectable } from '@angular/core';
import { AttachmentRemoteDataSourceService } from 'src/app/module/chat/data/data-source/attachment/attachment-remote-data-source.service'
import { Logger } from 'src/app/services/logger/main/service';
import { convertBlobToDataURL } from 'src/app/utils/ToBase64';
import { AttachmentLocalDataSource } from 'src/app/module/chat/data/data-source/attachment/attachment-local-data-source.service'
import { MessageAttachmentByMessageIdInput } from './message-attachment-by-message-id.service';
@Injectable({
providedIn: 'root'
})
export class DownloadMessageAttachmentUserCaseService {
constructor(
private AttachmentRemoteDataSourceService: AttachmentRemoteDataSourceService,
private AttachmentLocalDataSource: AttachmentLocalDataSource
) { }
async execute(input: MessageAttachmentByMessageIdInput) {
const result = await this.AttachmentRemoteDataSourceService.getAttachment(input.$messageId)
return result.asyncMap(async (e) => {
const dataUrl = await convertBlobToDataURL(e)
Logger.info('downloaded file #1', {
data: dataUrl.slice(0, 100)+'...',
context: 'DownloadMessageAttachmentUserCaseService'
})
this.AttachmentLocalDataSource.insert({
$messageId: input.$messageId,
id: input.id,
file: dataUrl
})
return dataUrl
})
}
}
@@ -4,6 +4,7 @@ import { AttachmentRemoteDataSourceService } from 'src/app/module/chat/data/data
import { AttachmentLocalDataSource } from 'src/app/module/chat/data/data-source/attachment/attachment-local-data-source.service'
import { convertBlobToDataURL } from 'src/app/utils/ToBase64';
import { Result } from 'neverthrow';
import { Logger } from 'src/app/services/logger/main/service';
const MessageAttachmentByMessageIdSchema = z.object({
$messageId: z.number(),
@@ -33,10 +34,13 @@ export class MessageAttachmentByMessageIdUseCase {
return getLocalAttachment.map(e => e.file)
}
} else {
const result = await this.AttachmentRemoteDataSourceService.getAttachment(input)
const result = await this.AttachmentRemoteDataSourceService.getAttachment(input.id)
return result.asyncMap(async (e) => {
const dataUrl = await convertBlobToDataURL(e)
Logger.info('downloaded file', {
data: dataUrl.slice(0, 100)+'...'
})
this.AttachmentLocalDataSource.insert({
$messageId: input.$messageId,