Files
doneit-web/src/app/pages/chat/messages/messages.page.ts
T

1081 lines
31 KiB
TypeScript
Raw Normal View History

2021-11-17 15:34:15 +01:00
import { AfterViewChecked, AfterViewInit, ChangeDetectorRef, Component, ElementRef, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router'
2022-04-02 09:40:09 +01:00
import { GestureController, Gesture, ModalController, NavParams, PopoverController, Platform, AlertController } from '@ionic/angular';
2021-09-01 17:14:57 +01:00
import { map } from 'rxjs/operators';
import { ViewDocumentPage } from 'src/app/modals/view-document/view-document.page';
2021-09-21 14:05:59 +01:00
import { EventPerson } from 'src/app/models/eventperson.model';
2021-10-09 16:41:18 +01:00
import { ExpedientTaskModalPageNavParamsTask } from 'src/app/models/ExpedientTaskModalPage';
2021-03-12 11:56:54 +01:00
import { ContactsPage } from 'src/app/pages/chat/messages/contacts/contacts.page';
2021-04-13 14:14:55 +01:00
import { AlertService } from 'src/app/services/alert.service';
2021-01-13 10:02:30 +01:00
import { AuthService } from 'src/app/services/auth.service';
import { ChatService } from 'src/app/services/chat.service';
2021-09-21 14:05:59 +01:00
import { FileService } from 'src/app/services/functions/file.service';
2021-10-09 16:41:18 +01:00
import { ProcessesService } from 'src/app/services/processes.service';
2021-07-12 11:13:29 +01:00
import { ToastService } from 'src/app/services/toast.service';
2021-09-21 14:05:59 +01:00
import { NewEventPage } from 'src/app/shared/agenda/new-event/new-event.page';
2020-12-30 11:13:50 +01:00
import { ChatOptionsPopoverPage } from 'src/app/shared/popover/chat-options-popover/chat-options-popover.page';
import { MessagesOptionsPage } from 'src/app/shared/popover/messages-options/messages-options.page';
2021-08-24 14:07:27 +01:00
import { ChatMessageStore } from 'src/app/store/chat/chat-message.service';
import { ChatUserStorage } from 'src/app/store/chat/chat-user.service';
2021-09-21 14:05:59 +01:00
import { environment } from 'src/environments/environment';
2021-10-23 09:53:21 +01:00
import { ThemeService } from 'src/app/services/theme.service'
2022-02-25 15:10:10 +01:00
2022-03-27 18:54:08 +01:00
import { Directory, Encoding, Filesystem, FilesystemDirectory, } from '@capacitor/filesystem';
2021-11-05 18:19:27 +01:00
import { VoiceRecorder, VoiceRecorderPlugin, RecordingData, GenericResponse, CurrentRecordingStatus } from 'capacitor-voice-recorder';
import { Haptics, ImpactStyle } from '@capacitor/haptics';
2021-11-17 15:34:15 +01:00
import { PreviewCameraPage } from 'src/app/modals/preview-camera/preview-camera.page';
2021-12-08 19:36:41 +01:00
import { SqliteService } from 'src/app/services/sqlite.service';
import { elementAt } from 'rxjs-compat/operator/elementAt';
2021-12-07 17:25:09 +01:00
import { ViewMediaPage } from 'src/app/modals/view-media/view-media.page';
2021-12-16 16:36:39 +01:00
import { HttpEventType } from '@angular/common/http';
import { ViewEventPage } from 'src/app/modals/view-event/view-event.page';
2022-01-12 14:48:17 +01:00
import { WsChatMethodsService } from 'src/app/services/chat/ws-chat-methods.service'
2022-01-21 16:55:05 +01:00
import { MessageService } from 'src/app/services/chat/message.service';
2022-02-03 21:01:53 +01:00
import { AttachmentsService } from 'src/app/services/attachments.service';
2022-02-04 07:42:43 +01:00
2022-02-03 21:01:53 +01:00
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';
2022-02-04 00:22:35 +01:00
import { FileToBase64Service } from 'src/app/services/file/file-to-base64.service';
2022-02-08 15:45:09 +01:00
import { Camera, CameraResultType, CameraSource } from '@capacitor/camera';
2022-03-25 09:25:05 +01:00
import { Plugins, Capacitor } from '@capacitor/core';
2022-03-14 08:09:33 +01:00
import { DomSanitizer } from '@angular/platform-browser';
2022-03-27 18:54:08 +01:00
import { StringDecoder } from 'string_decoder';
2022-04-04 00:37:00 +01:00
import { File } from '@awesome-cordova-plugins/file/ngx';
import { FileOpener } from '@awesome-cordova-plugins/file-opener/ngx';
import { DocumentViewer } from '@awesome-cordova-plugins/document-viewer/ngx';
2022-04-18 15:12:27 +01:00
import { SessionStore } from 'src/app/store/session.service';
2022-02-25 15:10:10 +01:00
2021-11-21 19:49:59 +01:00
const IMAGE_DIR = 'stored-images';
2020-12-30 11:13:50 +01:00
@Component({
selector: 'app-messages',
templateUrl: './messages.page.html',
styleUrls: ['./messages.page.scss'],
})
2021-08-23 16:31:06 +01:00
export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
2021-01-27 16:01:49 +01:00
showLoader: boolean;
2021-01-13 10:02:30 +01:00
@ViewChild('scrollMe') private myScrollContainer: ElementRef;
/* @ViewChild('messageContainer') messageContainer: ElementRef; */
@ViewChild('rectangle') private rectangle: ElementRef;
2021-01-13 10:02:30 +01:00
2021-11-23 10:57:07 +01:00
canvas: any
ctx: any
2021-01-13 10:02:30 +01:00
loggedUser: any;
userPresence = '';
dmUsers: any;
roomId: string;
el: any;
members: any;
scrollingOnce: boolean = true;
2021-07-23 14:43:51 +01:00
2021-11-05 18:19:27 +01:00
chatMessageStore = ChatMessageStore;
chatUserStorage = ChatUserStorage;
2021-08-23 16:31:06 +01:00
private scrollChangeCallback: () => void;
currentPosition: any;
startPosition: number;
2021-09-24 15:39:25 +01:00
scrollToBottomBtn = false;
2021-09-21 14:05:59 +01:00
attendees: EventPerson[] = [];
longPressActive = false;
2021-09-30 10:41:40 +01:00
showMessageOptions = false;
selectedMsgId: string;
2021-01-13 10:02:30 +01:00
2021-10-09 16:41:18 +01:00
dicIndex = 0;
task: ExpedientTaskModalPageNavParamsTask;
LoadedDocument: any = null;
2021-10-09 16:41:18 +01:00
2021-11-05 18:19:27 +01:00
recording = false;
2022-03-04 18:46:56 +01:00
allowTyping = true;
2021-11-05 18:19:27 +01:00
storedFileNames = [];
2022-03-04 11:52:43 +01:00
lastAudioRecorded = '';
2022-04-04 00:37:00 +01:00
audioRecorded: any = "";
audioDownloaded: any = "";
2021-11-05 18:19:27 +01:00
durationDisplay = '';
duration = 0;
@ViewChild('recordbtn', { read: ElementRef }) recordBtn: ElementRef;
myAudio: any;
2021-12-16 16:36:39 +01:00
downloadfile: any;
2021-12-17 17:20:43 +01:00
downloadFile: any;
2022-03-27 18:54:08 +01:00
files: any[] = [];
@ViewChild('filechooser') fileChooserElementRef: ElementRef;
//items: File[] = [];
fileSelected?: Blob;
2022-04-04 00:37:00 +01:00
pdfUrl?: string;
2022-03-27 18:54:08 +01:00
base64File: string;
2022-03-09 09:23:27 +01:00
downloadProgess: number;
downloadLoader: boolean;
2021-11-05 18:19:27 +01:00
2022-04-02 09:40:09 +01:00
audioPermissionStatus: 'granted'| 'denied' | 'prompt' | null = null
2022-04-18 15:12:27 +01:00
sessionStore = SessionStore
2022-04-02 09:40:09 +01:00
2020-12-30 11:13:50 +01:00
constructor(
public popoverController: PopoverController,
private modalController: ModalController,
2021-03-12 11:56:54 +01:00
private navParams: NavParams,
2021-01-13 10:02:30 +01:00
private chatService: ChatService,
private authService: AuthService,
2021-04-13 14:14:55 +01:00
private alertService: AlertService,
2021-07-12 11:13:29 +01:00
private toastService: ToastService,
2021-07-27 00:21:30 +01:00
private route: Router,
private activatedRoute: ActivatedRoute,
2021-09-21 14:05:59 +01:00
private fileService: FileService,
private gestureController: GestureController,
2021-10-09 16:41:18 +01:00
private processes: ProcessesService,
2021-11-17 15:34:15 +01:00
public ThemeService: ThemeService,
2021-11-30 12:30:58 +01:00
private changeDetectorRef: ChangeDetectorRef,
2021-12-08 19:36:41 +01:00
private platform: Platform,
2022-01-11 15:43:09 +01:00
private sqlservice: SqliteService,
2022-02-03 21:01:53 +01:00
public wsChatMethodsService: WsChatMethodsService,
private AttachmentsService: AttachmentsService,
2022-02-11 15:08:27 +01:00
2022-02-03 21:01:53 +01:00
private CameraService: CameraService,
private processesService: ProcessesService,
private storage: Storage,
2022-02-04 00:22:35 +01:00
private fileToBase64Service: FileToBase64Service,
2022-03-27 18:54:08 +01:00
private sant: DomSanitizer,
2022-04-07 15:35:48 +01:00
//private fileOpener: FileOpener,
2022-03-14 08:09:33 +01:00
private sanitiser: DomSanitizer,
2022-04-07 14:40:37 +01:00
private alertController: AlertController,
2022-04-07 15:35:48 +01:00
// private document: DocumentViewer
2021-07-23 14:43:51 +01:00
) {
this.loggedUser = authService.ValidatedUserChat['data'];
2021-03-12 11:56:54 +01:00
this.roomId = this.navParams.get('roomId');
2021-12-08 19:36:41 +01:00
console.log('ROOM ID', this.roomId)
2021-09-03 17:02:42 +01:00
window.onresize = (event) => {
if (window.innerWidth > 701) {
2021-09-03 17:02:42 +01:00
this.modalController.dismiss();
}
2022-04-07 15:35:48 +01:00
}
2022-01-11 15:43:09 +01:00
2022-03-14 08:09:33 +01:00
console.log(this.wsChatMethodsService.getDmRoom(this.roomId).loadHistory({}));
2022-02-09 17:06:12 +01:00
this.wsChatMethodsService.getDmRoom(this.roomId).loadHistory({})
2022-01-14 14:50:47 +01:00
this.wsChatMethodsService.getDmRoom(this.roomId).scrollDown = this.scrollToBottomClicked
2022-01-29 19:21:46 +01:00
this.wsChatMethodsService.openRoom(this.roomId)
2022-02-11 15:08:27 +01:00
2022-03-03 08:21:22 +01:00
setTimeout(() => {
2022-01-14 14:58:47 +01:00
this.scrollToBottomClicked()
2022-01-28 16:27:46 +01:00
}, 150)
2022-01-11 15:43:09 +01:00
2022-04-02 09:40:09 +01:00
2021-01-13 10:02:30 +01:00
}
2020-12-30 11:13:50 +01:00
ngOnInit() {
2022-02-03 16:36:05 +01:00
this.wsChatMethodsService.getUserOfRoom(this.roomId).then((value) => {
console.log('MEMBER', value)
})
2021-12-14 17:09:53 +01:00
//this.loadFiles();
2021-11-05 18:19:27 +01:00
VoiceRecorder.requestAudioRecordingPermission();
2022-02-03 16:36:05 +01:00
this.getChatMembers();
2022-03-04 11:52:43 +01:00
/* Filesystem.mkdir({
2021-11-21 19:49:59 +01:00
path: IMAGE_DIR,
directory: Directory.Data,
recursive: true
2022-03-04 11:52:43 +01:00
}); */
2021-11-05 18:19:27 +01:00
}
2021-07-23 14:43:51 +01:00
2021-11-05 18:19:27 +01:00
ngAfterViewInit() {
this.scrollChangeCallback = () => this.onContentScrolled(event);
window.addEventListener('scroll', this.scrollChangeCallback, true);
2021-11-05 18:19:27 +01:00
const longpress = this.gestureController.create({
el: this.recordBtn.nativeElement,
threshold: 0,
gestureName: 'long-press',
onStart: ev => {
Haptics.impact({ style: ImpactStyle.Light })
this.startRecording();
2022-03-04 18:46:56 +01:00
//this.calculateDuration();
2021-11-05 18:19:27 +01:00
},
onEnd: ev => {
2021-11-05 18:19:27 +01:00
Haptics.impact({ style: ImpactStyle.Light })
this.stopRecording();
2022-03-04 18:46:56 +01:00
/* setTimeout(() => {
2022-03-04 11:52:43 +01:00
this.loadFiles();
2022-03-04 18:46:56 +01:00
}, 500); */
2021-11-05 18:19:27 +01:00
}
}, true);
longpress.enable();
}
calculateDuration() {
if (!this.recording) {
2021-11-05 18:19:27 +01:00
this.duration = 0;
this.durationDisplay = '';
return;
}
this.duration += 1;
const minutes = Math.floor(this.duration / 60);
const seconds = (this.duration % 60).toString().padStart(2, '0');
2021-11-05 18:19:27 +01:00
this.durationDisplay = `${minutes}:${seconds}`;
setTimeout(() => {
2021-11-05 18:19:27 +01:00
this.calculateDuration();
}, 1000)
}
async loadFiles() {
2022-03-18 11:45:38 +01:00
this.storage.get('fileName').then((fileName) => {
this.lastAudioRecorded = fileName;
2021-11-05 18:19:27 +01:00
})
2022-03-18 11:45:38 +01:00
2022-03-22 14:23:38 +01:00
try {
this.storage.get('recordData').then((recordData) => {
console.log(recordData);
2022-04-04 00:37:00 +01:00
if (recordData?.value?.recordDataBase64.includes('data:audio')) {
2022-03-24 17:40:14 +01:00
this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(recordData?.value?.recordDataBase64);
2022-03-22 14:23:38 +01:00
}
2022-04-18 15:24:01 +01:00
else if(recordData?.value?.mimeType && recordData?.value?.recordDataBase64) {
2022-03-24 17:40:14 +01:00
this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(`data:${recordData.value.mimeType};base64,${recordData?.value?.recordDataBase64}`);
2022-03-22 14:23:38 +01:00
}
});
2022-04-04 00:37:00 +01:00
} catch (error) { }
2022-03-22 14:23:38 +01:00
}
2022-04-07 15:22:25 +01:00
async startRecording() {
if(await VoiceRecorder.canDeviceVoiceRecord().then((result: GenericResponse) =>{return result.value})){
if(await VoiceRecorder.requestAudioRecordingPermission().then((result: GenericResponse) => {return result.value})){
//if(await this.hasAudioRecordingPermission()){
if (this.recording) {
return;
}
this.recording = true;
VoiceRecorder.startRecording();
this.calculateDuration();
//}
}
else{
this.toastService._badRequest('Para gravar uma mensagem de voz, permita o acesso do Gabinete Digital ao seu microfone.');
}
}
else{
this.toastService._badRequest('Este dispositivo não tem capacidade para gravação de áudio!');
2021-11-05 18:19:27 +01:00
}
}
stopRecording() {
2022-03-18 11:45:38 +01:00
this.deleteRecording();
2022-03-04 18:46:56 +01:00
this.allowTyping = false;
2022-03-02 18:23:05 +01:00
console.log('Stop');
if (!this.recording) {
2021-11-05 18:19:27 +01:00
return;
}
this.recording = false;
VoiceRecorder.stopRecording().then(async (result: RecordingData) => {
2022-03-18 11:45:38 +01:00
console.log(result);
2021-11-05 18:19:27 +01:00
this.recording = false;
if (result.value && result.value.recordDataBase64) {
2021-11-05 18:19:27 +01:00
const recordData = result.value.recordDataBase64;
2022-03-02 18:23:05 +01:00
//console.log(recordData);
2022-03-18 16:42:59 +01:00
const fileName = new Date().getTime() + ".mp3";
2022-03-18 11:45:38 +01:00
//Save file
2022-04-04 00:37:00 +01:00
this.storage.set('fileName', fileName);
this.storage.set('recordData', result).then(() => {
2022-03-18 11:45:38 +01:00
console.log('Audio recorded saved');
2021-11-05 18:19:27 +01:00
})
}
})
2022-03-10 16:26:43 +01:00
setTimeout(async () => {
2022-03-04 18:46:56 +01:00
this.loadFiles();
2022-03-18 11:45:38 +01:00
}, 1000);
2021-11-05 18:19:27 +01:00
}
2022-04-04 00:37:00 +01:00
async deleteRecording() {
2022-03-18 11:45:38 +01:00
this.storage.remove('fileName');
this.storage.remove('recordData');
2021-10-08 15:37:24 +01:00
2022-03-04 18:46:56 +01:00
this.allowTyping = true;
2022-03-04 11:52:43 +01:00
this.lastAudioRecorded = '';
this.loadFiles();
}
2022-03-14 08:09:33 +01:00
handlePress(id?: string) {
2021-09-30 10:41:40 +01:00
this.selectedMsgId = id;
this.showMessageOptions = true;
}
handleClick() {
this.showMessageOptions = false;
2021-09-30 10:41:40 +01:00
this.selectedMsgId = "";
}
deleteMessage(msgId: string) {
2022-03-14 20:44:41 +01:00
const room = this.wsChatMethodsService.getDmRoom(this.roomId)
this.alertService.confirmDeleteMessage(msgId, room);
2021-08-23 16:31:06 +01:00
}
2021-04-13 14:14:55 +01:00
notImplemented() {
2021-04-13 14:14:55 +01:00
this.alertService.presentAlert('Funcionalidade em desenvolvimento');
}
close() {
2021-03-12 11:56:54 +01:00
this.modalController.dismiss();
2022-03-18 11:45:38 +01:00
this.deleteRecording();
2021-03-12 11:56:54 +01:00
}
2021-07-26 09:55:57 +01:00
load() {
2021-01-27 16:01:49 +01:00
this.getChatMembers();
2021-01-13 10:02:30 +01:00
}
2021-07-26 09:55:57 +01:00
doRefresh(ev: any) {
2021-01-27 16:01:49 +01:00
this.load();
ev.target.complete();
}
2021-07-23 14:43:51 +01:00
scrollToBottom(): void {
2021-01-13 10:02:30 +01:00
try {
if (this.scrollingOnce) {
2021-08-23 16:31:06 +01:00
this.myScrollContainer.nativeElement.scrollTop = this.myScrollContainer.nativeElement.scrollHeight;
//this.scrollingOnce = false;
}
} catch (err) { }
2021-01-13 10:02:30 +01:00
}
2022-01-14 14:50:47 +01:00
scrollToBottomClicked = () => {
2021-09-24 15:39:25 +01:00
try {
this.myScrollContainer.nativeElement.scrollTop = this.myScrollContainer.nativeElement.scrollHeight;
} catch (err) { }
2021-09-24 15:39:25 +01:00
}
async goToEvent(eventId: any) {
let classs;
if (window.innerWidth < 701) {
classs = 'modal modal-desktop'
} else {
classs = 'modal modal-desktop showAsideOptions'
}
const modal = await this.modalController.create({
component: ViewEventPage,
componentProps: {
eventId: eventId,
},
cssClass: classs,
});
await modal.present();
modal.onDidDismiss().then((res) => {
console.log(res);
});
}
2021-08-23 16:31:06 +01:00
2021-09-24 15:39:25 +01:00
onContentScrolled(e) {
2021-08-23 16:31:06 +01:00
this.startPosition = e.srcElement.scrollTop;
let scroll = e.srcElement.scrollTop;
2021-09-24 15:39:25 +01:00
let windowHeight = e.srcElement.scrollHeight;
2021-09-24 16:10:24 +01:00
let containerHeight = windowHeight - e.srcElement.clientHeight;
2021-09-24 15:39:25 +01:00
2021-08-23 16:31:06 +01:00
if (scroll > this.currentPosition) {
//alert('BOTTOM');
} else {
//alert('UP');
this.scrollingOnce = false;
}
if ((containerHeight - 100) > scroll) {
2021-09-24 15:39:25 +01:00
this.scrollToBottomBtn = true;
}
else {
2021-09-24 15:39:25 +01:00
this.scrollToBottomBtn = false;
}
2021-08-23 16:31:06 +01:00
this.currentPosition = scroll;
2021-09-24 15:39:25 +01:00
2021-08-23 16:31:06 +01:00
}
ngOnDestroy() {
window.removeEventListener('scroll', this.scrollChangeCallback, true);
}
2021-08-18 18:31:35 +01:00
sendMessage() {
2022-02-04 00:22:35 +01:00
this.wsChatMethodsService.getDmRoom(this.roomId).send({})
2021-01-13 10:02:30 +01:00
}
2021-07-23 14:43:51 +01:00
2022-03-21 21:09:05 +01:00
base64toBlob(base64Data, contentType) {
contentType = contentType || '';
var sliceSize = 1024;
var byteCharacters = atob(base64Data);
var bytesLength = byteCharacters.length;
var slicesCount = Math.ceil(bytesLength / sliceSize);
var byteArrays = new Array(slicesCount);
for (var sliceIndex = 0; sliceIndex < slicesCount; ++sliceIndex) {
2022-04-04 00:37:00 +01:00
var begin = sliceIndex * sliceSize;
var end = Math.min(begin + sliceSize, bytesLength);
2022-03-21 21:09:05 +01:00
2022-04-04 00:37:00 +01:00
var bytes = new Array(end - begin);
for (var offset = begin, i = 0; offset < end; ++i, ++offset) {
bytes[i] = byteCharacters[offset].charCodeAt(0);
}
byteArrays[sliceIndex] = new Uint8Array(bytes);
2022-03-21 21:09:05 +01:00
}
return new Blob(byteArrays, { type: contentType });
2022-04-04 00:37:00 +01:00
}
2022-03-04 14:51:08 +01:00
async sendAudio(fileName) {
const roomId = this.roomId
2022-03-21 21:09:05 +01:00
let audioFile;
2022-03-18 11:45:38 +01:00
this.storage.get('recordData').then((recordData) => {
2022-03-29 00:03:54 +01:00
2022-03-21 21:09:05 +01:00
audioFile = recordData;
2022-04-04 00:37:00 +01:00
if (recordData?.value?.recordDataBase64.includes('data:audio')) {
2022-03-24 17:40:14 +01:00
this.audioRecorded = recordData?.value?.recordDataBase64;
2022-03-18 11:45:38 +01:00
}
2022-04-18 15:24:01 +01:00
else if(recordData?.value?.mimeType && recordData?.value?.recordDataBase64) {
2022-03-24 17:40:14 +01:00
this.audioRecorded = `data:${recordData.value.mimeType};base64,${recordData?.value?.recordDataBase64}`;
2022-03-18 11:45:38 +01:00
}
2022-03-04 14:51:08 +01:00
2022-03-29 00:03:54 +01:00
console.log(this.audioRecorded);
2022-03-04 14:51:08 +01:00
2022-04-04 00:37:00 +01:00
//Converting base64 to blob
const encodedData = btoa(this.audioRecorded);
const blob = this.base64toBlob(encodedData, recordData.value.mimeType)
console.log(blob)
const formData = new FormData();
formData.append("blobFile", blob);
2022-03-04 14:51:08 +01:00
2022-04-04 00:37:00 +01:00
this.wsChatMethodsService.getDmRoom(roomId).send({
file: {
"type": "application/audio",
"msDuration": audioFile.value.msDuration,
"mimeType": audioFile.value.mimeType,
},
attachments: [{
"title": fileName,
"title_link_download": true,
"type": "audio"
}],
temporaryData: formData
})
2022-03-04 14:51:08 +01:00
2022-04-04 00:37:00 +01:00
});
2022-03-21 21:09:05 +01:00
this.deleteRecording();
2022-03-04 14:51:08 +01:00
}
2022-04-06 16:25:47 +01:00
viewDocument(file: any, url?: string) {
console.log()
if (file.type == "application/webtrix") {
this.openViewDocumentModal(file);
2022-02-25 15:10:10 +01:00
}
2022-04-06 16:25:47 +01:00
else {
let fullUrl = "https://www.tabularium.pt" + url;
this.fileService.viewDocumentByUrl(fullUrl);
}
}
2022-03-14 08:09:33 +01:00
/* playSound(url?:any){
alert('here')
console.log(url);
//this.audioDownloaded = this.sanitiser.bypassSecurityTrustResourceUrl(url);
this.audioDownloaded = url;
} */
docIndex(index: number) {
2021-10-09 16:41:18 +01:00
this.dicIndex = index
}
async openViewDocumentModal(file: any) {
2021-10-09 20:24:34 +01:00
let task = {
serialNumber: '',
taskStartDate: '',
isEvent: true,
workflowInstanceDataFields: {
FolderID: '',
Subject: file.Assunto,
SourceSecFsID: file.ApplicationId,
2022-02-25 15:10:10 +01:00
SourceType: 'PDF',
2021-10-09 20:24:34 +01:00
SourceID: file.DocId,
DispatchNumber: ''
2021-10-09 16:41:18 +01:00
}
2021-10-09 20:24:34 +01:00
}
2021-10-09 16:41:18 +01:00
2021-10-09 20:24:34 +01:00
let doc = {
"Id": "",
"ParentId": "",
"Source": 1,
"ApplicationId": file.ApplicationId,
"CreateDate": "",
"Data": null,
"Description": "",
"Link": null,
"SourceId": file.DocId,
"SourceName": file.Assunto,
"Stakeholders": "",
2021-10-09 20:24:34 +01:00
}
2021-10-09 16:41:18 +01:00
2021-10-09 20:24:34 +01:00
const modal = await this.modalController.create({
component: ViewDocumentPage,
componentProps: {
trustedUrl: '',
file: {
title: file.Assunto,
url: '',
title_link: '',
2021-10-09 16:41:18 +01:00
},
2021-10-09 20:24:34 +01:00
Document: doc,
applicationId: file.ApplicationId,
docId: file.DocId,
folderId: '',
task: task
},
cssClass: 'modal modal-desktop'
});
2021-10-09 20:24:34 +01:00
await modal.present();
2021-09-21 14:05:59 +01:00
}
2021-08-18 18:31:35 +01:00
getChatMembers() {
2021-01-27 16:01:49 +01:00
this.showLoader = true;
this.chatService.getMembers(this.roomId).subscribe(res => {
2021-08-18 18:58:02 +01:00
this.members = res['members'];
2022-04-18 15:12:27 +01:00
this.dmUsers = res['members'].filter(data => data.username != this.sessionStore.user.RochetChatUser)
2021-01-27 16:01:49 +01:00
this.showLoader = false;
2021-01-13 10:02:30 +01:00
});
2020-12-30 11:13:50 +01:00
}
showDateDuration(start: any) {
2021-08-20 17:00:48 +01:00
let end;
end = new Date();
start = new Date(start);
let customizedDate;
const totalSeconds = Math.floor((end - (start)) / 1000);;
const totalMinutes = Math.floor(totalSeconds / 60);
const totalHours = Math.floor(totalMinutes / 60);
const totalDays = Math.floor(totalHours / 24);
2021-08-20 17:00:48 +01:00
const hours = totalHours - (totalDays * 24);
const minutes = totalMinutes - (totalDays * 24 * 60) - (hours * 60);
const seconds = totalSeconds - (totalDays * 24 * 60 * 60) - (hours * 60 * 60) - (minutes * 60);
2021-08-20 17:00:48 +01:00
if (totalDays == 0) {
if (start.getDate() == new Date().getDate()) {
2021-08-20 17:00:48 +01:00
let time = start.getHours() + ":" + this.addZero(start.getUTCMinutes());
return time;
}
else {
2021-08-20 17:00:48 +01:00
return 'Ontem';
}
}
else {
let date = start.getDate() + "/" + (start.getMonth() + 1) + "/" + start.getFullYear();
2021-08-20 17:00:48 +01:00
return date;
}
}
addZero(i) {
if (i < 10) {
i = "0" + i;
}
return i;
}
2021-06-03 17:07:29 +01:00
async openMessagesOptions(ev?: any) {
2020-12-30 11:13:50 +01:00
const popover = await this.popoverController.create({
component: MessagesOptionsPage,
2021-01-13 10:02:30 +01:00
componentProps: {
2021-03-12 11:56:54 +01:00
roomId: this.roomId,
2021-01-13 10:02:30 +01:00
},
2020-12-30 11:13:50 +01:00
cssClass: 'messages-options',
event: ev,
2021-01-13 10:02:30 +01:00
translucent: true,
2020-12-30 11:13:50 +01:00
});
return await popover.present();
}
async addContacts() {
2020-12-30 11:13:50 +01:00
const modal = await this.modalController.create({
component: ContactsPage,
2021-07-23 14:43:51 +01:00
componentProps: {},
2020-12-30 11:13:50 +01:00
cssClass: 'contacts',
backdropDismiss: false
});
await modal.present();
modal.onDidDismiss();
}
2021-09-21 14:05:59 +01:00
async bookMeeting() {
this.attendees = this.members.map((val) => {
2021-09-21 14:05:59 +01:00
return {
Name: val.name,
EmailAddress: val.username + "@" + environment.domain,
2021-09-21 14:05:59 +01:00
IsRequired: "true",
}
});
console.log(this.attendees);
this.popoverController.dismiss();
if (window.innerWidth <= 1024) {
2021-09-21 14:05:59 +01:00
const modal = await this.modalController.create({
component: NewEventPage,
componentProps: {
2021-09-21 14:05:59 +01:00
attendees: this.attendees,
},
cssClass: 'modal modal-desktop',
backdropDismiss: false
});
await modal.present();
modal.onDidDismiss().then((data) => {
if (data) {
2021-09-21 14:05:59 +01:00
}
});
}
}
2022-02-03 21:01:53 +01:00
async takePicture() {
const roomId = this.roomId
2022-02-11 15:08:27 +01:00
2022-02-03 21:01:53 +01:00
const image = await this.CameraService.takePicture();
2022-02-04 07:42:43 +01:00
await this.fileService.saveImage(image)
const lastphoto: any = await this.fileService.loadFiles();
2022-03-03 08:21:22 +01:00
const { capturedImage, capturedImageTitle } = await this.fileService.loadFileData(lastphoto);
2022-02-03 21:01:53 +01:00
2022-02-11 15:08:27 +01:00
2022-02-07 17:55:00 +01:00
const base64 = await fetch(capturedImage);
const blob = await base64.blob();
const formData = new FormData();
formData.append("blobFile", blob);
console.log('ALL IMAGE', formData)
this.wsChatMethodsService.getDmRoom(roomId).send({
2022-02-04 00:22:35 +01:00
file: {
"type": "application/img",
2022-02-08 17:44:15 +01:00
"guid": ''
2022-02-04 00:22:35 +01:00
},
attachments: [{
2022-03-03 08:21:22 +01:00
"title": capturedImageTitle,
2022-02-04 00:57:46 +01:00
"text": "description",
2022-02-04 00:22:35 +01:00
"title_link_download": false,
2022-02-07 17:55:00 +01:00
}],
2022-02-07 20:18:48 +01:00
temporaryData: formData
2022-02-04 00:22:35 +01:00
})
2022-02-03 21:01:53 +01:00
}
2022-02-08 15:45:09 +01:00
async addImageMobile() {
this.addFileToChatMobile(['image/apng', 'image/jpeg', 'image/png'])
}
2022-02-11 15:08:27 +01:00
2022-02-03 21:01:53 +01:00
async addImage() {
this.addFileToChat(['image/apng', 'image/jpeg', 'image/png'])
}
2022-02-11 15:08:27 +01:00
2022-02-03 21:01:53 +01:00
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();
2022-03-03 08:21:22 +01:00
modal.onDidDismiss().then(async res => {
2022-02-03 21:01:53 +01:00
const data = res.data;
2022-02-04 08:11:49 +01:00
const roomId = this.roomId
2022-02-03 21:01:53 +01:00
2022-03-03 08:21:22 +01:00
if (data.selected) {
2022-02-03 21:01:53 +01:00
2022-02-07 17:55:00 +01:00
this.wsChatMethodsService.getDmRoom(roomId).send({
2022-03-03 08:21:22 +01:00
file: {
2022-02-03 21:01:53 +01:00
"name": res.data.selected.Assunto,
"type": "application/webtrix",
"ApplicationId": res.data.selected.ApplicationType,
"DocId": res.data.selected.Id,
"Assunto": res.data.selected.Assunto,
},
2022-04-06 16:25:47 +01:00
temporaryData: res,
2022-02-04 00:22:35 +01:00
attachments: [{
"title": res.data.selected.Assunto,
"description": res.data.selected.DocTypeDesc,
// "title_link": url_no_options,
"title_link_download": true,
2022-02-07 17:55:00 +01:00
"thumb_url": "https://static.ichimura.ed.jp/uploads/2017/10/pdf-icon.png",
2022-02-04 00:22:35 +01:00
// "message_link": url_no_options,
2022-02-04 08:00:10 +01:00
"text": res.data.selected.DocTypeDesc,
2022-02-07 17:55:00 +01:00
"type": "webtrix"
2022-02-07 20:18:48 +01:00
}],
2022-02-03 21:01:53 +01:00
})
2022-02-04 00:22:35 +01:00
2022-02-03 21:01:53 +01:00
}
});
}
2022-03-03 08:21:22 +01:00
async addFileToChatMobile(types: typeof FileType[]) {
2022-02-08 15:45:09 +01:00
const roomId = this.roomId
const file = await Camera.getPhoto({
quality: 90,
// allowEditing: true,
resultType: CameraResultType.Base64,
source: CameraSource.Photos
});
console.log('ADDFILECHAT', file)
//const imageData = await this.fileToBase64Service.convert(file)
//console.log('ADDFILECHAT', imageData)
2022-03-03 08:21:22 +01:00
const response = await fetch('data:image/jpeg;base64,' + file.base64String!);
2022-02-08 15:45:09 +01:00
const blob = await response.blob();
const formData = new FormData();
formData.append("blobFile", blob);
2022-02-11 15:08:27 +01:00
2022-02-08 15:45:09 +01:00
this.wsChatMethodsService.getDmRoom(roomId).send({
file: {
"type": "application/img",
2022-02-09 14:39:59 +01:00
"guid": ''
2022-02-08 15:45:09 +01:00
},
temporaryData: formData,
attachments: [{
2022-03-03 08:21:22 +01:00
"title": file.path,
2022-02-08 15:45:09 +01:00
"text": "description",
"title_link_download": false,
}]
})
}
2022-03-27 18:54:08 +01:00
getFileReader(): FileReader {
const fileReader = new FileReader();
const zoneOriginalInstance = (fileReader as any)["__zone_symbol__originalInstance"];
return zoneOriginalInstance || fileReader;
2022-04-04 00:37:00 +01:00
}
2022-02-03 21:01:53 +01:00
2022-03-03 08:21:22 +01:00
async addFileToChat(types: typeof FileType[]) {
2022-02-25 15:10:10 +01:00
2022-02-04 08:11:49 +01:00
const roomId = this.roomId
2022-03-27 18:54:08 +01:00
const file: any = await this.fileService.getFileFromDevice(types);
2022-04-04 00:37:00 +01:00
2022-03-27 18:54:08 +01:00
console.log('Add file', JSON.stringify(await this.getBase64(file)))
2022-04-06 16:25:47 +01:00
if (file.type != "application/img" && file.type != "image/png" && file.type != "image/jpeg" && file.type != "image/gif") {
2022-02-04 00:22:35 +01:00
const encodedData = btoa(JSON.stringify(await this.getBase64(file)));
2022-04-05 17:39:14 +01:00
const blob = this.base64toBlob(encodedData, file.type)
console.log('Add Blob file', blob)
2022-02-11 15:08:27 +01:00
const formData = new FormData();
formData.append('blobFile', blob);
console.log(formData)
2022-03-25 09:25:05 +01:00
this.wsChatMethodsService.getDmRoom(roomId).send({
file: {
"type": file.type,
"guid": '',
},
attachments: [{
"title": file.name,
"name": file.name,
// "text": "description",
"title_link_download": false,
}],
temporaryData: formData
});
2022-04-06 16:25:47 +01:00
} else {
console.log('File type invalid')
2022-04-06 16:25:47 +01:00
}
2022-03-25 09:25:05 +01:00
2022-03-27 18:54:08 +01:00
}
2022-02-04 00:22:35 +01:00
2022-03-27 18:54:08 +01:00
getBase64(file) {
var reader = this.getFileReader();
reader.readAsDataURL(file);
return new Promise(resolve => {
reader.onload = function () {
resolve(reader.result)
};
reader.onerror = function (error) {
console.log('Error: ', error);
};
});
2022-04-04 00:37:00 +01:00
}
2022-03-27 18:54:08 +01:00
2021-08-18 18:58:02 +01:00
async openChatOptions(ev?: any) {
2021-10-07 15:30:36 +01:00
const roomId = this.roomId
2022-03-03 08:21:22 +01:00
console.log('MOBILE CHAT OPTION', this.members);
2021-08-18 18:58:02 +01:00
2020-12-30 11:13:50 +01:00
const popover = await this.popoverController.create({
component: ChatOptionsPopoverPage,
cssClass: 'chat-options-popover',
event: ev,
2021-08-18 18:58:02 +01:00
componentProps: {
room: this.roomId,
members: this.members,
eventSelectedDate: new Date(),
},
2020-12-30 11:13:50 +01:00
translucent: true
});
2021-09-21 14:05:59 +01:00
await popover.present();
2022-03-03 08:21:22 +01:00
popover.onDidDismiss().then(async (res) => {
2021-09-21 14:05:59 +01:00
console.log(res['data']);
if (res['data'] == 'meeting') {
2021-09-21 14:05:59 +01:00
this.bookMeeting();
}
else if (res['data'] == 'take-picture') {
2022-02-04 08:00:10 +01:00
this.takePicture()
2021-09-21 14:05:59 +01:00
}
else if (res['data'] == 'add-picture') {
2022-02-08 15:45:09 +01:00
this.addImageMobile()
2021-09-21 14:05:59 +01:00
}
else if (res['data'] == 'add-document') {
2022-02-03 21:01:53 +01:00
this.addFile()
2021-09-21 14:05:59 +01:00
}
else if (res['data'] == 'documentoGestaoDocumental') {
2021-09-21 14:05:59 +01:00
2022-02-03 21:01:53 +01:00
this.addFileWebtrix()
2021-09-21 14:05:59 +01:00
}
2022-01-29 20:39:35 +01:00
2021-09-21 14:05:59 +01:00
});
2020-12-30 11:13:50 +01:00
}
2021-12-16 16:36:39 +01:00
2021-12-08 19:36:41 +01:00
getRoomMessageDB(roomId) {
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
} else {
this.sqlservice.getAllChatMSG(roomId).then((msg: any) => {
2021-12-23 07:40:01 +01:00
console.log('ALL MSG DBBB', msg)
2021-12-08 19:36:41 +01:00
let chatmsgArray = [];
let array = []
msg.forEach(element => {
console.log('CHANNEL ELEMENT', element.channels)
2021-12-08 19:36:41 +01:00
let msgChat = {
_id: element.Id,
attachments: this.isJson(element.Attachments),
channels: this.isJson(element.Channels),
file: this.isJson(element.File),
mentions: this.isJson(element.Mentions),
msg: element.Msg,
rid: element.Rid,
ts: element.Ts,
u: this.isJson(element.U),
2021-12-23 07:40:01 +01:00
_updatedAt: element.UpdatedAt,
image_url: this.isJson(element.image_url)
2021-12-08 19:36:41 +01:00
}
chatmsgArray.push(msgChat)
});
2022-01-29 20:39:35 +01:00
2021-12-08 19:36:41 +01:00
console.log('CHAT MSG FROM DB', chatmsgArray)
})
}
}
isJson(str) {
try {
JSON.parse(str);
2021-12-08 19:36:41 +01:00
} catch (e) {
return "";
2021-12-08 19:36:41 +01:00
}
return JSON.parse(str);
}
2021-12-08 19:36:41 +01:00
transformDataMSG(res) {
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
} else {
res.forEach(element => {
2021-12-16 16:36:39 +01:00
2021-12-08 19:36:41 +01:00
let chatmsg = {
_id: element._id,
attachments: element.attachments,
channels: element.channels,
file: element.file,
mentions: element.mentions,
msg: element.msg,
rid: element.rid,
ts: element.ts,
u: element.u,
2021-12-16 16:36:39 +01:00
_updatedAt: element._updatedAt,
/* image_url: {
name: name,
path: `${IMAGE_DIR}/${name}`,
data: `data:image/jpeg;base64,${readFile.data}`,
}, */
2021-12-08 19:36:41 +01:00
}
this.sqlservice.addChatMSG(chatmsg)
2021-12-16 16:36:39 +01:00
2021-12-08 19:36:41 +01:00
});
}
2021-12-08 19:36:41 +01:00
}
2022-04-04 00:37:00 +01:00
/* testeDownload(msg: MessageService) {
this.downloadFile = "";
this.AttachmentsService.downloadFileAndStore(msg.file.guid);
} */
2022-03-09 09:23:27 +01:00
2021-11-17 15:34:15 +01:00
2022-01-21 16:55:05 +01:00
downloadFileMsg(msg: MessageService) {
msg.downloadFileMsg();
2021-12-17 17:20:43 +01:00
}
2021-11-23 10:57:07 +01:00
b64toBlob(b64Data, contentType) {
2022-04-04 00:37:00 +01:00
contentType = contentType || '';
var sliceSize = 512;
b64Data = b64Data.replace(/^[^,]+,/, '');
b64Data = b64Data.replace(/\s/g, '');
var byteCharacters = window.atob(b64Data);
2022-04-04 00:37:00 +01:00
var byteArrays = [];
2022-04-04 00:37:00 +01:00
for (var offset = 0; offset < byteCharacters.length; offset += sliceSize) {
var slice = byteCharacters.slice(offset, offset + sliceSize);
2022-04-04 00:37:00 +01:00
var byteNumbers = new Array(slice.length);
for (var i = 0; i < slice.length; i++) {
byteNumbers[i] = slice.charCodeAt(i);
}
2022-04-04 00:37:00 +01:00
var byteArray = new Uint8Array(byteNumbers);
2022-04-04 00:37:00 +01:00
byteArrays.push(byteArray);
}
2022-04-04 00:37:00 +01:00
var blob = new Blob(byteArrays, { type: contentType });
return blob;
2021-12-17 17:20:43 +01:00
}
2021-11-23 10:57:07 +01:00
2022-04-05 17:39:14 +01:00
openFile(pdfString, filename, type) {
2022-04-07 15:35:48 +01:00
// const blob = this.b64toBlob(pdfString, type)
// let pathFile = ''
// const fileName = filename
// const contentFile = blob
// if (this.platform.is('ios')) {
// pathFile = this.file.documentsDirectory
// } else {
// pathFile = this.file.externalRootDirectory
// }
// console.log(pdfString)
// console.log(pathFile)
// console.log(contentFile)
// this.file
// .writeFile(pathFile, fileName, contentFile, { replace: true })
// .then(success => {
// this.fileOpener
// .open(pathFile + fileName, type)
// .then(() => console.log('File is opened'))
// .catch(e => console.log('Error opening file', e));
// })
// .catch(e => console.log('Error writing file', e))
2022-03-09 09:23:27 +01:00
}
2022-04-06 16:25:47 +01:00
downloadFileFromBrowser(fileName: string, data: any): void {
const linkSource = data;
const downloadLink = document.createElement("a");
downloadLink.href = linkSource;
downloadLink.download = fileName;
downloadLink.click();
}
2022-04-04 00:37:00 +01:00
2021-11-17 15:34:15 +01:00
async openPreview(msg) {
2022-03-03 08:21:22 +01:00
console.log(msg);
2022-01-21 16:55:05 +01:00
2022-04-06 16:25:47 +01:00
if(msg.file.type === "application/webtrix") {
this.viewDocument(msg.file, msg.attachments.image_url)
2022-01-21 16:55:05 +01:00
} else {
2022-04-06 16:25:47 +01:00
if (!msg.attachments[0].image_url || msg.attachments[0].image_url === null || msg.attachments[0].image_url === '') {
this.downloadFileMsg(msg)
//this.testDownlod(msg)
2022-04-07 15:22:25 +01:00
} else {
2022-04-06 16:25:47 +01:00
var str = msg.attachments[0].image_url;
str = str.substring(1, ((str.length) - 1));
2022-04-07 15:22:25 +01:00
2022-04-06 16:25:47 +01:00
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
2022-04-07 15:22:25 +01:00
2022-04-06 16:25:47 +01:00
this.downloadFileFromBrowser(msg.attachments[0].name, str)
/* const modal = await this.modalController.create({
component: ViewMediaPage,
cssClass: 'modal modal-desktop',
componentProps: {
image: str,
type: msg.file.type,
username: msg.u.name,
_updatedAt: msg._updatedAt
}
});
modal.present(); */
2022-04-07 15:22:25 +01:00
2022-04-06 16:25:47 +01:00
} else {
this.openFile(str, msg.attachments[0].name, msg.file.type);
}
2022-04-07 15:22:25 +01:00
}
2021-12-17 17:20:43 +01:00
}
2022-01-21 16:55:05 +01:00
2021-11-17 15:34:15 +01:00
}
2021-11-22 13:53:37 +01:00
2022-03-21 21:09:05 +01:00
async audioPreview(msg) {
console.log(msg);
if (!msg.attachments[0].title_link || msg.attachments[0].title_link === null || msg.attachments[0].title_link === '') {
this.downloadFileMsg(msg)
2022-04-04 00:37:00 +01:00
} else { }
2022-03-21 21:09:05 +01:00
}
2021-11-29 15:48:35 +01:00
imageSize(img) {
2021-11-22 13:53:37 +01:00
var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');
canvas.width = 300
canvas.height = 234
2021-11-22 13:53:37 +01:00
ctx.drawImage(img.attachments[0].image_url, 0, 0, 300, 234);
document.body.appendChild(canvas);
}
2021-11-23 10:57:07 +01:00
getPicture(img) {
var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');
canvas.width = 300
canvas.height = 234
ctx.drawImage(img.attachments[0].image_url, 0, 0, 300, 234);
document.body.appendChild(canvas);
2021-11-23 10:57:07 +01:00
}
2021-11-30 12:30:58 +01:00
2022-02-25 15:10:10 +01:00
2021-11-30 17:56:56 +01:00
// async ShareEmail(msg){
// // Check if sharing via email is supported
// await Share.share({
// title: msg.u.username,
// text: msg._updatedAt,
// url: msg.attachments[0].image_url,
// dialogTitle: 'Share with buddies',
// });
// }
2022-02-16 15:52:59 +01:00
hkellor() {
// alert('cool!')
}
2021-07-23 14:43:51 +01:00
}
2021-11-17 15:34:15 +01:00