improve chat

This commit is contained in:
Peter Maquiran
2022-02-03 21:01:53 +01:00
parent 33a2982805
commit 61de7b937b
13 changed files with 1147 additions and 668 deletions
@@ -26,6 +26,13 @@ import { ViewEventPage } from 'src/app/modals/view-event/view-event.page';
import { HttpEventType } from '@angular/common/http';
import { SqliteService } from 'src/app/services/sqlite.service';
import { WsChatMethodsService } from 'src/app/services/chat/ws-chat-methods.service';
import { AttachmentsService } from 'src/app/services/attachments.service';
import { FileType } from 'src/app/models/fileType';
import { Storage } from '@ionic/storage';
import { FileSystemService } from 'src/app/services/file-system.service';
import { CameraService } from 'src/app/services/camera.service';
import { SearchPage } from 'src/app/pages/search/search.page';
import { ProcessesService } from 'src/app/services/processes.service';
@Component({
selector: 'app-group-messages',
@@ -87,7 +94,12 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
private changeDetectorRef: ChangeDetectorRef,
private sqlservice: SqliteService,
private platform: Platform,
public wsChatMethodsService: WsChatMethodsService
public wsChatMethodsService: WsChatMethodsService,
private AttachmentsService: AttachmentsService,
private storage: Storage,
private processesService: ProcessesService,
private FileSystemService: FileSystemService,
private CameraService: CameraService,
) {
this.loggedUserChat = authService.ValidatedUserChat['data'];
this.isGroupCreated = true;
@@ -481,8 +493,150 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
}
}
async takePicture() {
const roomId = this.roomId
const image = await this.CameraService.takePicture();
await this.FileSystemService.saveImage(image, roomId)
const lastphoto: any = await this.FileSystemService.loadFiles(roomId);
const { capturedImage, capturedImageTitle} = await this.FileSystemService.loadFileData(lastphoto, roomId);
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);
this.AttachmentsService.downloadFile(guid.path).subscribe(async (event) => {
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) {
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 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,
}]
})
});
}
});
}
async addImage() {
this.addFileToChat(['image/apng', 'image/jpeg', 'image/png'])
}
async addFile() {
this.addFileToChat(['.doc', '.docx', '.pdf'])
}
async addFileWebtrix() {
const modal = await this.modalController.create({
component: SearchPage,
cssClass: 'group-messages modal-desktop search-modal search-modal-to-desktop',
componentProps: {
type: 'AccoesPresidenciais & ArquivoDespachoElect',
select: true,
showSearchInput: true,
}
});
await modal.present();
modal.onDidDismiss().then(async res=>{
const data = res.data;
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",
file:{
"name": res.data.selected.Assunto,
"type": "application/webtrix",
"ApplicationId": res.data.selected.ApplicationType,
"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"
}]
})
loader.remove();
}
});
}
async addFileToChat(types: typeof FileType[] ) {
const file = await this.fileService.getFileFromDevice(types);
const formData = new FormData();
formData.append("blobFile", file);
let guid: any = await this.AttachmentsService.uploadFile(formData).toPromise()
this.AttachmentsService.downloadFile(guid.path).subscribe(async (event) => {
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) {
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 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,
}]
})
});
}
});
}
async openChatOptions(ev?: any) {
console.log(this.members);
const roomId = this.roomId;
const popover = await this.popoverController.create({
component: ChatOptionsPopoverPage,
@@ -496,27 +650,65 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
translucent: true
});
await popover.present();
await popover.onDidDismiss().then((res)=>{
await popover.onDidDismiss().then( async(res)=>{
console.log(res['data']);
if(res['data'] == 'meeting'){
this.bookMeeting();
}
else if(res['data'] == 'take-picture'){
this.fileService.addCameraPictureToChat(this.roomId);
//this.loadPicture();
else if(res['data'] == 'take-picture') {
const image = await this.CameraService.takePicture();
await this.FileSystemService.saveImage(image, roomId)
const lastphoto: any = await this.FileSystemService.loadFiles(roomId);
const { capturedImage, capturedImageTitle} = await this.FileSystemService.loadFileData(lastphoto, roomId);
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);
this.AttachmentsService.downloadFile(guid.path).subscribe(async (event) => {
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) {
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 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,
}]
})
});
}
});
}
else if(res['data'] == 'add-picture'){
this.fileService.addPictureToChatMobile(this.roomId);
//this.loadPicture();
this.addImage()
}
else if(res['data'] == 'add-document'){
this.fileService.addDocumentToChat(this.roomId);
//this.loadDocument();
this.addFile()
}
else if(res['data'] == 'documentoGestaoDocumental'){
this.fileService.addDocGestaoDocumentalToChat(this.roomId);
//this.addDocGestaoDocumental();
this.addFileWebtrix()
}
this.loadGroupMessages(this.roomId);
});
@@ -742,7 +934,7 @@ 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) => {
this.AttachmentsService.downloadFile(msg.file.guid).subscribe(async (event) => {
console.log('FILE TYPE 22', msg.file.guid)
var name = msg.file.guid;