offline messagens

This commit is contained in:
Peter Maquiran
2022-02-04 00:22:35 +01:00
parent 61de7b937b
commit 0f04ad98c2
11 changed files with 381 additions and 239 deletions
@@ -97,7 +97,7 @@
<ion-label *ngIf="msg.file">
<span *ngIf="file.description">{{file.description}}</span>
<span *ngIf="file.description && msg.file.type != 'application/webtrix'"></span>
<span *ngIf="msg.file.type != 'application/webtrix'">{{msg.file.type.replace('application/','').toUpperCase()}}</span>
<span *ngIf="msg.file.type != 'application/webtrix'">{{msg.displayType}}</span>
</ion-label>
</div>
</div>
@@ -317,7 +317,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
}
sendMessage() {
this.wsChatMethodsService.getGroupRoom(this.roomId).send()
this.wsChatMethodsService.getGroupRoom(this.roomId).send({})
}
deleteMessage(msgId: string, room:any) {
@@ -674,13 +674,36 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
const lastphoto: any = await this.FileSystemService.loadFiles(roomId);
const { capturedImage, capturedImageTitle} = await this.FileSystemService.loadFileData(lastphoto, roomId);
const { message, updateMessage} = this.wsChatMethodsService.getDmRoom(this.roomId).send({
file: {
"type": "application/img",
"guid": '',
"image_url": capturedImage
},
attachments: [{
//"title": this.capturedImageTitle ,
//"text": "description",
"title_link_download": false,
//"image_url": this.capturedImage,
}]
})
const base64 = await fetch(capturedImage);
const blob = await base64.blob();
const formData = new FormData();
formData.append("blobFile", blob);
console.log('ALL IMAGE', formData)
let guid: any = await this.AttachmentsService.uploadFile(formData).toPromise()
console.log(guid.path);
updateMessage({
file: {
type: "application/img",
guid: guid.path,
image_url: capturedImage
}
})
this.AttachmentsService.downloadFile(guid.path).subscribe(async (event) => {
@@ -689,25 +712,12 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
//console.log('FILE TYPE 33', msg.file.type)
} else if (event.type === HttpEventType.Response) {
var fileImage = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), ''));
console.log('add picture to chat',fileImage);
await this.storage.set(guid.path, fileImage).then(() => {
console.log('add picture to chat', capturedImage);
await this.storage.set(guid.path, capturedImage).then(() => {
console.log('add picture to chat IMAGE SAVED')
this.wsChatMethodsService.getDmRoom(this.roomId).sendFile({
file: {
"type": "application/img",
"guid": guid.path,
"image_url": fileImage
},
attachments: [{
//"title": this.capturedImageTitle ,
//"text": "description",
"title_link_download": false,
//"image_url": this.capturedImage,
}]
})
message.getFileFromDb()
});
}
});
@@ -736,15 +746,10 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
modal.onDidDismiss().then(async res=>{
const data = res.data;
if(data.selected){
if(data.selected) {
const loader = this.toastService.loading();
let url = await this.processesService.GetDocumentUrl(res.data.selected.Id, res.data.selected.ApplicationType).toPromise();
let url_no_options: string = url.replace("webTRIX.Viewer","webTRIX.Viewer.Branch1");
console.log(url_no_options);
this.wsChatMethodsService.getDmRoom(this.roomId).sendFile({
alias: "documento",
const { message, updateMessage} = this.wsChatMethodsService.getDmRoom(this.roomId).send({
file:{
"name": res.data.selected.Assunto,
"type": "application/webtrix",
@@ -752,6 +757,22 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
"DocId": res.data.selected.Id,
"Assunto": res.data.selected.Assunto,
},
attachments: [{
"title": res.data.selected.Assunto,
"description": res.data.selected.DocTypeDesc,
// "title_link": url_no_options,
"title_link_download": true,
//"thumb_url": "assets/images/webtrix-logo.png",
// "message_link": url_no_options,
"type": "webtrix"
}]
})
let url = await this.processesService.GetDocumentUrl(res.data.selected.Id, res.data.selected.ApplicationType).toPromise();
let url_no_options: string = url.replace("webTRIX.Viewer","webTRIX.Viewer.Branch1");
console.log(url_no_options);
updateMessage({
attachments: [{
"title": res.data.selected.Assunto,
"description": res.data.selected.DocTypeDesc,
@@ -762,6 +783,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
"type": "webtrix"
}]
})
loader.remove();
}
@@ -769,11 +791,37 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
}
async addFileToChat(types: typeof FileType[] ) {
const file = await this.fileService.getFileFromDevice(types);
const imageData = await this.fileToBase64Service.convert(file)
const formData = new FormData();
formData.append("blobFile", file);
const { message, updateMessage} = this.wsChatMethodsService.getDmRoom(this.roomId).send({
file: {
"type": "application/img",
"guid": '',
"image_url": imageData
},
attachments: [{
//"title": this.capturedImageTitle ,
//"text": "description",
"title_link_download": false,
//"image_url": this.capturedImage,
}]
})
let guid: any = await this.AttachmentsService.uploadFile(formData).toPromise()
updateMessage({
file: {
type: "application/img",
guid: guid.path,
image_url: imageData
}
})
this.AttachmentsService.downloadFile(guid.path).subscribe(async (event) => {
if (event.type === HttpEventType.DownloadProgress) {
@@ -784,21 +832,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
console.log('add picture to chat',fileImage);
await this.storage.set(guid.path, fileImage).then(() => {
console.log('add picture to chat IMAGE SAVED')
this.wsChatMethodsService.getDmRoom(this.roomId).sendFile({
file: {
"type": "application/img",
"guid": guid.path,
"image_url": fileImage
},
attachments: [{
//"title": this.capturedImageTitle ,
//"text": "description",
"title_link_download": false,
//"image_url": this.capturedImage,
}]
})
message.getFileFromDb()
});
}
@@ -887,7 +921,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
await this.storage.set(guid.path, fileImage).then(() => {
console.log('add picture to chat IMAGE SAVED')
this.wsChatMethodsService.getDmRoom(this.roomId).sendFile({
this.wsChatMethodsService.getDmRoom(this.roomId).send({
file: {
"type": "application/img",
"guid": guid.path,
@@ -97,7 +97,7 @@
<span *ngIf="file.description">{{file.description}}</span>
<span *ngIf="file.description && msg.file.type != 'application/webtrix'"></span>
<span
*ngIf="msg.file.type != 'application/webtrix'">{{msg.file.type.replace('application/','').toUpperCase()}}</span>
*ngIf="msg.file.type != 'application/webtrix'">{{msg.displayType}}</span>
</ion-label>
</div>
</div>
+82 -42
View File
@@ -32,6 +32,7 @@ import { CameraService } from 'src/app/services/camera.service';
import { FileType } from 'src/app/models/fileType';
import { SearchPage } from 'src/app/pages/search/search.page';
import { ProcessesService } from 'src/app/services/processes.service';
import { FileToBase64Service } from 'src/app/services/file/file-to-base64.service';
const IMAGE_DIR = 'stored-images';
@Component({
@@ -102,6 +103,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
private FileSystemService: FileSystemService,
private CameraService: CameraService,
private processesService: ProcessesService,
private fileToBase64Service: FileToBase64Service,
) {
this.loggedUser = authService.ValidatedUserChat['data'];
@@ -113,6 +115,11 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
this.wsChatMethodsService.getDmRoom(this.roomId).scrollDown = this.scrollToBottomClicked
this.wsChatMethodsService.openRoom(this.roomId)
this.wsChatMethodsService.getDmRoom(this.roomId).uploadAttachment = async (formData) => {
let guid: any = await this.AttachmentsService.uploadFile(formData).toPromise()
}
setTimeout(() => {
this.scrollToBottomClicked()
}, 150)
@@ -238,7 +245,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
}
sendMessage() {
this.wsChatMethodsService.getDmRoom(this.roomId).send()
this.wsChatMethodsService.getDmRoom(this.roomId).send({})
}
deleteMessage(msgId: string, room:any) {
@@ -443,13 +450,36 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
const lastphoto: any = await this.FileSystemService.loadFiles(roomId);
const { capturedImage, capturedImageTitle} = await this.FileSystemService.loadFileData(lastphoto, roomId);
const { message, updateMessage} = this.wsChatMethodsService.getDmRoom(this.roomId).send({
file: {
"type": "application/img",
"guid": '',
"image_url": capturedImage
},
attachments: [{
//"title": this.capturedImageTitle ,
//"text": "description",
"title_link_download": false,
//"image_url": this.capturedImage,
}]
})
const base64 = await fetch(capturedImage);
const blob = await base64.blob();
const formData = new FormData();
formData.append("blobFile", blob);
console.log('ALL IMAGE', formData)
let guid: any = await this.AttachmentsService.uploadFile(formData).toPromise()
console.log(guid.path);
updateMessage({
file: {
type: "application/img",
guid: guid.path,
image_url: capturedImage
}
})
this.AttachmentsService.downloadFile(guid.path).subscribe(async (event) => {
@@ -458,26 +488,12 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
//console.log('FILE TYPE 33', msg.file.type)
} else if (event.type === HttpEventType.Response) {
var fileImage = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), ''));
console.log('add picture to chat',fileImage);
await this.storage.set(guid.path, fileImage).then(() => {
console.log('add picture to chat', capturedImage);
await this.storage.set(guid.path, capturedImage).then(() => {
console.log('add picture to chat IMAGE SAVED')
message.getFileFromDb()
});
this.wsChatMethodsService.getDmRoom(this.roomId).sendFile({
alias: 'document',
file: {
"type": "application/img",
"guid": guid.path,
"image_url": fileImage
},
attachments: [{
//"title": this.capturedImageTitle ,
//"text": "description",
"title_link_download": false,
//"image_url": this.capturedImage,
}]
})
}
});
@@ -506,15 +522,10 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
modal.onDidDismiss().then(async res=>{
const data = res.data;
if(data.selected){
if(data.selected) {
const loader = this.toastService.loading();
let url = await this.processesService.GetDocumentUrl(res.data.selected.Id, res.data.selected.ApplicationType).toPromise();
let url_no_options: string = url.replace("webTRIX.Viewer","webTRIX.Viewer.Branch1");
console.log(url_no_options);
this.wsChatMethodsService.getDmRoom(this.roomId).sendFile({
alias: "documento",
const { message, updateMessage} = this.wsChatMethodsService.getDmRoom(this.roomId).send({
file:{
"name": res.data.selected.Assunto,
"type": "application/webtrix",
@@ -522,6 +533,22 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
"DocId": res.data.selected.Id,
"Assunto": res.data.selected.Assunto,
},
attachments: [{
"title": res.data.selected.Assunto,
"description": res.data.selected.DocTypeDesc,
// "title_link": url_no_options,
"title_link_download": true,
//"thumb_url": "assets/images/webtrix-logo.png",
// "message_link": url_no_options,
"type": "webtrix"
}]
})
let url = await this.processesService.GetDocumentUrl(res.data.selected.Id, res.data.selected.ApplicationType).toPromise();
let url_no_options: string = url.replace("webTRIX.Viewer","webTRIX.Viewer.Branch1");
console.log(url_no_options);
updateMessage({
attachments: [{
"title": res.data.selected.Assunto,
"description": res.data.selected.DocTypeDesc,
@@ -532,6 +559,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
"type": "webtrix"
}]
})
loader.remove();
}
@@ -539,11 +567,37 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
}
async addFileToChat(types: typeof FileType[] ) {
const file = await this.fileService.getFileFromDevice(types);
const imageData = await this.fileToBase64Service.convert(file)
const formData = new FormData();
formData.append("blobFile", file);
const { message, updateMessage} = this.wsChatMethodsService.getDmRoom(this.roomId).send({
file: {
"type": "application/img",
"guid": '',
"image_url": imageData
},
attachments: [{
//"title": this.capturedImageTitle ,
//"text": "description",
"title_link_download": false,
//"image_url": this.capturedImage,
}]
})
let guid: any = await this.AttachmentsService.uploadFile(formData).toPromise()
updateMessage({
file: {
type: "application/img",
guid: guid.path,
image_url: imageData
}
})
this.AttachmentsService.downloadFile(guid.path).subscribe(async (event) => {
if (event.type === HttpEventType.DownloadProgress) {
@@ -554,21 +608,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
console.log('add picture to chat',fileImage);
await this.storage.set(guid.path, fileImage).then(() => {
console.log('add picture to chat IMAGE SAVED')
this.wsChatMethodsService.getDmRoom(this.roomId).sendFile({
file: {
"type": "application/img",
"guid": guid.path,
"image_url": fileImage
},
attachments: [{
//"title": this.capturedImageTitle ,
//"text": "description",
"title_link_download": false,
//"image_url": this.capturedImage,
}]
})
message.getFileFromDb()
});
}
@@ -585,7 +625,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
}
chatSendFile() {
chatsend() {
}