mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
fix, open file
This commit is contained in:
@@ -26,7 +26,7 @@ export function messageListDetermineChanges(serverList: MessageTable[], localLis
|
||||
item.$id = localItem.$id
|
||||
}
|
||||
|
||||
return localItem && (item.editedAt !== localItem.editedAt || item.reactions.some((r, index) => {
|
||||
return localItem && (item.editedAt !== localItem.editedAt || item.sentAt != item.sentAt || item.reactions.some((r, index) => {
|
||||
const localReaction = localItem.reactions[index];
|
||||
return !localReaction || r.reactedAt !== localReaction.reactedAt;
|
||||
}));
|
||||
|
||||
@@ -76,11 +76,11 @@ export class MessageLocalDataSourceService extends DexieRepository<MessageTable,
|
||||
}
|
||||
|
||||
getItems(roomId: string): PromiseExtended<MessageEntity[]> {
|
||||
return chatDatabase.message.where('roomId').equals(roomId).sortBy('$createAt') as any
|
||||
return chatDatabase.message.where('roomId').equals(roomId).sortBy('sentAt') as any
|
||||
}
|
||||
|
||||
getItemsLive(roomId: string): DexieObservable<MessageEntity[]> {
|
||||
return liveQuery(() => chatDatabase.message.where('roomId').equals(roomId).sortBy('$createAt') as any)
|
||||
return liveQuery(() => chatDatabase.message.where('roomId').equals(roomId).sortBy('sentAt') as any)
|
||||
}
|
||||
|
||||
async getOfflineMessages () {
|
||||
|
||||
@@ -13,19 +13,14 @@ export class RoomLocalRepository extends DexieRepository<RoomTable, RoomTable> i
|
||||
|
||||
constructor() {
|
||||
super(chatDatabase.room, RoomTableSchema)
|
||||
// chatDatabase.room.hook('creating', (primaryKey, obj, transaction) => {
|
||||
// if(obj.messages?.[0].attachments?.[0]) {
|
||||
// delete obj.messages[0].attachments[0].file
|
||||
// }
|
||||
// });
|
||||
|
||||
chatDatabase.room.hook('updating', (modifications, primKey, oldValue, transaction) => {
|
||||
|
||||
if((modifications as Partial<RoomTable>).messages?.[0].requestId == oldValue.messages?.[0].requestId) {
|
||||
(modifications as Partial<RoomTable>).messages[0].sentAt = oldValue.messages?.[0]?.sentAt;
|
||||
} else if ((modifications as Partial<RoomTable>).messages?.[0].id == oldValue.messages?.[0].id) {
|
||||
(modifications as Partial<RoomTable>).messages[0].sentAt = oldValue.messages?.[0]?.sentAt
|
||||
}
|
||||
// if((modifications as Partial<RoomTable>).messages?.[0].requestId == oldValue.messages?.[0].requestId) {
|
||||
// (modifications as Partial<RoomTable>).messages[0].sentAt = oldValue.messages?.[0]?.sentAt;
|
||||
// } else if ((modifications as Partial<RoomTable>).messages?.[0].id == oldValue.messages?.[0].id) {
|
||||
// (modifications as Partial<RoomTable>).messages[0].sentAt = oldValue.messages?.[0]?.sentAt
|
||||
// }
|
||||
|
||||
return modifications
|
||||
});
|
||||
|
||||
@@ -148,8 +148,8 @@ export class ChatServiceService {
|
||||
}
|
||||
|
||||
async start() {
|
||||
await this.chatSync()
|
||||
await this.SocketConnectUseCaseService.execute();
|
||||
this.chatSync()
|
||||
this.SocketConnectUseCaseService.execute();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -5,10 +5,8 @@ import { MessageRemoteDataSourceService } from '../../../data/repository/message
|
||||
import { MessageSocketRepositoryService } from '../../../data/repository/message/message-live-signalr-data-source.service';
|
||||
import { ok } from 'neverthrow';
|
||||
import { RoomLocalRepository } from '../../../data/repository/room/room-local-repository.service';
|
||||
import { SessionStore } from 'src/app/store/session.service';
|
||||
import { Logger } from 'src/app/services/logger/main/service';
|
||||
import { XTracerAsync, TracingType } from 'src/app/services/monitoring/opentelemetry/tracer';
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import { MessageTable } from 'src/app/infra/database/dexie/instance/chat/schema/message';
|
||||
|
||||
@Injectable({
|
||||
@@ -51,7 +49,7 @@ export class SyncAllRoomMessagesService {
|
||||
for (const message of changedItems) {
|
||||
delete message.sentAt
|
||||
let clone: MessageTable = { ...message, roomId: room.id };
|
||||
await this.messageLocalDataSourceService.update(clone.$id, clone);
|
||||
this.messageLocalDataSourceService.update(clone.$id, clone);
|
||||
|
||||
// const me = message.info.find(e => e.memberId === SessionStore.user.UserId && typeof e.deliverAt === 'string');
|
||||
|
||||
@@ -72,7 +70,7 @@ export class SyncAllRoomMessagesService {
|
||||
// You can perform operations with addedItems here if needed
|
||||
}
|
||||
|
||||
await this.messageLocalDataSourceService.insertMany(addedItems.reverse().map(e => {
|
||||
this.messageLocalDataSourceService.insertMany(addedItems.reverse().map(e => {
|
||||
e.origin = 'history'
|
||||
return e
|
||||
}));
|
||||
|
||||
@@ -41,6 +41,7 @@ export class RoomSetLastMessageService {
|
||||
|
||||
for(const room of roomList) {
|
||||
if(room.messages?.[0]?.id == message.id) {
|
||||
console.log('listenToUpdateMessage', message.roomId)
|
||||
const result = await this.roomLocalRepository.update(message.roomId, {
|
||||
messages: [message]
|
||||
})
|
||||
@@ -67,6 +68,7 @@ export class RoomSetLastMessageService {
|
||||
map(message => Object.assign(new MessageEntity(), message))
|
||||
).subscribe(async (message) => {
|
||||
if(message?.roomId) {
|
||||
console.log('listenToIncomingMessage', message.roomId)
|
||||
const result = await this.roomLocalRepository.update(message.roomId, {
|
||||
messages: [message]
|
||||
})
|
||||
@@ -88,9 +90,11 @@ export class RoomSetLastMessageService {
|
||||
if(message?.roomId) {
|
||||
|
||||
setTimeout(async() => {
|
||||
const result = await this.roomLocalRepository.update(message.roomId, {
|
||||
messages: [message]
|
||||
})
|
||||
if(message.origin != 'history') {
|
||||
const result = await this.roomLocalRepository.update(message.roomId, {
|
||||
messages: [message]
|
||||
})
|
||||
}
|
||||
}, 100)
|
||||
}
|
||||
|
||||
|
||||
@@ -333,6 +333,11 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
this.messages1[this.roomId].push(msg)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.messages1[this.roomId].sort((a, b) => {
|
||||
return new Date(a.sentAt).getTime() - new Date(b.sentAt).getTime()
|
||||
})
|
||||
})
|
||||
|
||||
}
|
||||
@@ -1471,9 +1476,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
this.openFile(msg.attachments[0].safeFile, msg.attachments[0].description, msg.attachments[0].mimeType);
|
||||
// this.downloadFileFromBrowser("file", str)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@
|
||||
<audio [src]="attachment.safeFile|safehtml" preload="metadata" class="flex-grow-1" controls controlsList="nodownload noplaybackrate"></audio>
|
||||
</div>
|
||||
|
||||
<div *ngIf="attachment.fileType == MessageAttachmentFileType.Doc" class="d-flex">
|
||||
<div *ngIf="attachment.fileType == MessageAttachmentFileType.Doc" class="d-flex" (click)="openPreview(message)">
|
||||
<fa-icon *ngIf="attachment.mimeType == 'application/pdf'" icon="file-pdf" class="pdf-icon"></fa-icon>
|
||||
<fa-icon *ngIf="attachment.mimeType == 'application/word'" icon="file-word" class="word-icon">
|
||||
</fa-icon>
|
||||
|
||||
@@ -52,7 +52,9 @@ import { tap } from 'rxjs/operators';
|
||||
import { ChatPopoverPage } from '../chat-popover/chat-popover.page';
|
||||
import { ViewOncesImagePageInput, ViewOncesImagePage } from '../view-onces/view-onces.page';
|
||||
import { LastMessage } from '../../utils/lastMessage';
|
||||
|
||||
import { File } from '@awesome-cordova-plugins/file/ngx';
|
||||
import { Filesystem, Directory } from '@capacitor/filesystem';
|
||||
import { FileOpener } from '@awesome-cordova-plugins/file-opener/ngx';
|
||||
|
||||
|
||||
const IMAGE_DIR = 'stored-images';
|
||||
@@ -168,6 +170,8 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
private userTypingLocalRepository: UserTypingLocalRepository,
|
||||
private UserTypingRemoteRepositoryService: UserTypingRemoteRepositoryService,
|
||||
private messageLocalDataSourceService: MessageLocalDataSourceService,
|
||||
private file: File,
|
||||
private fileOpener: FileOpener,
|
||||
) {
|
||||
|
||||
|
||||
@@ -1263,59 +1267,133 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
}
|
||||
|
||||
|
||||
async openFile(pdfString, filename, type) {
|
||||
// async openFile(pdfString, filename, type) {
|
||||
|
||||
console.log('url while open ',pdfString)
|
||||
// console.log('url while open ',pdfString)
|
||||
|
||||
/* const modal = await this.modalController.create({
|
||||
component: ViewDocumentSecondOptionsPage,
|
||||
componentProps: {
|
||||
fileUrl: pdfString,
|
||||
filename: filename
|
||||
},
|
||||
cssClass: 'modal modal-desktop'
|
||||
// /* const modal = await this.modalController.create({
|
||||
// component: ViewDocumentSecondOptionsPage,
|
||||
// componentProps: {
|
||||
// fileUrl: pdfString,
|
||||
// filename: filename
|
||||
// },
|
||||
// cssClass: 'modal modal-desktop'
|
||||
// });
|
||||
// await modal.present();
|
||||
// /*
|
||||
// await modal.present(); */
|
||||
|
||||
// // var blob = new Blob([pdfString], { type: 'application/pdf' });
|
||||
|
||||
|
||||
// let pathFile = ''
|
||||
// const fileName = filename
|
||||
// if (this.platform.is('ios')) {
|
||||
// pathFile = this.file.documentsDirectory
|
||||
// } else {
|
||||
// pathFile = this.file.externalRootDirectory
|
||||
// }
|
||||
|
||||
// console.log('file data', pdfString)
|
||||
// console.log(pathFile)
|
||||
|
||||
// let removePre = this.removeTextBeforeSlash(pdfString,',')
|
||||
// console.log('file data remove ', removePre)
|
||||
|
||||
// await Filesystem.writeFile({
|
||||
// path: fileName,
|
||||
// data: removePre,
|
||||
// directory: Directory.Cache,
|
||||
// }).then((dir) => {
|
||||
// console.log('DIR ', dir)
|
||||
// this.fileOpener
|
||||
// .open(dir.uri, type)
|
||||
// .then(() => console.log())
|
||||
// .catch(e => console.error(e))
|
||||
// }).catch((error) => {
|
||||
// console.log('error writing the file', error)
|
||||
// });
|
||||
// }
|
||||
|
||||
async fetchBlobFromURL(blobUrl: string): Promise<Blob> {
|
||||
try {
|
||||
const response = await fetch(blobUrl);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch blob: ${response.statusText}`);
|
||||
}
|
||||
return await response.blob();
|
||||
} catch (error) {
|
||||
console.error('Error fetching blob from URL:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
convertBlobToDataURL(blob: Blob): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.onloadend = () => {
|
||||
if (reader.result) {
|
||||
resolve(reader.result as string);
|
||||
} else {
|
||||
reject('Conversion failed');
|
||||
}
|
||||
};
|
||||
reader.onerror = (error) => reject(error);
|
||||
reader.readAsDataURL(blob);
|
||||
});
|
||||
await modal.present();
|
||||
/*
|
||||
await modal.present(); */
|
||||
}
|
||||
|
||||
// var blob = new Blob([pdfString], { type: 'application/pdf' });
|
||||
// async openFile(blobUrl:string, filename, fileType) {
|
||||
// console.log(blobUrl, filename, fileType)
|
||||
// let pathFile: string;
|
||||
|
||||
// console.log('blob blob', blob)
|
||||
// if (this.platform.is('ios')) {
|
||||
// pathFile = this.file.documentsDirectory
|
||||
// } else {
|
||||
// pathFile = this.file.externalRootDirectory
|
||||
// }
|
||||
|
||||
// this.blobToBase64(blob).then((value) => {
|
||||
// console.log(value)
|
||||
// }).catch((error) => {
|
||||
// console.log(error)
|
||||
// })
|
||||
// let a = await this.fetchBlobFromURL(blobUrl)
|
||||
|
||||
// let pathFile = ''
|
||||
// const fileName = filename
|
||||
// if (this.platform.is('ios')) {
|
||||
// pathFile = this.file.documentsDirectory
|
||||
// } else {
|
||||
// pathFile = this.file.externalRootDirectory
|
||||
// }
|
||||
// console.log({e:await this.convertBlobToDataURL(a)})
|
||||
// let removePre = this.removeTextBeforeSlash(await this.convertBlobToDataURL(a),',')
|
||||
|
||||
// console.log('file data', pdfString)
|
||||
// console.log(pathFile)
|
||||
// Filesystem.writeFile({
|
||||
// path: filename,
|
||||
// data: removePre,
|
||||
// directory: Directory.Cache,
|
||||
|
||||
// let removePre = this.removeTextBeforeSlash(pdfString,',')
|
||||
// console.log('file data remove ', removePre)
|
||||
// }).then(dir => {
|
||||
// console.log('DIR ', dir)
|
||||
// this.fileOpener
|
||||
// .open(dir.uri, fileType)
|
||||
// .then(() => console.log())
|
||||
// .catch(e => console.error(e))
|
||||
// })
|
||||
// .catch(e => console.log('Error writing file', e))
|
||||
// }
|
||||
|
||||
// await Filesystem.writeFile({
|
||||
// path: fileName,
|
||||
// data: removePre,
|
||||
// directory: Directory.Cache,
|
||||
// }).then((dir) => {
|
||||
// console.log('DIR ', dir)
|
||||
// this.fileOpener
|
||||
// .open(dir.uri, type)
|
||||
// .then(() => console.log())
|
||||
// .catch(e => console.error(e))
|
||||
// }).catch((error) => {
|
||||
// console.log('error writing the file', error)
|
||||
// });
|
||||
async openFile(blobUrl:string, filename, fileType) {
|
||||
|
||||
let pathFile = ''
|
||||
const fileName = filename
|
||||
const contentFile = await this.fetchBlobFromURL(blobUrl)
|
||||
if (this.platform.is('ios')) {
|
||||
pathFile = this.file.documentsDirectory
|
||||
} else {
|
||||
pathFile = this.file.cacheDirectory
|
||||
}
|
||||
console.log(pathFile)
|
||||
console.log(contentFile)
|
||||
this.file
|
||||
.writeFile(pathFile, fileName, contentFile, { replace: true })
|
||||
.then(success => {
|
||||
this.fileOpener
|
||||
.open(pathFile + fileName, fileType)
|
||||
.then(() => console.log('File is opened'))
|
||||
.catch(e => console.log('Error opening file', e));
|
||||
})
|
||||
.catch(e => console.log('Error writing file', e))
|
||||
}
|
||||
|
||||
removeTextBeforeSlash(inputString, controlString) {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { IRoom, RoomEntitySchema } from "src/app/core/chat/entity/group";
|
||||
import { MessageAttachmentSource } from "src/app/core/chat/entity/message";
|
||||
import { isDocument } from "src/app/utils/document-mimetype";
|
||||
|
||||
export class RoomViewModel implements IRoom {
|
||||
@@ -19,12 +20,17 @@ export class RoomViewModel implements IRoom {
|
||||
Object.assign(this, model)
|
||||
this.formatarData()
|
||||
|
||||
this.check()
|
||||
}
|
||||
|
||||
check() {
|
||||
if(this.messages?.[0]?.attachments[0]?.mimeType?.startsWith('image/') ) {
|
||||
this.lastMessageImage = true
|
||||
} else if (this.messages?.[0]?.attachments[0]?.mimeType && isDocument({mimeType: this.messages?.[0]?.attachments[0]?.mimeType})) {
|
||||
this.lastMessageDocument = true
|
||||
} else if (this.messages?.[0]?.attachments[0]?.source == MessageAttachmentSource.Webtrix) {
|
||||
this.lastMessageDocument = true
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
formatarData() {
|
||||
|
||||
Reference in New Issue
Block a user