mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-21 05:45:50 +00:00
fix, open file
This commit is contained in:
@@ -26,7 +26,7 @@ export function messageListDetermineChanges(serverList: MessageTable[], localLis
|
|||||||
item.$id = localItem.$id
|
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];
|
const localReaction = localItem.reactions[index];
|
||||||
return !localReaction || r.reactedAt !== localReaction.reactedAt;
|
return !localReaction || r.reactedAt !== localReaction.reactedAt;
|
||||||
}));
|
}));
|
||||||
|
|||||||
@@ -76,11 +76,11 @@ export class MessageLocalDataSourceService extends DexieRepository<MessageTable,
|
|||||||
}
|
}
|
||||||
|
|
||||||
getItems(roomId: string): PromiseExtended<MessageEntity[]> {
|
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[]> {
|
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 () {
|
async getOfflineMessages () {
|
||||||
|
|||||||
@@ -13,19 +13,14 @@ export class RoomLocalRepository extends DexieRepository<RoomTable, RoomTable> i
|
|||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super(chatDatabase.room, RoomTableSchema)
|
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) => {
|
chatDatabase.room.hook('updating', (modifications, primKey, oldValue, transaction) => {
|
||||||
|
|
||||||
if((modifications as Partial<RoomTable>).messages?.[0].requestId == oldValue.messages?.[0].requestId) {
|
// if((modifications as Partial<RoomTable>).messages?.[0].requestId == oldValue.messages?.[0].requestId) {
|
||||||
(modifications as Partial<RoomTable>).messages[0].sentAt = oldValue.messages?.[0]?.sentAt;
|
// (modifications as Partial<RoomTable>).messages[0].sentAt = oldValue.messages?.[0]?.sentAt;
|
||||||
} else if ((modifications as Partial<RoomTable>).messages?.[0].id == oldValue.messages?.[0].id) {
|
// } else if ((modifications as Partial<RoomTable>).messages?.[0].id == oldValue.messages?.[0].id) {
|
||||||
(modifications as Partial<RoomTable>).messages[0].sentAt = oldValue.messages?.[0]?.sentAt
|
// (modifications as Partial<RoomTable>).messages[0].sentAt = oldValue.messages?.[0]?.sentAt
|
||||||
}
|
// }
|
||||||
|
|
||||||
return modifications
|
return modifications
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -148,8 +148,8 @@ export class ChatServiceService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async start() {
|
async start() {
|
||||||
await this.chatSync()
|
this.chatSync()
|
||||||
await this.SocketConnectUseCaseService.execute();
|
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 { MessageSocketRepositoryService } from '../../../data/repository/message/message-live-signalr-data-source.service';
|
||||||
import { ok } from 'neverthrow';
|
import { ok } from 'neverthrow';
|
||||||
import { RoomLocalRepository } from '../../../data/repository/room/room-local-repository.service';
|
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 { Logger } from 'src/app/services/logger/main/service';
|
||||||
import { XTracerAsync, TracingType } from 'src/app/services/monitoring/opentelemetry/tracer';
|
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';
|
import { MessageTable } from 'src/app/infra/database/dexie/instance/chat/schema/message';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
@@ -51,7 +49,7 @@ export class SyncAllRoomMessagesService {
|
|||||||
for (const message of changedItems) {
|
for (const message of changedItems) {
|
||||||
delete message.sentAt
|
delete message.sentAt
|
||||||
let clone: MessageTable = { ...message, roomId: room.id };
|
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');
|
// 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
|
// 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'
|
e.origin = 'history'
|
||||||
return e
|
return e
|
||||||
}));
|
}));
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ export class RoomSetLastMessageService {
|
|||||||
|
|
||||||
for(const room of roomList) {
|
for(const room of roomList) {
|
||||||
if(room.messages?.[0]?.id == message.id) {
|
if(room.messages?.[0]?.id == message.id) {
|
||||||
|
console.log('listenToUpdateMessage', message.roomId)
|
||||||
const result = await this.roomLocalRepository.update(message.roomId, {
|
const result = await this.roomLocalRepository.update(message.roomId, {
|
||||||
messages: [message]
|
messages: [message]
|
||||||
})
|
})
|
||||||
@@ -67,6 +68,7 @@ export class RoomSetLastMessageService {
|
|||||||
map(message => Object.assign(new MessageEntity(), message))
|
map(message => Object.assign(new MessageEntity(), message))
|
||||||
).subscribe(async (message) => {
|
).subscribe(async (message) => {
|
||||||
if(message?.roomId) {
|
if(message?.roomId) {
|
||||||
|
console.log('listenToIncomingMessage', message.roomId)
|
||||||
const result = await this.roomLocalRepository.update(message.roomId, {
|
const result = await this.roomLocalRepository.update(message.roomId, {
|
||||||
messages: [message]
|
messages: [message]
|
||||||
})
|
})
|
||||||
@@ -88,9 +90,11 @@ export class RoomSetLastMessageService {
|
|||||||
if(message?.roomId) {
|
if(message?.roomId) {
|
||||||
|
|
||||||
setTimeout(async() => {
|
setTimeout(async() => {
|
||||||
const result = await this.roomLocalRepository.update(message.roomId, {
|
if(message.origin != 'history') {
|
||||||
messages: [message]
|
const result = await this.roomLocalRepository.update(message.roomId, {
|
||||||
})
|
messages: [message]
|
||||||
|
})
|
||||||
|
}
|
||||||
}, 100)
|
}, 100)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -333,6 +333,11 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
|||||||
this.messages1[this.roomId].push(msg)
|
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>
|
<audio [src]="attachment.safeFile|safehtml" preload="metadata" class="flex-grow-1" controls controlsList="nodownload noplaybackrate"></audio>
|
||||||
</div>
|
</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/pdf'" icon="file-pdf" class="pdf-icon"></fa-icon>
|
||||||
<fa-icon *ngIf="attachment.mimeType == 'application/word'" icon="file-word" class="word-icon">
|
<fa-icon *ngIf="attachment.mimeType == 'application/word'" icon="file-word" class="word-icon">
|
||||||
</fa-icon>
|
</fa-icon>
|
||||||
|
|||||||
@@ -52,7 +52,9 @@ import { tap } from 'rxjs/operators';
|
|||||||
import { ChatPopoverPage } from '../chat-popover/chat-popover.page';
|
import { ChatPopoverPage } from '../chat-popover/chat-popover.page';
|
||||||
import { ViewOncesImagePageInput, ViewOncesImagePage } from '../view-onces/view-onces.page';
|
import { ViewOncesImagePageInput, ViewOncesImagePage } from '../view-onces/view-onces.page';
|
||||||
import { LastMessage } from '../../utils/lastMessage';
|
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';
|
const IMAGE_DIR = 'stored-images';
|
||||||
@@ -168,6 +170,8 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
|||||||
private userTypingLocalRepository: UserTypingLocalRepository,
|
private userTypingLocalRepository: UserTypingLocalRepository,
|
||||||
private UserTypingRemoteRepositoryService: UserTypingRemoteRepositoryService,
|
private UserTypingRemoteRepositoryService: UserTypingRemoteRepositoryService,
|
||||||
private messageLocalDataSourceService: MessageLocalDataSourceService,
|
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({
|
// /* const modal = await this.modalController.create({
|
||||||
component: ViewDocumentSecondOptionsPage,
|
// component: ViewDocumentSecondOptionsPage,
|
||||||
componentProps: {
|
// componentProps: {
|
||||||
fileUrl: pdfString,
|
// fileUrl: pdfString,
|
||||||
filename: filename
|
// filename: filename
|
||||||
},
|
// },
|
||||||
cssClass: 'modal modal-desktop'
|
// 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) => {
|
// let a = await this.fetchBlobFromURL(blobUrl)
|
||||||
// console.log(value)
|
|
||||||
// }).catch((error) => {
|
|
||||||
// console.log(error)
|
|
||||||
// })
|
|
||||||
|
|
||||||
// let pathFile = ''
|
// console.log({e:await this.convertBlobToDataURL(a)})
|
||||||
// const fileName = filename
|
// let removePre = this.removeTextBeforeSlash(await this.convertBlobToDataURL(a),',')
|
||||||
// if (this.platform.is('ios')) {
|
|
||||||
// pathFile = this.file.documentsDirectory
|
|
||||||
// } else {
|
|
||||||
// pathFile = this.file.externalRootDirectory
|
|
||||||
// }
|
|
||||||
|
|
||||||
// console.log('file data', pdfString)
|
// Filesystem.writeFile({
|
||||||
// console.log(pathFile)
|
// path: filename,
|
||||||
|
// data: removePre,
|
||||||
|
// directory: Directory.Cache,
|
||||||
|
|
||||||
// let removePre = this.removeTextBeforeSlash(pdfString,',')
|
// }).then(dir => {
|
||||||
// console.log('file data remove ', removePre)
|
// 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({
|
async openFile(blobUrl:string, filename, fileType) {
|
||||||
// path: fileName,
|
|
||||||
// data: removePre,
|
let pathFile = ''
|
||||||
// directory: Directory.Cache,
|
const fileName = filename
|
||||||
// }).then((dir) => {
|
const contentFile = await this.fetchBlobFromURL(blobUrl)
|
||||||
// console.log('DIR ', dir)
|
if (this.platform.is('ios')) {
|
||||||
// this.fileOpener
|
pathFile = this.file.documentsDirectory
|
||||||
// .open(dir.uri, type)
|
} else {
|
||||||
// .then(() => console.log())
|
pathFile = this.file.cacheDirectory
|
||||||
// .catch(e => console.error(e))
|
}
|
||||||
// }).catch((error) => {
|
console.log(pathFile)
|
||||||
// console.log('error writing the file', error)
|
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) {
|
removeTextBeforeSlash(inputString, controlString) {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { IRoom, RoomEntitySchema } from "src/app/core/chat/entity/group";
|
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";
|
import { isDocument } from "src/app/utils/document-mimetype";
|
||||||
|
|
||||||
export class RoomViewModel implements IRoom {
|
export class RoomViewModel implements IRoom {
|
||||||
@@ -19,12 +20,17 @@ export class RoomViewModel implements IRoom {
|
|||||||
Object.assign(this, model)
|
Object.assign(this, model)
|
||||||
this.formatarData()
|
this.formatarData()
|
||||||
|
|
||||||
|
this.check()
|
||||||
|
}
|
||||||
|
|
||||||
|
check() {
|
||||||
if(this.messages?.[0]?.attachments[0]?.mimeType?.startsWith('image/') ) {
|
if(this.messages?.[0]?.attachments[0]?.mimeType?.startsWith('image/') ) {
|
||||||
this.lastMessageImage = true
|
this.lastMessageImage = true
|
||||||
} else if (this.messages?.[0]?.attachments[0]?.mimeType && isDocument({mimeType: this.messages?.[0]?.attachments[0]?.mimeType})) {
|
} else if (this.messages?.[0]?.attachments[0]?.mimeType && isDocument({mimeType: this.messages?.[0]?.attachments[0]?.mimeType})) {
|
||||||
this.lastMessageDocument = true
|
this.lastMessageDocument = true
|
||||||
|
} else if (this.messages?.[0]?.attachments[0]?.source == MessageAttachmentSource.Webtrix) {
|
||||||
|
this.lastMessageDocument = true
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
formatarData() {
|
formatarData() {
|
||||||
|
|||||||
Reference in New Issue
Block a user