mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
improve chat
This commit is contained in:
@@ -26,7 +26,12 @@ import { Storage } from '@ionic/storage';
|
||||
import { WsChatMethodsService } from 'src/app/services/chat/ws-chat-methods.service'
|
||||
import { WsChatService } from 'src/app/services/chat/ws-chat.service'
|
||||
import { MessageService } from 'src/app/services/chat/message.service';
|
||||
import { element } from 'protractor';
|
||||
import { AttachmentsService } from 'src/app/services/attachments.service';
|
||||
import { FileSystemService } from 'src/app/services/file-system.service';
|
||||
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';
|
||||
|
||||
const IMAGE_DIR = 'stored-images';
|
||||
@Component({
|
||||
@@ -92,7 +97,11 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
private router: Router,
|
||||
private storage: Storage,
|
||||
public wsChatMethodsService: WsChatMethodsService,
|
||||
public WsChatService: WsChatService
|
||||
public WsChatService: WsChatService,
|
||||
private AttachmentsService: AttachmentsService,
|
||||
private FileSystemService: FileSystemService,
|
||||
private CameraService: CameraService,
|
||||
private processesService: ProcessesService,
|
||||
) {
|
||||
|
||||
this.loggedUser = authService.ValidatedUserChat['data'];
|
||||
@@ -113,7 +122,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
|
||||
ngOnInit() {
|
||||
this.scrollToBottom();
|
||||
this.setStatus('online');
|
||||
|
||||
}
|
||||
|
||||
@@ -133,15 +141,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
});
|
||||
}
|
||||
|
||||
setStatus(status: string) {
|
||||
let body = {
|
||||
message: '',
|
||||
status: status,
|
||||
}
|
||||
this.chatService.setUserStatus(body).subscribe(res => {
|
||||
console.log(res);
|
||||
})
|
||||
}
|
||||
|
||||
notImplemented() {
|
||||
this.alertService.presentAlert('Funcionalidade em desenvolvimento');
|
||||
@@ -149,7 +148,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
|
||||
load = () => {
|
||||
this.checktimeOut = true;
|
||||
this.serverLongPull();
|
||||
this.getChatMembers();
|
||||
}
|
||||
|
||||
@@ -204,7 +202,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
|
||||
ngOnDestroy() {
|
||||
this.checktimeOut = false;
|
||||
this.setStatus('away');
|
||||
window.removeEventListener('scroll', this.scrollChangeCallback, true);
|
||||
}
|
||||
|
||||
@@ -250,7 +247,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
|
||||
async viewDocument(msg: any, url?: string) {
|
||||
if (msg.file.type == "application/img") {
|
||||
let response: any = await this.fileService.getFile(msg.file.guid).toPromise();
|
||||
let response: any = await this.AttachmentsService.getFile(msg.file.guid).toPromise();
|
||||
console.log(response);
|
||||
alert(response);
|
||||
|
||||
@@ -266,7 +263,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
//fullUrl = "http://www.africau.edu/images/default/sample.pdf";
|
||||
|
||||
this.frameUrl = fullUrl;
|
||||
//this.fileService.viewDocumentByUrl(fullUrl);
|
||||
|
||||
this.chatService.getDocumentDetails(fullUrl);
|
||||
}
|
||||
}
|
||||
@@ -438,22 +435,147 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
|
||||
|
||||
|
||||
takePicture() {
|
||||
async takePicture() {
|
||||
const roomId = this.roomId
|
||||
this.fileService.addCameraPictureToChat(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({
|
||||
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,
|
||||
}]
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
addImage() {
|
||||
const roomId = this.roomId;
|
||||
this.fileService.addPictureToChat(roomId);
|
||||
//this.fileService.loadPicture();
|
||||
//this.fileService.addPictureToChat(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 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,
|
||||
}]
|
||||
})
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
bookMeeting() {
|
||||
let data = {
|
||||
roomId: this.roomId,
|
||||
@@ -463,7 +585,13 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
}
|
||||
|
||||
|
||||
chatSendFile() {
|
||||
|
||||
}
|
||||
|
||||
async _openChatOptions() {
|
||||
const roomId = this.roomId;
|
||||
|
||||
|
||||
const enterAnimation = (baseEl: any) => {
|
||||
const backdropAnimation = this.animationController.create()
|
||||
@@ -499,8 +627,10 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
}
|
||||
});
|
||||
await modal.present();
|
||||
modal.onDidDismiss().then((res) => {
|
||||
modal.onDidDismiss().then( async (res) => {
|
||||
console.log(res['data']);
|
||||
|
||||
|
||||
if (res['data'] == 'meeting') {
|
||||
//this.closeAllDesktopComponents.emit();
|
||||
let data = {
|
||||
@@ -510,63 +640,30 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
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.fileService.addDocumentToChat(this.roomId);
|
||||
//this.loadDocument();
|
||||
|
||||
this.addFile()
|
||||
|
||||
}
|
||||
else if (res['data'] == 'documentoGestaoDocumental') {
|
||||
|
||||
this.fileService.addDocGestaoDocumentalToChat(this.roomId);
|
||||
this.addFileWebtrix()
|
||||
|
||||
this.showLoader = false;
|
||||
//this.addDocGestaoDocumental();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
async serverLongPull() {
|
||||
|
||||
const roomId = this.roomId;
|
||||
|
||||
this.chatService.getRoomMessages(this.roomId).subscribe(async res => {
|
||||
console.log('serverLongPull', res['success']);
|
||||
|
||||
|
||||
if (res['success'] == true) {
|
||||
// Show Error
|
||||
//showMessage(response.statusText);
|
||||
/* this.messages = res['messages'].reverse();
|
||||
this.chatMessageStore.add(roomId, this.messages) */
|
||||
console.log('MSG FROM ROCKET ', res['messages'].reverse())
|
||||
/* this.transformData(res['messages'].reverse());
|
||||
this.getMessageDB(); */
|
||||
|
||||
//console.log(this.messages);
|
||||
// Reconnect in one second
|
||||
if (this.route.url != "/home/chat") {
|
||||
console.log("Timer message stop")
|
||||
}
|
||||
else {
|
||||
if (document.querySelector('app-messages')) {
|
||||
await new Promise(resolve => setTimeout(resolve, 5000));
|
||||
// await this.serverLongPull();
|
||||
this.getDirectMessages.emit();
|
||||
console.log('Timer message running')
|
||||
}
|
||||
}
|
||||
}
|
||||
}, (error) => {
|
||||
console.log(error);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
sliderOpts = {
|
||||
zoom: false,
|
||||
@@ -614,7 +711,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user