diff --git a/src/app/pages/chat/chat.page.ts b/src/app/pages/chat/chat.page.ts index 5bd4148f8..3627afcae 100644 --- a/src/app/pages/chat/chat.page.ts +++ b/src/app/pages/chat/chat.page.ts @@ -148,6 +148,7 @@ export class ChatPage implements OnInit { this.load(); this.getDirectMessagesDB(); + this.getGroupsDB() }); /* websocket functions */ diff --git a/src/app/pages/chat/messages/messages.page.html b/src/app/pages/chat/messages/messages.page.html index 97799ed82..ccc0a8b3c 100644 --- a/src/app/pages/chat/messages/messages.page.html +++ b/src/app/pages/chat/messages/messages.page.html @@ -51,7 +51,7 @@
-
+
{{msg.u.name}} {{showDateDuration(msg._updatedAt)}} @@ -59,16 +59,15 @@
{{msg.msg}}
- image
-
- image +
+ image
-
+
diff --git a/src/app/pages/chat/messages/messages.page.ts b/src/app/pages/chat/messages/messages.page.ts index 20ba00ac8..ac53a29ac 100644 --- a/src/app/pages/chat/messages/messages.page.ts +++ b/src/app/pages/chat/messages/messages.page.ts @@ -78,6 +78,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { @ViewChild('recordbtn', { read: ElementRef }) recordBtn: ElementRef; myAudio: any; downloadfile: any; + downloadFile: any; constructor( public popoverController: PopoverController, @@ -343,7 +344,6 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { } viewDocument(file: any, url?: string) { - console.log(file); if (file.type == "application/webtrix") { this.openViewDocumentModal(file); @@ -757,18 +757,68 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { card.el.style['z-index'] = 11; } + downloadFileMsg(msg) { + console.log('FILE TYPE', msg.file.type) + this.downloadFile = ""; + if (msg.file.type == "application/img") { + this.fileService.downloadFile(msg.file.guid).subscribe(async (event) => { + console.log('FILE TYPE 22', msg.file.guid) + var name = msg.file.guid; + + if (event.type === HttpEventType.DownloadProgress) { + //this.downloadProgess = Math.round((100 * event.loaded) / event.total); + console.log('FILE TYPE 33', msg.file.type) + } else if (event.type === HttpEventType.Response) { + this.downloadFile = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), '')); + console.log('FILE TYPE 44', this.downloadFile) + + console.log('TRY ARRAY BUFFER NAME', name); + console.log('TRY ARRAY BUFFER', this.downloadFile); + + this.sqlservice.updateChatMsg(msg._id, this.downloadFile); + + await Filesystem.writeFile({ + path: `${IMAGE_DIR}/${name}`, + data: this.downloadFile, + directory: Directory.Data + }).then((foo) => { + console.log('SAVED FILE WEB', foo) + }).catch((error) => { + console.log('SAVED FILE WEB error ', error) + }); + + const readFile = await Filesystem.readdir({ + path: `${IMAGE_DIR}/${name}`, + directory: Directory.Data, + }).then((foo) => { + console.log('GET FILE WEB', foo) + }); + } + + }); + + console.log('FILE TYPE 44', this.downloadFile) + + } + + } async openPreview(msg) { - const modal = await this.modalController.create({ - component: ViewMediaPage, - cssClass: 'modal modal-desktop', - componentProps: { - image: msg.attachments[0].image_url, - username: msg.u.name, - _updatedAt: msg._updatedAt, - } - }); - modal.present(); + if(msg.image_url != "") { + this.downloadFile(); + } else { + const modal = await this.modalController.create({ + component: ViewMediaPage, + cssClass: 'modal modal-desktop', + componentProps: { + image: msg.attachments[0].image_url, + username: msg.u.name, + _updatedAt: msg._updatedAt, + } + }); + modal.present(); + + } } diff --git a/src/app/services/functions/file.service.ts b/src/app/services/functions/file.service.ts index b011b1cc8..cfd5de3ff 100644 --- a/src/app/services/functions/file.service.ts +++ b/src/app/services/functions/file.service.ts @@ -87,7 +87,7 @@ export class FileService { downloadFile(guid:any) { - let downloadUrl = 'https://equilibrium.dyndns.info/GabineteDigital.Services/V5/api/objectserver/streamfiles?path='+guid; + let downloadUrl = environment.apiURL +'objectserver/streamfiles?path='+guid; var name = new Date().getTime(); return this.http.get(downloadUrl, { responseType: "arraybuffer", diff --git a/src/app/services/sqlite.service.ts b/src/app/services/sqlite.service.ts index 6e2f87937..640fc9ad3 100644 --- a/src/app/services/sqlite.service.ts +++ b/src/app/services/sqlite.service.ts @@ -279,7 +279,7 @@ export class SqliteService { public addChatMSG(data) { console.log('INSIDE DB CHAT MSG',data,) this.dbInstance.executeSql(` - INSERT OR REPLACE INTO ${this.chatmsg} (Id,Attachments,Channels,File,Mentions,Msg,Rid, Ts ,U, UpdatedAt,image_url) + INSERT OR IGNORE INTO ${this.chatmsg} (Id,Attachments,Channels,File,Mentions,Msg,Rid, Ts ,U, UpdatedAt,image_url) VALUES ('${data._id}','${JSON.stringify(data.attachments)}','${JSON.stringify(data.channels)}','${JSON.stringify(data.file)}','${JSON.stringify(data.mentions)}','${data.msg}','${data.rid}','${data.ts}','${JSON.stringify(data.u)}','${data._updatedAt}','${JSON.stringify(data.image_url)}')`, []) .then(() => { console.log("chat msg add with Success"); @@ -319,6 +319,22 @@ export class SqliteService { } + //updateChatMsg + public updateChatMsg(id, data) { + try { + console.log("update action data", data) + this.dbInstance.executeSql(` + UPDATE ${this.chatmsg} SET image_url = ? WHERE Id = ${id}`, [data]) + .then(() => { + console.log("ChatMsg update with Success"); + + }, (e) => { + console.log(JSON.stringify(e.err)); + }); + } catch(error) {} + + } + //updateprocess public updateProcess(data) { diff --git a/src/app/shared/chat/messages/messages.page.html b/src/app/shared/chat/messages/messages.page.html index abbada216..c5475e9c4 100644 --- a/src/app/shared/chat/messages/messages.page.html +++ b/src/app/shared/chat/messages/messages.page.html @@ -56,7 +56,7 @@
- image + image