mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
lastest changes
This commit is contained in:
@@ -22,6 +22,7 @@ import { SqliteService } from 'src/app/services/sqlite.service';
|
||||
import { StorageService } from 'src/app/services/storage.service';
|
||||
import { Directory, Filesystem } from '@capacitor/filesystem';
|
||||
import { ViewEventPage } from 'src/app/modals/view-event/view-event.page';
|
||||
import { Storage } from '@ionic/storage';
|
||||
|
||||
const IMAGE_DIR = 'stored-images';
|
||||
@Component({
|
||||
@@ -85,6 +86,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
private sqliteservice: SqliteService,
|
||||
private storageservice: StorageService,
|
||||
private router: Router,
|
||||
private storage: Storage
|
||||
) {
|
||||
this.loggedUser = authService.ValidatedUserChat['data'];
|
||||
|
||||
@@ -107,6 +109,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
console.log("Chat route", this.route.url)
|
||||
|
||||
this.setStatus('online');
|
||||
this.getMessageDB();
|
||||
}
|
||||
|
||||
onPressingMessage() {
|
||||
@@ -258,8 +261,9 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
|
||||
|
||||
getMessageDB() {
|
||||
this.storageservice.get('chatmsg').then((msg) => {
|
||||
let msgArray =[];
|
||||
this.storage.get('chatmsg').then((msg) => {
|
||||
console.log('FROM DB WEB', msg)
|
||||
let msgArray = [];
|
||||
msgArray = msg;
|
||||
msgArray.filter(data => data._id != this.roomId);
|
||||
this.messages = msgArray.reverse();
|
||||
@@ -271,9 +275,18 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
transformData(res) {
|
||||
let mgsArray = [];
|
||||
res.forEach(async element => {
|
||||
/* console.log('Web TRANSFORM MSG', element)
|
||||
let image = await this.storageservice.get(element.file.guid);
|
||||
console.log('IMAGE STORAGE', image) */
|
||||
let image;
|
||||
|
||||
if (element.file) {
|
||||
try {
|
||||
image = await this.storage.get(element.file.guid) ?? console.log('CHECK VALUE UNDEFINE');
|
||||
console.log('IMAGE STORAGE', image)
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
let chatmsg = {
|
||||
_id: element._id,
|
||||
@@ -286,24 +299,29 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
ts: element.ts,
|
||||
u: element.u,
|
||||
_updatedAt: element._updatedAt,
|
||||
/* image_url: image, */
|
||||
image_url: image,
|
||||
}
|
||||
|
||||
mgsArray.push(chatmsg)
|
||||
|
||||
|
||||
|
||||
});
|
||||
console.log('Web TRANSFORM MSG', mgsArray)
|
||||
this.storage.remove('chatmsg').then(() => {
|
||||
console.log('MSG REMOVE FROM STORAGE')
|
||||
});
|
||||
this.storage.set('chatmsg', mgsArray).then(() => {
|
||||
console.log('MSG SAVED ON STORAGE')
|
||||
this.getMessageDB();
|
||||
});
|
||||
|
||||
console.log('Web TRANSFORM MSG', mgsArray)
|
||||
|
||||
this.storageservice.store('chatmsg',mgsArray);
|
||||
|
||||
}
|
||||
|
||||
loadMessages() {
|
||||
//this.showLoader = true;
|
||||
const roomId = this.roomId
|
||||
this.chatService.getRoomMessages(this.roomId).subscribe(res => {
|
||||
console.log('ALL MSG FROM CHATROCK',res);
|
||||
console.log('ALL MSG FROM CHATROCK', res);
|
||||
this.transformData(res['messages']);
|
||||
this.getMessageDB();
|
||||
//this.getFileFromLakeFS();
|
||||
@@ -320,78 +338,78 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
}
|
||||
|
||||
async viewDocument(msg: any, url?: string) {
|
||||
console.log('FILE TYPE',msg.file.type)
|
||||
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);
|
||||
console.log('FILE TYPE 22', msg.file.guid)
|
||||
var name = msg.file.guid;
|
||||
|
||||
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 )
|
||||
});
|
||||
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)
|
||||
|
||||
const readFile = await Filesystem.readdir({
|
||||
path: `${IMAGE_DIR}/${name}`,
|
||||
directory: Directory.Data,
|
||||
}).then((foo) => {
|
||||
console.log('GET FILE WEB', foo )
|
||||
});
|
||||
console.log('TRY ARRAY BUFFER NAME', name);
|
||||
console.log('TRY ARRAY BUFFER', this.downloadFile);
|
||||
|
||||
this.storageservice.get('chatmsg').then(async (msg) => {
|
||||
let msgArray =[];
|
||||
msgArray = msg;
|
||||
msgArray.filter(data => data._id != this.roomId);
|
||||
this.messages = msgArray.reverse();
|
||||
console.log("MSG CHAT WEB", this.messages)
|
||||
|
||||
let newmgsArray = [];
|
||||
msgArray.forEach(async element => {
|
||||
console.log('GET FILE TRANSFORM',element.file.guid )
|
||||
try {
|
||||
if(element.file.guid == msg.file.guid) {
|
||||
let chatmsg = {
|
||||
_id: element._id,
|
||||
attachments: element.attachments,
|
||||
channels: element.channels,
|
||||
file: element.file,
|
||||
mentions: element.mentions,
|
||||
msg: element.msg,
|
||||
rid: element.rid,
|
||||
ts: element.ts,
|
||||
u: element.u,
|
||||
_updatedAt: element._updatedAt,
|
||||
image_url: this.downloadFile
|
||||
}
|
||||
newmgsArray.push(chatmsg)
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
}
|
||||
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)
|
||||
});
|
||||
await this.storageservice.remove('chatmsg');
|
||||
await this.storageservice.store('chatmsg',newmgsArray);
|
||||
})
|
||||
}
|
||||
|
||||
this.getMessageDB();
|
||||
});
|
||||
const readFile = await Filesystem.readdir({
|
||||
path: `${IMAGE_DIR}/${name}`,
|
||||
directory: Directory.Data,
|
||||
}).then((foo) => {
|
||||
console.log('GET FILE WEB', foo)
|
||||
});
|
||||
|
||||
this.storage.get('chatmsg').then(async (msg) => {
|
||||
let msgArray = [];
|
||||
msgArray = msg;
|
||||
msgArray.filter(data => data._id != this.roomId);
|
||||
this.messages = msgArray.reverse();
|
||||
console.log("MSG CHAT WEB", this.messages)
|
||||
|
||||
let newmgsArray = [];
|
||||
msgArray.forEach(async element => {
|
||||
console.log('GET FILE TRANSFORM', element.file.guid)
|
||||
try {
|
||||
if (element.file.guid == msg.file.guid) {
|
||||
let chatmsg = {
|
||||
_id: element._id,
|
||||
attachments: element.attachments,
|
||||
channels: element.channels,
|
||||
file: element.file,
|
||||
mentions: element.mentions,
|
||||
msg: element.msg,
|
||||
rid: element.rid,
|
||||
ts: element.ts,
|
||||
u: element.u,
|
||||
_updatedAt: element._updatedAt,
|
||||
image_url: this.downloadFile
|
||||
}
|
||||
newmgsArray.push(chatmsg)
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
}
|
||||
});
|
||||
await this.storage.remove('chatmsg');
|
||||
await this.storage.set('chatmsg', newmgsArray);
|
||||
})
|
||||
}
|
||||
|
||||
this.getMessageDB();
|
||||
});
|
||||
|
||||
//this.openPreview(msg);
|
||||
|
||||
@@ -401,7 +419,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
}
|
||||
else {
|
||||
let fullUrl;
|
||||
fullUrl = "https://www.tabularium.pt" + url;
|
||||
fullUrl = "https://gabinetedigitalchat.dyndns.info" + url;
|
||||
//fullUrl = "http://www.africau.edu/images/default/sample.pdf";
|
||||
|
||||
this.frameUrl = fullUrl;
|
||||
@@ -672,15 +690,20 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
const roomId = this.roomId;
|
||||
|
||||
this.chatService.getRoomMessages(this.roomId).subscribe(async res => {
|
||||
//console.log(res['success']);
|
||||
console.log('serverLongPull', res['success']);
|
||||
|
||||
|
||||
if (res['success'] == true) {
|
||||
// Show Error
|
||||
//showMessage(response.statusText);
|
||||
this.loadMessages()
|
||||
console.log('ALL MSG FROM CHATROCK', res);
|
||||
/* this.transformData(res['messages']);
|
||||
this.getMessageDB(); */
|
||||
this.transformData(res['messages']);
|
||||
this.getMessageDB();
|
||||
/*
|
||||
this.messages = res['messages'].reverse();
|
||||
this.chatMessageStore.add(roomId, this.messages)
|
||||
this.chatMessageStore.add(roomId, this.messages) */
|
||||
|
||||
//console.log(this.messages);
|
||||
// Reconnect in one second
|
||||
@@ -766,7 +789,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
console.log('TRY ARRAY BUFFER NAME', name);
|
||||
console.log('TRY ARRAY BUFFER', this.downloadFile);
|
||||
|
||||
this.storageservice.store(msg.file.guid,this.downloadFile);
|
||||
this.storage.set(msg.file.guid, this.downloadFile);
|
||||
|
||||
await Filesystem.writeFile({
|
||||
path: `${IMAGE_DIR}/${name}`,
|
||||
@@ -783,7 +806,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
directory: Directory.Data,
|
||||
}).then((foo) => {
|
||||
console.log('GET FILE WEB', foo)
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@@ -796,7 +819,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
}
|
||||
|
||||
async openPreview(msg) {
|
||||
if(msg.image_url = "") {
|
||||
if (msg.image_url = "") {
|
||||
const modal = await this.modalController.create({
|
||||
component: ViewMediaPage,
|
||||
cssClass: 'modal modal-desktop',
|
||||
@@ -810,7 +833,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
} else {
|
||||
this.downloadFileMsg(msg)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user