diff --git a/src/app/pages/chat/chat.page.ts b/src/app/pages/chat/chat.page.ts
index 8c6c10a53..89a76b4d7 100644
--- a/src/app/pages/chat/chat.page.ts
+++ b/src/app/pages/chat/chat.page.ts
@@ -159,11 +159,6 @@ export class ChatPage implements OnInit {
let t = this.showDateDuration(new Date());
- this.setStatus('away');
- /* if(this.dataService.get("newGroup")){
- this.openNewGroupPage();
- } */
-
this.router.events.forEach((event) => {
if (event instanceof NavigationStart && event.url.startsWith('/home/chat')) {
if (this.dataService.get("newGroup")) {
diff --git a/src/app/pages/chat/group-messages/group-messages.page.html b/src/app/pages/chat/group-messages/group-messages.page.html
index a6b7ff0fb..00a341ca9 100644
--- a/src/app/pages/chat/group-messages/group-messages.page.html
+++ b/src/app/pages/chat/group-messages/group-messages.page.html
@@ -121,7 +121,7 @@
{{file.description}}
•
- {{msg.file.type.replace('application/','').toUpperCase()}}
+ {{msg.displayType}}
diff --git a/src/app/pages/chat/group-messages/group-messages.page.ts b/src/app/pages/chat/group-messages/group-messages.page.ts
index 56ffae756..5623e58b7 100644
--- a/src/app/pages/chat/group-messages/group-messages.page.ts
+++ b/src/app/pages/chat/group-messages/group-messages.page.ts
@@ -20,12 +20,18 @@ import { NewEventPage } from '../../agenda/new-event/new-event.page';
import { EventPerson } from 'src/app/models/eventperson.model';
import { ViewDocumentPage } from 'src/app/modals/view-document/view-document.page';
import { ThemeService } from 'src/app/services/theme.service'
-import { PreviewCameraPage } from 'src/app/modals/preview-camera/preview-camera.page';
import { ViewMediaPage } from 'src/app/modals/view-media/view-media.page';
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 { 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 +93,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 CameraService: CameraService,
) {
this.loggedUserChat = authService.ValidatedUserChat['data'];
this.isGroupCreated = true;
@@ -240,7 +251,6 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
this.roomCountDownDate = this.timeService.countDownDateTimer(this.room.customFields.countDownDate, this.room._id);
}
this.getGroupContacts(this.room);
- this.loadGroupMessages(this.room);
this.showLoader = false;
});
}
@@ -289,27 +299,6 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
}
}
- loadGroupMessages(room:any){
- this.showLoader = true;
- //If group is private call getGroupMembers
- if(this.room.t === 'p'){
- this.chatService.getPrivateGroupMessages(this.roomId).subscribe(res=>{
- console.log(res);
- let msgOnly = res['messages'].filter(data => data.t != 'au');
- //this.messages = msgOnly.reverse();
- this.transformDataMSG(msgOnly.reverse());
- this.getRoomMessageDB(this.roomId);
- this.showLoader = false;
- });
- }
- //Otherwise call getChannelMembers for públic groups
- /* else{
- this.chatService.getPublicGroupMessages(this.roomId).subscribe(res=>{
- console.log(res);
- this.messages = res['messages'].reverse();
- });
- } */
- }
showDateDuration(start:any){
return this.timeService.showDateDuration(start);
@@ -330,7 +319,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
sendMessage() {
- this.wsChatMethodsService.getGroupRoom(this.roomId).send()
+ this.wsChatMethodsService.getGroupRoom(this.roomId).send({})
}
async openOptions() {
@@ -357,42 +346,6 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
});
}
- 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)
- };
- }
viewDocument(file:any, url?:string){
@@ -484,8 +437,183 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
}
}
+
+
+ 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(this.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()
+ });
+
+ }
+
+ });
+
+ }
+
+ 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();
+
+ const { message, updateMessage} = this.wsChatMethodsService.getDmRoom(this.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 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(this.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()
+ });
+ }
+
+ });
+ }
+
async openChatOptions(ev?: any) {
console.log(this.members);
+ const roomId = this.roomId;
const popover = await this.popoverController.create({
component: ChatOptionsPopoverPage,
@@ -499,29 +627,25 @@ 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'){
+ 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') {
+ this.takePicture()
}
- else if(res['data'] == 'add-picture'){
- this.fileService.addPictureToChatMobile(this.roomId);
- //this.loadPicture();
- }
- else if(res['data'] == 'add-document'){
- this.fileService.addDocumentToChat(this.roomId);
- //this.loadDocument();
- }
- else if(res['data'] == 'documentoGestaoDocumental'){
+ else if (res['data'] == 'add-picture') {
+ this.addImage()
- this.fileService.addDocGestaoDocumentalToChat(this.roomId);
- //this.addDocGestaoDocumental();
}
- this.loadGroupMessages(this.roomId);
+ else if (res['data'] == 'add-document') {
+ this.addFile()
+ }
+ else if (res['data'] == 'documentoGestaoDocumental') {
+
+ this.addFileWebtrix()
+ }
});
}
@@ -745,7 +869,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;
diff --git a/src/app/pages/chat/messages/messages.page.html b/src/app/pages/chat/messages/messages.page.html
index ee9612b12..dabd8c88d 100644
--- a/src/app/pages/chat/messages/messages.page.html
+++ b/src/app/pages/chat/messages/messages.page.html
@@ -102,7 +102,7 @@
{{file.description}}
•
- {{msg.file.type.replace('application/','').toUpperCase()}}
+ {{msg.displayType}}
diff --git a/src/app/pages/chat/messages/messages.page.ts b/src/app/pages/chat/messages/messages.page.ts
index 63e80320f..cc7d24b79 100644
--- a/src/app/pages/chat/messages/messages.page.ts
+++ b/src/app/pages/chat/messages/messages.page.ts
@@ -1,11 +1,10 @@
import { AfterViewChecked, AfterViewInit, ChangeDetectorRef, Component, ElementRef, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router'
-import { GestureController, Gesture, ModalController, NavParams, PopoverController, IonSlides, Platform } from '@ionic/angular';
+import { GestureController, Gesture, ModalController, NavParams, PopoverController, Platform } from '@ionic/angular';
import { map } from 'rxjs/operators';
import { ViewDocumentPage } from 'src/app/modals/view-document/view-document.page';
import { EventPerson } from 'src/app/models/eventperson.model';
import { ExpedientTaskModalPageNavParamsTask } from 'src/app/models/ExpedientTaskModalPage';
-import { SearchDocumentDetails, SearchFolderDetails } from 'src/app/models/search-document';
import { ContactsPage } from 'src/app/pages/chat/messages/contacts/contacts.page';
import { AlertService } from 'src/app/services/alert.service';
import { AuthService } from 'src/app/services/auth.service';
@@ -31,6 +30,14 @@ import { HttpEventType } from '@angular/common/http';
import { ViewEventPage } from 'src/app/modals/view-event/view-event.page';
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 { SearchPage } from 'src/app/pages/search/search.page';
+import { Storage } from '@ionic/storage';
+import { FileToBase64Service } from 'src/app/services/file/file-to-base64.service';
const IMAGE_DIR = 'stored-images';
@@ -98,7 +105,13 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
private changeDetectorRef: ChangeDetectorRef,
private platform: Platform,
private sqlservice: SqliteService,
- public wsChatMethodsService: WsChatMethodsService
+ public wsChatMethodsService: WsChatMethodsService,
+ private AttachmentsService: AttachmentsService,
+
+ private CameraService: CameraService,
+ private processesService: ProcessesService,
+ private storage: Storage,
+ private fileToBase64Service: FileToBase64Service,
) {
this.loggedUser = authService.ValidatedUserChat['data'];
this.roomId = this.navParams.get('roomId');
@@ -121,11 +134,10 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
}
ngOnInit() {
- //this.load();
- this.setStatus('online');
this.wsChatMethodsService.getUserOfRoom(this.roomId).then((value) => {
console.log('MEMBER', value)
})
+
//this.loadFiles();
VoiceRecorder.requestAudioRecordingPermission();
this.getChatMembers();
@@ -256,15 +268,6 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
this.selectedMsgId = "";
}
- setStatus(status: string) {
- let body = {
- message: '',
- status: status,
- }
- this.chatService.setUserStatus(body).subscribe(res => {
- console.log(res);
- })
- }
notImplemented() {
this.alertService.presentAlert('Funcionalidade em desenvolvimento');
@@ -275,7 +278,6 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
}
load() {
- this.serverLongPull();
this.getChatMembers();
}
@@ -350,7 +352,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
}
sendMessage() {
- this.wsChatMethodsService.getDmRoom(this.roomId).send()
+ this.wsChatMethodsService.getDmRoom(this.roomId).send({})
}
@@ -518,6 +520,183 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
}
}
+
+ 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()
+ });
+
+ }
+
+ });
+
+ }
+
+ 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;
+ const roomId = this.roomId
+
+ 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()
+ });
+ }
+
+ });
+ }
+
async openChatOptions(ev?: any) {
const roomId = this.roomId
console.log('MOBILE CHAT OPTION',this.members);
@@ -534,66 +713,29 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
translucent: true
});
await popover.present();
- popover.onDidDismiss().then((res) => {
+ popover.onDidDismiss().then( async (res) => {
console.log(res['data']);
if (res['data'] == 'meeting') {
this.bookMeeting();
}
else if (res['data'] == 'take-picture') {
- this.fileService.addCameraPictureToChat(roomId);
- //this.loadPicture();
+ this.takePicture()
}
else if (res['data'] == 'add-picture') {
- //this.fileService.addPictureToChat(roomId);
- this.fileService.loadPicture(this.roomId);
+ 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.fileService.downloadFile(element.file.guid).subscribe(async (event) => {
- var name = element.file.guid;
- if (event.type === HttpEventType.DownloadProgress) {
-
- } else if (event.type === HttpEventType.Response) {
- var base64 = btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), '')
- );
-
- console.log('TRY ARRAY BUFFER NAME', name);
- console.log('TRY ARRAY BUFFER', base64);
-
- await Filesystem.writeFile({
- path: `${IMAGE_DIR}/${name}`,
- data: base64,
- directory: Directory.Data
- }).then((foo) => {
-
- console.log('LSKE FS FILE SAVED', foo)
-
- }).catch((error) => {
- console.log('error LAKE FS FILE', error)
- });
-
-
-
- const readFile = await Filesystem.readFile({
- path: `${IMAGE_DIR}/${name}`,
- directory: Directory.Data,
- });
-
-
- });*/
getRoomMessageDB(roomId) {
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
@@ -669,108 +811,12 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
}
- async serverLongPull() {
-
- const roomId = this.roomId
-
- /* this.chatService.getRoomMessages(roomId).subscribe(res=>{
- console.log(res);
-
- }) */
-
-
- this.chatService.getRoomMessages(roomId).subscribe(async res => {
- console.log("Chat message", res)
-
- this.transformDataMSG(res['messages'])
- this.getRoomMessageDB(this.roomId);
-
-
- if (res == 502) {
- // Connection timeout
- // happens when the synchro was pending for too long
- // let's reconnect
- await this.serverLongPull();
- }
- else if (res != 200) {
- // Show Error
- //showMessage(response.statusText);
- //this.loadMessages()
- if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
-
- }
-
-
- //console.log(this.messages);
- // Reconnect in one second
- if (this.route.url != "/home/chat") {
- console.log("Timer message stop")
- } else {
- //Check if modal is opened
- if (document.querySelector('.isMessagesChatOpened')) {
- await new Promise(resolve => setTimeout(resolve, 5000));
- await this.serverLongPull();
- //console.log('Timer message running')
- }
- }
-
- } else {
- // Got message
- //let message = await response.text();
- //this.loadMessages()
- await this.serverLongPull();
- }
- });
- }
-
-
- 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;
diff --git a/src/app/services/attachments.service.ts b/src/app/services/attachments.service.ts
index fa0be2ba1..1c20db0dd 100644
--- a/src/app/services/attachments.service.ts
+++ b/src/app/services/attachments.service.ts
@@ -20,6 +20,47 @@ export class AttachmentsService {
this.headers = this.headers.set('Authorization', this.loggeduser.BasicAuthKey);
}
+ uploadFile(formData:any) {
+
+ console.log('UPLOAD file', formData)
+
+ //const geturl = environment.apiURL + 'Tasks/DelegateTask';
+ const geturl = environment.apiURL + 'ObjectServer/UploadFiles';
+
+ let options = {
+ headers: this.headers
+ };
+
+ return this.http.post(`${geturl}`, formData, options);
+ }
+
+ getFile(guid:any) {
+ const geturl = environment.apiURL + 'lakefs/StreamFile';
+ let params = new HttpParams();
+
+ params = params.set("path", guid);
+
+ this.headers = this.headers.set('responseType', 'blob');
+ this.headers = this.headers.set('Content-Type', 'application/octet-stream');
+
+ let options = {
+ headers: this.headers,
+ params: params
+ };
+ return this.http.get(`${geturl}`, options);
+ }
+
+ downloadFile(guid:any) {
+
+ let downloadUrl = environment.apiURL +'objectserver/streamfiles?path='+guid;
+ var name = new Date().getTime();
+ return this.http.get(downloadUrl, {
+ responseType: "arraybuffer",
+ reportProgress: true, observe: 'events'
+ })
+
+ }
+
getAttachmentsBySerial(serialNumber: string): Observable{
let geturl = environment.apiURL + 'attachments/GetAttachments';
let params = new HttpParams();
diff --git a/src/app/services/camera.service.spec.ts b/src/app/services/camera.service.spec.ts
new file mode 100644
index 000000000..73b57d3a5
--- /dev/null
+++ b/src/app/services/camera.service.spec.ts
@@ -0,0 +1,16 @@
+import { TestBed } from '@angular/core/testing';
+
+import { CameraService } from './camera.service';
+
+describe('CameraService', () => {
+ let service: CameraService;
+
+ beforeEach(() => {
+ TestBed.configureTestingModule({});
+ service = TestBed.inject(CameraService);
+ });
+
+ it('should be created', () => {
+ expect(service).toBeTruthy();
+ });
+});
diff --git a/src/app/services/camera.service.ts b/src/app/services/camera.service.ts
new file mode 100644
index 000000000..b99fd6956
--- /dev/null
+++ b/src/app/services/camera.service.ts
@@ -0,0 +1,36 @@
+import { Injectable } from '@angular/core';
+import { Camera, CameraResultType, CameraSource, Photo} from '@capacitor/camera';
+
+@Injectable({
+ providedIn: 'root'
+})
+export class CameraService {
+
+ constructor() { }
+
+
+ async takePicture(){
+
+ return new Promise(async (resolve, reject)=>{
+
+ console.log('add camera to picture')
+
+ const image = await Camera.getPhoto({
+ quality: 50,
+ allowEditing: false,
+ resultType: CameraResultType.Uri,
+ source: CameraSource.Camera // Camera, Photos or Prompt!
+ });
+
+ if (image) {
+ resolve(image)
+
+ } else {
+ reject('Error saving image')
+ }
+
+ //this.capturedImage = this.capturedImage;
+ })
+
+ }
+}
diff --git a/src/app/services/chat/message.service.ts b/src/app/services/chat/message.service.ts
index 43c8f74be..6eb0f3015 100644
--- a/src/app/services/chat/message.service.ts
+++ b/src/app/services/chat/message.service.ts
@@ -2,6 +2,8 @@ import { Injectable } from '@angular/core';
import { Message } from 'src/app/models/chatMethod';
import { chatHistory, ChatMessage, File } from 'src/app/models/chatMethod'
import { Storage } from '@ionic/storage';
+import { SessionStore } from 'src/app/store/session.service';
+import { capitalizeTxt } from 'src/plugin/text'
@Injectable({
providedIn: 'root'
@@ -17,54 +19,77 @@ export class MessageService {
u = {}
t = ''
_id =''
- _updatedAt = ''
+ _updatedAt
file
attachments
- offline = false
+ offline = true
+ displayType = ''
constructor(private storage: Storage) {
- }
+ }
setData({customFields, channels, mentions, msg ,rid ,ts, u, t, _id, _updatedAt, file, attachments}:Message) {
- this.customFields = customFields
- this.channels = channels
- this.mentions = mentions
- this.msg = msg
+ this.customFields = customFields
+ this.channels = channels || []
+ this.mentions = mentions || []
+ this.msg = msg || ""
this.rid = rid
this.ts = ts
- this.u = u
+ this.u = u || { name: this.usernameToDisplayName(SessionStore.user.RochetChatUser), username: SessionStore.user.RochetChatUser, _id: ""}
this.t = t
this._id = _id
- this._updatedAt = _updatedAt
+ this._updatedAt = _updatedAt || new Date().getTime()
this.file = file
this.attachments = attachments
-
- if (this.file) {
- if (this.file.guid) {
- this.storage.get(this.file.guid).then((image) => {
- // console.log('IMAGE FROM STORAGE', image)
- this.file.image_url = image
- });
- }
- }
-
-
- if(this.rid == 'offline') {
+ if(!this.ts) {
this.offline = true
} else {
this.offline = false
}
+
+ if (this.file) {
+ this.getFileFromDb()
+ if(this.file.type) {
+ if(this.file.type != 'application/webtrix' && typeof(this.file.type) == 'string') {
+ this.displayType = this.file.type.replace('application/','').toUpperCase()
+ }
+ }
+
+ }
+
+
}
delete() {}
showDateDuration() {}
-
-
+
resend() {
}
+
+ private usernameToDisplayName(username) {
+
+ const firstName = capitalizeTxt(username.split('.')[0])
+ const lastName = capitalizeTxt(username.split('.')[1])
+ return firstName + ' ' + lastName
+ }
+
+
+ getFileFromDb() {
+ if (this.file) {
+ if (this.file.guid) {
+ this.storage.get(this.file.guid).then((image) => {
+ if(image != null) {
+ this.file.image_url = image
+ }
+
+ });
+ }
+ }
+ }
+
}
diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts
index a3c58eaed..325172ac2 100644
--- a/src/app/services/chat/room.service.ts
+++ b/src/app/services/chat/room.service.ts
@@ -14,6 +14,7 @@ import { capitalizeTxt } from 'src/plugin/text'
import { SortService } from '../functions/sort.service';
import { chatUser } from 'src/app/models/chatMethod';
import { environment } from 'src/environments/environment';
+import { ChatService } from 'src/app/services/chat.service';
@Injectable({
providedIn: 'root'
@@ -53,6 +54,7 @@ export class RoomService {
}
sortRoomList = () => {}
+ uploadAttachment = (formData) => {}
constructor(
public WsChatService: WsChatService,
@@ -62,6 +64,7 @@ export class RoomService {
private sqlservice: SqliteService,
private NativeNotificationService: NativeNotificationService,
private sortService: SortService,
+ private chatService: ChatService,
) {
this.NativeNotificationService.askForPermission()
}
@@ -88,9 +91,10 @@ export class RoomService {
this.id,
"stream-room-messages",
(ChatMessage) => {
+ ChatMessage = ChatMessage.fields.args[0]
if(environment.chatOffline == false || this.isSenderIsNotMe(ChatMessage)) {
- ChatMessage = ChatMessage.fields.args[0]
+
ChatMessage = this.fix_updatedAt(ChatMessage)
console.log('recivemessage', ChatMessage)
@@ -201,61 +205,67 @@ export class RoomService {
/**
* @description sen text message
*/
- send() {
+ send({file = null, attachments = null}) {
- if(environment.chatOffline == false) {
- this.WsChatService.send(this.id, this.message)
- this.message= ''
+
+ let offlineChatMessage = {
+ rid: this.id,
+ msg: this.message,
+ attachments,
+ file,
+ }
+
+ this.addMessageDB(offlineChatMessage)
+ const message: MessageService = this.prepareMessage(offlineChatMessage)
+
+ setTimeout(() => {
+ this.scrollDown()
+ }, 150)
+
+ this.lastMessage = message
+
+
+ if(file == null && attachments == null) {
+ console.log('simple send')
+ this.WsChatService.send({roomId:this.id, msg:message.msg}).then((data: any) => {
+ let ChatMessage = data.result
+ this.redefinedMessage(message, ChatMessage)
+ })
} else {
-
- const offlineChatMessage = {
- channels: [],
- mentions: [],
- rid: 'offline',
- msg: this.message,
- ts: { $date: new Date().getTime() },
- u: {
- name: this.usernameToDisplayName(SessionStore.user.RochetChatUser),
- username: SessionStore.user.RochetChatUser,
- _id: ""
- },
- _updatedAt: new Date().getTime()
+ console.log('complex send')
+ return {
+ message: message,
+ updateMessage: (update)=> {
+ offlineChatMessage = Object.assign(offlineChatMessage, update)
+
+ this.WsChatService.send({roomId:this.id, msg:message.msg,attachments:offlineChatMessage.attachments, file:offlineChatMessage.file}).then((data: any) => {
+ console.log('send sucees', data.result)
+ let ChatMessage = data.result
+ this.redefinedMessage(message, ChatMessage)
+ })
+
+ }
}
-
- this.addMessageDB(offlineChatMessage)
- const message: MessageService = this.prepareMessage(offlineChatMessage)
-
- setTimeout(() => {
- this.scrollDown()
- }, 150)
-
- this.lastMessage = message
-
- this.redefinedMessage(message)
-
- this.calDateDuration(message._updatedAt)
- this.sortRoomList()
-
-
- this.message= ''
}
+
+ this.calDateDuration(message._updatedAt)
+ this.sortRoomList()
+
+ this.message= ''
}
- redefinedMessage = (message: MessageService) => {
- this.WsChatService.send(this.id, message.msg).then((data: any) => {
- let ChatMessage = data.result
+ redefinedMessage (message: MessageService, ChatMessage) {
- ChatMessage = this.fix_updatedAt(ChatMessage)
+ ChatMessage = this.fix_updatedAt(ChatMessage)
- message.setData(ChatMessage)
+ message.setData(ChatMessage)
- if( new Date(this.lastMessage._updatedAt).getTime() < new Date(message._updatedAt).getTime()) {
- this.lastMessage = message
- this.calDateDuration(message._updatedAt)
- }
- this.sortRoomList()
- })
+ if( new Date(this.lastMessage._updatedAt).getTime() < new Date(message._updatedAt).getTime()) {
+ this.lastMessage = message
+ this.calDateDuration(message._updatedAt)
+ }
+ this.sortRoomList()
}
@@ -330,11 +340,17 @@ export class RoomService {
let localMessages = []
- messages.forEach((message = []) => {
- const wewMessage = this.prepareMessage(message)
+ if(messages==null) messages = []
- if(wewMessage.rid == 'offline') {
- this.redefinedMessage(wewMessage)
+ messages.reverse().forEach((ChatMessage, index) => {
+ const wewMessage = this.prepareMessage(ChatMessage)
+
+ if(wewMessage.offline == true) {
+ this.WsChatService.send({roomId:this.id, msg:wewMessage.msg, attachments:wewMessage.attachments, file: wewMessage.file}).then((data: any) => {
+ let _ChatMessage = data.result
+ this.redefinedMessage(wewMessage, _ChatMessage)
+ this.storage.set('chatmsg' + this.id, messages)
+ })
}
localMessages.push(wewMessage)
@@ -381,7 +397,7 @@ export class RoomService {
- prepareMessage(message) {
+ prepareMessage(message): MessageService {
message = this.fix_updatedAt(message)
const wewMessage = new MessageService(this.storage)
wewMessage.setData(message)
@@ -412,9 +428,11 @@ export class RoomService {
if (message.result) {
//console.log('FIX UPDATE ', message.result)
message.result._updatedAt = message.result._updatedAt['$date']
- } else if(message._updatedAt.hasOwnProperty('$date')) {
- // console.log('FIX UPDATE 11', message)
- message._updatedAt = message._updatedAt['$date']
+ } else if(message._updatedAt) {
+ if(message._updatedAt.hasOwnProperty('$date')) {
+ // console.log('FIX UPDATE 11', message)
+ message._updatedAt = message._updatedAt['$date']
+ }
}
return message
}
diff --git a/src/app/services/chat/ws-chat-methods.service.ts b/src/app/services/chat/ws-chat-methods.service.ts
index b8879a467..2926c42c3 100644
--- a/src/app/services/chat/ws-chat-methods.service.ts
+++ b/src/app/services/chat/ws-chat-methods.service.ts
@@ -203,7 +203,7 @@ export class WsChatMethodsService {
prepareRoom(roomData) {
let room:RoomService;
- room = new RoomService(this.WsChatService, new MessageService(this.storage), this.storage, this.platform, this.sqlservice, this.NativeNotificationService, this.sortService)
+ room = new RoomService(this.WsChatService, new MessageService(this.storage), this.storage, this.platform, this.sqlservice, this.NativeNotificationService, this.sortService, this.ChatService)
room.setData({
customFields: roomData.customFields,
diff --git a/src/app/services/chat/ws-chat.service.ts b/src/app/services/chat/ws-chat.service.ts
index 4b94ad019..593b79276 100644
--- a/src/app/services/chat/ws-chat.service.ts
+++ b/src/app/services/chat/ws-chat.service.ts
@@ -162,7 +162,7 @@ export class WsChatService {
}
// send message to room
- send(roomId, msg) {
+ send({roomId, msg, attachments = null, file = null}) {
const requestId = uuidv4()
@@ -171,9 +171,10 @@ export class WsChatService {
method: "sendMessage",
id: requestId,
params: [{
- _id: uuidv4(),
rid: roomId,
- msg: msg
+ msg: msg,
+ attachments,
+ file
}]
}
@@ -181,7 +182,7 @@ export class WsChatService {
return new Promise((resolve, reject) => {
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
- if(message.id == requestId || deepFind(message,'result.id') == requestId) { // same request send
+ if(message.id == requestId ) { // same request send
resolve(message)
return true
}
@@ -206,7 +207,7 @@ export class WsChatService {
return new Promise((resolve, reject) => {
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
- if(message.id == requestId || deepFind(message,'result.id') == requestId) { // same request send
+ if(message.id == requestId ) { // same request send
resolve(message)
return true
}
@@ -232,7 +233,7 @@ export class WsChatService {
return new Promise((resolve, reject) => {
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
- if(message.id == requestId || deepFind(message,'result.id') == requestId) { // same request send
+ if(message.id == requestId ) { // same request send
resolve(message)
return true
}
@@ -255,7 +256,7 @@ export class WsChatService {
return new Promise((resolve, reject) => {
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
- if(message.id == requestId || deepFind(message,'result.id') == requestId) { // same request send
+ if(message.id == requestId ) { // same request send
resolve(message)
return true
}
@@ -310,7 +311,7 @@ export class WsChatService {
return new Promise((resolve, reject) => {
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
- if(message.id == requestId || deepFind(message,'result.id') == requestId) { // same request send
+ if(message.id == requestId ) { // same request send
resolve(message)
return true
}
@@ -337,7 +338,7 @@ export class WsChatService {
return new Promise((resolve, reject) => {
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
- if(message.id == requestId || deepFind(message,'result.id') == requestId) { // same request send
+ if(message.id == requestId ) { // same request send
resolve(message)
return true
}
@@ -565,7 +566,7 @@ updateRoomEventss(roomId, collection:string, funx: Function, ) {
return new Promise((resolve, reject) => {
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
- if(message.id == requestId || deepFind(message,'result.id') == requestId) { // same request send
+ if(message.id == requestId ) { // same request send
resolve(message)
return true
}
@@ -592,7 +593,7 @@ updateRoomEventss(roomId, collection:string, funx: Function, ) {
return new Promise((resolve, reject) => {
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
- if(message.id == requestId || deepFind(message,'result.id') == requestId) { // same request send
+ if(message.id == requestId ) { // same request send
resolve(message)
return true
}
diff --git a/src/app/services/functions/file.service.ts b/src/app/services/functions/file.service.ts
index f7c684859..4ab379fa8 100644
--- a/src/app/services/functions/file.service.ts
+++ b/src/app/services/functions/file.service.ts
@@ -1,21 +1,13 @@
import { Injectable } from '@angular/core';
import { FileLoaderService } from '../file/file-loader.service';
-import { FileToBase64Service } from '../file/file-to-base64.service';
import { InAppBrowser } from '@ionic-native/in-app-browser/ngx';
-
-import { ChatService } from '../chat.service';
-import { ModalController, Platform,LoadingController } from '@ionic/angular';
-import { SearchPage } from 'src/app/pages/search/search.page';
-import { SearchList } from 'src/app/models/search-document';
-import { ProcessesService } from '../processes.service';
-import { ToastService } from '../toast.service';
-import { Camera, CameraResultType, CameraSource, Photo} from '@capacitor/camera';
+import { LoadingController, Platform } from '@ionic/angular';
+import {Photo} from '@capacitor/camera';
+import { FileType } from 'src/app/models/fileType';
import { Filesystem, Directory } from '@capacitor/filesystem';
-import { environment } from 'src/environments/environment';
-import { HttpClient, HttpEventType, HttpHeaders, HttpParams } from '@angular/common/http';
-import { Storage } from '@ionic/storage';
-const IMAGE_DIR = 'stored-images';
+import { FileToBase64Service } from 'src/app/services/file/file-to-base64.service';
+const IMAGE_DIR = 'stored-images';
interface LocalFile {
name: string;
@@ -31,112 +23,24 @@ export class FileService {
images: LocalFile[] = [];
capturedImage:any;
capturedImageTitle:any;
- documents:SearchList[] = [];
showLoader: boolean;
files: Set;
photos: any[] = [];
idroom: any;
- headers: HttpHeaders;
downloadProgess = 0;
downloadFilename: any;
convertBlobToBase64Worker;
constructor(
private fileLoaderService: FileLoaderService,
- private fileToBase64Service: FileToBase64Service,
private iab: InAppBrowser,
- private chatService: ChatService,
- private modalController: ModalController,
- private processesService: ProcessesService,
- private toastService: ToastService,
- private platform: Platform,
private loadingCtrl: LoadingController,
- private http: HttpClient,
- private storage: Storage
- ) {
- this.headers = new HttpHeaders();
- }
+ private platform: Platform,
+ private fileToBase64Service: FileToBase64Service
+ ) {}
- uploadFile(formData:any){
-
- console.log('UPLOAD file', formData)
-
- //const geturl = environment.apiURL + 'Tasks/DelegateTask';
- const geturl = environment.apiURL + 'ObjectServer/UploadFiles';
-
- let options = {
- headers: this.headers
- };
-
- return this.http.post(`${geturl}`, formData, options);
- }
-
- getFile(guid:any){
- const geturl = environment.apiURL + 'lakefs/StreamFile';
- let params = new HttpParams();
-
- params = params.set("path", guid);
-
- this.headers = this.headers.set('responseType', 'blob');
- this.headers = this.headers.set('Content-Type', 'application/octet-stream');
-
- let options = {
- headers: this.headers,
- params: params
- };
- return this.http.get(`${geturl}`, options);
- }
-
- downloadFile(guid:any) {
-
- let downloadUrl = environment.apiURL +'objectserver/streamfiles?path='+guid;
- var name = new Date().getTime();
- return this.http.get(downloadUrl, {
- responseType: "arraybuffer",
- reportProgress: true, observe: 'events'
- })
-
- }
-
- _arrayBufferToBase64( buffer ) {
- var binary = '';
- var bytes = new Uint8Array( buffer );
- var len = bytes.byteLength;
- for (var i = 0; i < len; i++) {
- binary += String.fromCharCode( bytes[ i ] );
- }
- return window.btoa( binary );
-}
-
-
- async takePicture() {
- const capturedImage = await Camera.getPhoto({
- quality: 90,
- // allowEditing: true,
- resultType: CameraResultType.Uri,
- source: CameraSource.Camera
-
- });
- const response = await fetch(capturedImage.webPath!);
- const blob = await response.blob();
-
- this.photos.unshift({
- filepath: "soon...",
- webviewPath: capturedImage.webPath
- });
-
- this.capturedImage = await this.convertBlobToBase64(blob);
- this.capturedImageTitle = new Date().getTime() + '.jpeg';
-
- let data = {
- image:this.capturedImage,
- name: this.capturedImageTitle
- }
-
- return data;
- }
convertBlobToBase64 = (blob: Blob) => new Promise((resolve, reject) => {
const reader = new FileReader;
@@ -147,68 +51,9 @@ export class FileService {
reader.readAsDataURL(blob);
});
- async loadPicture(roomid) {
- const capturedImage = await Camera.getPhoto({
- quality: 90,
- // allowEditing: true,
- resultType: CameraResultType.Uri,
- source: CameraSource.Photos
- });
-
- const response = await fetch(capturedImage.webPath!);
- const blob = await response.blob();
- const formData = new FormData();
- formData.append("blobFile", blob);
- console.log('ALL IMAGE', formData)
- let guid: any = await this.uploadFile(formData).toPromise()
- console.log(guid.path);
- this.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')
- let body = {
- "message":
- {
- "rid": roomid,
- "msg": "",
- "attachments": [{
- "title": this.capturedImageTitle,
- "title_link_download": false,
- "image_url": fileImage,
- }],
- "file":{
- "type": "application/img",
- "guid": guid.path,
- "image_url": fileImage
- }
- }
- }
- console.log('BODY TAKE PICTURE CHAT', body)
- const loader = this.toastService.loading();
- this.chatService.sendMessage(body).subscribe(res=> {
- console.log(res);
- loader.remove();
- },(error) => {
- loader.remove();
- this.toastService.badRequest("Não foi possível adicionar a fotografia!");
- });
-
- });
- }
-
- });
- }
-
- //new method1
- async saveImage(photo: Photo, roomid: any) {
+ async saveImage(photo: Photo) {
const base64Data = await this.readAsBase64(photo);
const fileName = new Date().getTime() + '.jpeg';
@@ -217,10 +62,43 @@ export class FileService {
data: base64Data,
directory: Directory.Data
});
-
- this.loadFiles(roomid);
+
}
+ //new method 3
+ async loadFiles() {
+
+ const loading = await this.loadingCtrl.create({
+ message: 'Loading data...',
+ });
+ await loading.present();
+
+ return new Promise((resolve, reject)=>{
+ Filesystem.readdir({
+ path: IMAGE_DIR,
+ directory: Directory.Data,
+ }).then(result => {
+ console.log('ALL RESULTS', result.files[0])
+ let lastphoto = result.files[result.files.length - 1]
+ resolve(lastphoto)
+ },
+ async (err) => {
+ console.log('ERROR FILE DOSENT EXIST', err)
+ reject('ERROR FILE DOSENT EXIST')
+ // Folder does not yet exists!
+ await Filesystem.mkdir({
+ path: IMAGE_DIR,
+ directory: Directory.Data,
+ recursive: true
+ });
+ }
+ ).then(_ => {
+ loading.dismiss();
+ });
+ })
+ }
+
+
//new method 2
private async readAsBase64(photo: Photo) {
if (this.platform.is('hybrid')) {
@@ -239,343 +117,61 @@ export class FileService {
}
}
- //new method 3
- async loadFiles(roomid) {
- this.images = [];
- const loading = await this.loadingCtrl.create({
- message: 'Loading data...',
- });
- await loading.present();
-
- Filesystem.readdir({
- path: IMAGE_DIR,
+ async readFile(filePath) {
+ return await Filesystem.readFile({
+ path: filePath,
directory: Directory.Data,
- }).then(result => {
- console.log('ALL RESULTS', result.files[0])
- let lastphoto = result.files[result.files.length - 1]
- this.loadFileData(lastphoto,roomid);
- },
- async (err) => {
- console.log('ERROR FILE DOSENT EXIST', err)
- // Folder does not yet exists!
- await Filesystem.mkdir({
- path: IMAGE_DIR,
- directory: Directory.Data,
- recursive: true
- });
- }
- ).then(_ => {
- loading.dismiss();
});
}
//new method 4
- async loadFileData(fileName: string, roomid: any) {
+ async loadFileData(fileName: string) {
console.log('ALL PHOTOT FILE', fileName)
// for (let f of fileNames) {
const filePath = `${IMAGE_DIR}/${fileName}`;
- const readFile = await Filesystem.readFile({
- path: filePath,
- directory: Directory.Data,
- });
+ const readFile = await this.readFile(filePath)
- this.images.push({
+ const image ={
name: fileName,
path: filePath,
data: `data:image/jpeg;base64,${readFile.data}`,
- });
+ };
- console.log('ALL IMAGE', this.images)
+ console.log('ALL IMAGE', image)
- this.capturedImage = this.images[0].data
+ const capturedImage = image.data
- this.capturedImageTitle = new Date().getTime() + '.jpeg';
- const base64 = await fetch(this.capturedImage);
- const blob = await base64.blob();
- const formData = new FormData();
- formData.append("blobFile", blob);
- console.log('ALL IMAGE', formData)
- let guid: any = await this.uploadFile(formData).toPromise()
- console.log(guid.path);
+ const capturedImageTitle = new Date().getTime() + '.jpeg';
- this.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')
- let body = {
- "message":
- {
- "rid": roomid,
- "msg": "",
- "attachments": [{
- "title": this.capturedImageTitle,
- "title_link_download": false,
- "image_url": fileImage,
- }],
- "file":{
- "type": "application/img",
- "guid": guid.path,
- "image_url": fileImage
- }
- }
- }
- console.log('BODY TAKE PICTURE CHAT', body)
- const loader = this.toastService.loading();
- this.chatService.sendMessage(body).subscribe(res=> {
- console.log(res);
- loader.remove();
- },(error) => {
- loader.remove();
- this.toastService.badRequest("Não foi possível adicionar a fotografia!");
- });
-
- });
- }
-
- });
- }
-
-
-
- async addCameraPictureToChat(roomId){
-
- console.log('add camera to picture')
-
- const image = await Camera.getPhoto({
- quality: 50,
- allowEditing: false,
- resultType: CameraResultType.Uri,
- source: CameraSource.Camera // Camera, Photos or Prompt!
- });
-
- if (image) {
- await this.saveImage(image,roomId)
- } else {
- console.log('Error saving image')
- }
-
- //this.capturedImage = this.capturedImage;
-
+ return { capturedImage, capturedImageTitle}
}
- async addPictureToChatMobile(roomId) {
-
- const capturedImage = await Camera.getPhoto({
- quality: 50,
- // allowEditing: true,
- resultType: CameraResultType.Uri,
- source: CameraSource.Photos
-
- });
-
- if (capturedImage) {
- await this.saveImage(capturedImage,roomId)
- }
- /* const response = await fetch(capturedImage.webPath!);
- const blob = await response.blob();
-
- this.photos.unshift({
- filepath: "soon...",
- webviewPath: capturedImage.webPath
- });
-
- this.capturedImage = await this.convertBlobToBase64(blob);
- this.capturedImageTitle = new Date().getTime() + '.jpeg';
-
- //const loader = this.toastService.loading();
-
- let body = {
- "message":
- {
- "rid": roomId,
- "msg": "",
- "attachments": [{
- //"title": this.capturedImageTitle ,
- //"text": "description",
- "title_link_download": false,
- "image_url": this.capturedImage,
- }]
- }
- }
- this.chatService.sendMessage(body).subscribe(res=> {
- //loader.remove();
- //console.log(res);
- },(error) => {
- //loader.remove();
- });
- */ }
- addPictureToChat(roomId) {
-
- console.log('add picture to chat')
-
- const input = this.fileLoaderService.createInput({
- accept: ['image/apng', 'image/jpeg', 'image/png']
- })
-
- input.onchange = async () => {
-
- //alert('Onchange AQUI')
-
- const file = this.fileLoaderService.getFirstFile(input)
-
- console.log('first file',file);
-
-
- const formData = new FormData();
- formData.append("blobFile", file);
- let guid: any = await this.uploadFile(formData).toPromise()
- console.log('ADD IMAGE FORM DATA', formData)
- console.log('add picture to chat', guid.path);
- this.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')
-
- let body = {
- "message":
- {
- "rid": roomId,
- "msg": "",
- "attachments": [{
- //"title": this.capturedImageTitle ,
- //"text": "description",
- "title_link_download": false,
- //"image_url": this.capturedImage,
- }],
- "file": {
- "type": "application/img",
- "guid": guid.path,
- "image_url": fileImage
- }
- }
- }
-
- console.log('SELECT PICTURE GALLERY', body)
- console.log(this.capturedImage)
-
- this.chatService.sendMessage(body).subscribe(res => {
-
- console.log('Msg after send image', res);
- }, (error) => {
- console.log('Msg after send image error', error);
- });
- });
- }
-
- });
-
- /* const imageData = await this.fileToBase64Service.convert(file)
- this.capturedImage = imageData; */
-
- //console.log(this.capturedImage)
- };
-}
-
- addDocumentToChat(roomId:string) {
+ getFileFromDevice(types: typeof FileType[]) {
const input = this.fileLoaderService.createInput({
- accept: ['.doc', '.docx', '.pdf']
+ accept: types
})
- input.onchange = async () => {
- const loader = this.toastService.loading();
- const file = this.fileLoaderService.getFirstFile(input)
+ return new Promise((resolve, reject)=>{
+ input.onchange = async () => {
+ const file = this.fileLoaderService.getFirstFile(input)
+
+ resolve(file);
+ };
+ })
- console.log(file);
- const formData = new FormData();
- formData.append('file', file, file.name);
-
- this.chatService.uploadFile(formData, roomId).subscribe(res=> {
- console.log(res);
- loader.remove();
- },(error) => {
- loader.remove();
- });
- //console.log(this.capturedImage)
- };
}
- async addDocGestaoDocumentalToChat(roomId:string){
- 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();
-
- 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);
-
- let body = {
- "message":
- {
- "rid": roomId,
- "msg": "",
- "alias": "documento",
- "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"
- }],
- "file":{
- "name": res.data.selected.Assunto,
- "type": "application/webtrix",
- "ApplicationId": res.data.selected.ApplicationType,
- "DocId": res.data.selected.Id,
- "Assunto": res.data.selected.Assunto,
- }
- }
- }
- this.chatService.sendMessage(body).subscribe(res=> {
- loader.remove();
- console.log(res);
- },(error) => {
- loader.remove();
- });
- loader.remove();
- }
- });
- }
viewDocumentByUrl(url) {
const browser = this.iab.create(url,"_parent");
browser.show();
}
+
}
diff --git a/src/app/shared/chat/group-messages/group-messages.page.html b/src/app/shared/chat/group-messages/group-messages.page.html
index d1989fed9..99162985b 100644
--- a/src/app/shared/chat/group-messages/group-messages.page.html
+++ b/src/app/shared/chat/group-messages/group-messages.page.html
@@ -97,7 +97,7 @@
{{file.description}}
•
- {{msg.file.type.replace('application/','').toUpperCase()}}
+ {{msg.displayType}}
diff --git a/src/app/shared/chat/group-messages/group-messages.page.ts b/src/app/shared/chat/group-messages/group-messages.page.ts
index 5747db9e1..eb6fdda08 100644
--- a/src/app/shared/chat/group-messages/group-messages.page.ts
+++ b/src/app/shared/chat/group-messages/group-messages.page.ts
@@ -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;
diff --git a/src/app/shared/chat/messages/messages.page.html b/src/app/shared/chat/messages/messages.page.html
index b132f662f..16c0804e9 100644
--- a/src/app/shared/chat/messages/messages.page.html
+++ b/src/app/shared/chat/messages/messages.page.html
@@ -97,7 +97,7 @@
{{file.description}}
•
{{msg.file.type.replace('application/','').toUpperCase()}}
+ *ngIf="msg.file.type != 'application/webtrix'">{{msg.displayType}}
diff --git a/src/app/shared/chat/messages/messages.page.ts b/src/app/shared/chat/messages/messages.page.ts
index f61e12a17..55316e203 100644
--- a/src/app/shared/chat/messages/messages.page.ts
+++ b/src/app/shared/chat/messages/messages.page.ts
@@ -13,10 +13,9 @@ import { ChatMessageStore } from 'src/app/store/chat/chat-message.service';
import { ChatUserStorage } from 'src/app/store/chat/chat-user.service';
import { TimeService } from 'src/app/services/functions/time.service';
import { FileService } from 'src/app/services/functions/file.service';
-import { HttpClient, HttpEventType, HttpHeaders } from '@angular/common/http';
+import { HttpClient, HttpEventType } from '@angular/common/http';
import { ViewDocumentPage } from 'src/app/modals/view-document/view-document.page';
import { ThemeService } from 'src/app/services/theme.service'
-import { PreviewCameraPage } from 'src/app/modals/preview-camera/preview-camera.page';
import { ViewMediaPage } from 'src/app/modals/view-media/view-media.page';
import { SqliteService } from 'src/app/services/sqlite.service';
import { StorageService } from 'src/app/services/storage.service';
@@ -26,7 +25,13 @@ 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 { 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({
@@ -92,7 +97,12 @@ 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 CameraService: CameraService,
+ private processesService: ProcessesService,
+ private fileToBase64Service: FileToBase64Service,
) {
this.loggedUser = authService.ValidatedUserChat['data'];
@@ -104,6 +114,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)
@@ -113,7 +128,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
ngOnInit() {
this.scrollToBottom();
- this.setStatus('online');
+
this.getChatMembers();
}
@@ -134,15 +149,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');
@@ -150,7 +156,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
load = () => {
this.checktimeOut = true;
- this.serverLongPull();
this.getChatMembers();
}
@@ -205,7 +210,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
ngOnDestroy() {
this.checktimeOut = false;
- this.setStatus('away');
window.removeEventListener('scroll', this.scrollChangeCallback, true);
}
@@ -242,7 +246,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) {
@@ -251,7 +255,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);
@@ -267,7 +271,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);
}
}
@@ -439,22 +443,183 @@ 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.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() {
- 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;
+ const roomId = this.roomId
+
+ 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,
@@ -464,7 +629,13 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
}
+ chatsend() {
+
+ }
+
async _openChatOptions() {
+ const roomId = this.roomId;
+
const enterAnimation = (baseEl: any) => {
const backdropAnimation = this.animationController.create()
@@ -500,8 +671,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 = {
@@ -511,111 +684,38 @@ 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,
- 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;