This commit is contained in:
Peter Maquiran
2022-02-07 13:41:27 +01:00
17 changed files with 1120 additions and 1107 deletions
@@ -26,6 +26,12 @@ import { HttpEventType } from '@angular/common/http';
import { Storage } from '@ionic/storage';
import { WsChatMethodsService } from 'src/app/services/chat/ws-chat-methods.service';
import { MessageService } from 'src/app/services/chat/message.service';
import { AttachmentsService } from 'src/app/services/attachments.service';
import { CameraService } from 'src/app/services/camera.service';
import { element } from 'protractor';
import { FileType } from 'src/app/models/fileType';
import { ToastService } from 'src/app/services/toast.service';
/*
import * as pdfjsLib from 'pdfjs-dist';
@@ -96,6 +102,10 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
public ThemeService: ThemeService,
private changeDetectorRef: ChangeDetectorRef,
private storage: Storage,
private AttachmentsService: AttachmentsService,
private CameraService: CameraService,
private toastService: ToastService,
) {
console.log('OnCONSTRUCTOR');
@@ -129,7 +139,6 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
setTimeout(() => {
this.getRoomInfo();
}, 1000);
this.setStatus('online');
this.getChatMembers();
//this.getMessageDB();
@@ -216,7 +225,6 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
}
ngOnDestroy() {
this.setStatus('away');
window.removeEventListener('scroll', this.scrollChangeCallback, true);
}
@@ -297,17 +305,8 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
}
}
loadGroupMessages(roomId) {
this.showLoader = true;
this.chatService.getPrivateGroupMessages(this.roomId).subscribe(res => {
console.log(res);
let msgOnly = res['messages'].filter(data => data.t != 'au');
this.showLoader = false;
});
}
sendMessage() {
this.wsChatMethodsService.getGroupRoom(this.roomId).send()
this.wsChatMethodsService.getGroupRoom(this.roomId).send({})
}
deleteMessage(msgId: string, room:any) {
@@ -388,10 +387,6 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
else {
this.roomName = res.data.name.split('-').join(' ');
console.log(this.roomName);
//this.getRoomInfo();
this.loadGroupMessages(this.roomId);
//this.modalController.dismiss();
};
});
@@ -423,7 +418,6 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
popover.onDidDismiss().then(res => {
console.log(res);
if (res.data) {
this.loadGroupMessages(this.roomId);
//this.getRoomInfo();
//this.modalController.dismiss();
};
@@ -464,89 +458,9 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
modal.onDidDismiss().then(() => {
//this.getRoomInfo();
this.loadGroupMessages(this.roomId)
});
}
loadPicture() {
const input = this.fileLoaderService.createInput({
accept: ['image/apng', 'image/jpeg', 'image/png']
})
input.onchange = async () => {
const file = this.fileLoaderService.getFirstFile(input)
console.log(file);
const imageData = await this.fileToBase64Service.convert(file)
this.capturedImage = imageData;
this.capturedImageTitle = file.name;
let body = {
"message":
{
"rid": this.roomId,
"msg": "",
"attachments": [{
//"title": this.capturedImageTitle ,
//"text": "description",
"title_link_download": false,
"image_url": this.capturedImage,
}]
}
}
this.chatService.sendMessage(body).subscribe(res => {
console.log(res);
}, (error) => {
});
//console.log(this.capturedImage)
};
}
loadDocument() {
const input = this.fileLoaderService.createInput({
accept: ['.doc', '.docx', '.pdf']
})
input.onchange = async () => {
const file = this.fileLoaderService.getFirstFile(input)
console.log(file);
const imageData = await this.fileToBase64Service.convert(file)
this.capturedImage = imageData;
this.capturedImageTitle = file.name;
let body = {
"message":
{
"rid": this.roomId,
"msg": "",
"attachments": [{
"title": this.capturedImageTitle,
"text": "",
"title_link": this.capturedImage,
"title_link_download": true,
"thumb_url": "https://static.ichimura.ed.jp/uploads/2017/10/pdf-icon.png",
"message_link": this.capturedImage,
}],
"file": {
"name": this.capturedImageTitle,
"type": "application/pdf",
}
}
}
this.chatService.sendMessage(body).subscribe(res => {
//console.log(res);
}, (error) => {
});
//console.log(this.capturedImage)
};
}
async addDocGestaoDocumental() {
const modal = await this.modalController.create({
@@ -563,36 +477,8 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
if (res) {
const data = res.data;
this.documents.push(data.selected);
console.log(res.data.selected);
console.log(res.data.selected.Id);
console.log(res.data.selected.ApplicationType);
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);
//console.log('Oie');
let body = {
"message":
{
"rid": this.roomId,
"msg": "",
"attachments": [{
"title": res.data.selected.Assunto,
"text": res.data.selected.DocTypeDesc,
"title_link": url_no_options,
"title_link_download": true,
"thumb_url": "https://static.ichimura.ed.jp/uploads/2017/10/pdf-icon.png",
"message_link": url_no_options,
}]
}
}
this.chatService.sendMessage(body).subscribe(res => {
console.log(res);
}, (error) => {
});
this.addFileWebtrix()
}
});
}
@@ -656,18 +542,183 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
await modal.present();
}
takePicture() {
this.fileService.addCameraPictureToChat(this.roomId);
async takePicture() {
const roomId = this.roomId
const image = await this.CameraService.takePicture();
await this.fileService.saveImage(image)
const lastphoto: any = await this.fileService.loadFiles();
const { capturedImage, capturedImageTitle} = await this.fileService.loadFileData(lastphoto);
const { message, updateMessage} = this.wsChatMethodsService.getDmRoom(roomId).send({
file: {
"type": "application/img",
"guid": '',
"image_url": capturedImage
},
attachments: [{
"title": capturedImageTitle ,
"text": "description",
"title_link_download": false,
}]
})
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()
updateMessage({
file: {
type: "application/img",
guid: guid.path,
image_url: capturedImage
}
})
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', capturedImage);
await this.storage.set(guid.path, capturedImage).then(() => {
console.log('add picture to chat IMAGE SAVED')
message.getFileFromDb()
});
}
});
}
addImage() {
this.fileService.addPictureToChat(this.roomId);
async addImage() {
this.addFileToChat(['image/apng', 'image/jpeg', 'image/png'])
}
addFile() {
this.fileService.addDocumentToChat(this.roomId);
async addFile() {
this.addFileToChat(['.doc', '.docx', '.pdf'])
}
addFileWebtrix() {
this.fileService.addDocGestaoDocumentalToChat(this.roomId);
async addFileWebtrix() {
const roomId = this.roomId
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();
const { message, updateMessage} = this.wsChatMethodsService.getDmRoom(roomId).send({
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"
}]
})
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,
"title_link": url_no_options,
"title_link_download": true,
//"thumb_url": "assets/images/webtrix-logo.png",
"message_link": url_no_options,
"type": "webtrix",
"text": res.data.selected.DocTypeDesc,
"thumb_url": "https://static.ichimura.ed.jp/uploads/2017/10/pdf-icon.png",
}]
})
loader.remove();
}
});
}
async addFileToChat(types: typeof FileType[] ) {
const roomId = this.roomId
const file: any = 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(roomId).send({
file: {
"type": "application/img",
"guid": '',
"image_url": imageData
},
attachments: [{
"title": file.name ,
"text": "description",
"title_link_download": false,
}]
})
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) {
//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')
message.getFileFromDb()
});
}
});
}
bookMeeting() {
let data = {
roomId: this.roomId,
@@ -693,7 +744,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
return this.animationController.create()
.addElement(baseEl)
.easing('ease-out')
.duration(5000)
.duration(500)
.addAnimation([backdropAnimation, wrapperAnimation]);
}
@@ -711,10 +762,11 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
members: this.members,
}
});
await modal.present();
modal.onDidDismiss().then((res) => {
//console.log(res['data']);
modal.onDidDismiss().then( async (res) => {
console.log(res['data']);
const roomId = this.roomId;
if (res['data'] == 'meeting') {
//this.closeAllDesktopComponents.emit();
let data = {
@@ -724,73 +776,36 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
this.openNewEventPage.emit(data);
}
else if (res['data'] == 'take-picture') {
this.fileService.addCameraPictureToChat(this.roomId);
//this.loadPicture();
this.takePicture()
}
else if (res['data'] == 'add-picture') {
this.fileService.addPictureToChat(this.roomId);
//this.loadPicture();
this.addImage()
}
else if (res['data'] == 'add-document') {
this.loadDocument();
this.addFile()
}
else if (res['data'] == 'documentoGestaoDocumental') {
this.fileService.addDocGestaoDocumentalToChat(this.roomId);
//this.addDocGestaoDocumental();
this.addFileWebtrix()
this.showLoader = false;
}
this.loadGroupMessages(this.roomId);
});
}
sliderOpts = {
zoom: false,
slidesPerView: 1.5,
spaceBetween: 20,
centeredSlides: true
};
zoomActive = false;
zoomScale = 1;
sliderZoomOpts = {
allowSlidePrev: false,
allowSlideNext: false,
zoom: {
maxRatio: 5
},
on: {
zoomChange: (scale, imageEl, slideEl) => {
this.zoomActive = true;
this.zoomScale = scale / 5;
this.changeDetectorRef.detectChanges();
}
}
}
async touchEnd(zoomslides: IonSlides, card) {
// Zoom back to normal
const slider = await zoomslides.getSwiper();
const zoom = slider.zoom;
zoom.out();
// Card back to normal
card.el.style['z-index'] = 9;
this.zoomActive = false;
this.changeDetectorRef.detectChanges();
}
touchStart(card) {
// Make card appear above backdrop
card.el.style['z-index'] = 11;
}
downloadFileMsg(msg: MessageService) {
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;