mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 21:06:06 +00:00
Storage add suceffuly to chat
This commit is contained in:
@@ -109,7 +109,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
console.log("Chat route", this.route.url)
|
||||
|
||||
this.setStatus('online');
|
||||
//this.getMessageDB();
|
||||
this.getMessageDB();
|
||||
}
|
||||
|
||||
onPressingMessage() {
|
||||
@@ -300,6 +300,21 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
mgsArray.push(chatmsg)
|
||||
|
||||
})
|
||||
} else {
|
||||
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,
|
||||
}
|
||||
|
||||
mgsArray.push(chatmsg)
|
||||
}
|
||||
} else {
|
||||
let chatmsg = {
|
||||
@@ -348,79 +363,8 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
|
||||
async viewDocument(msg: any, url?: string) {
|
||||
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);
|
||||
|
||||
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)
|
||||
});
|
||||
|
||||
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);
|
||||
this.downloadFileMsg(msg)
|
||||
|
||||
}
|
||||
else if (msg.file.type == "application/webtrix") {
|
||||
@@ -793,36 +737,12 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
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.storage.set(msg.file.guid, 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.readFile({
|
||||
path: `${IMAGE_DIR}/${name}`,
|
||||
directory: Directory.Data,
|
||||
}).then((foo) => {
|
||||
console.log('GET FILE WEB', foo)
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
console.log('FILE TYPE 44', this.downloadFile)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user