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

863 lines
24 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-02-07 13:41:27 +01:00
import { GestureController, Gesture, ModalController, NavParams, PopoverController, Platform } 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'
2021-11-05 18:19:27 +01:00
import { Filesystem, Directory, Encoding } from '@capacitor/filesystem';
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';
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;
storedFileNames = [];
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;
2021-11-05 18:19:27 +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-04 07:42:43 +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,
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-01-11 15:43:09 +01:00
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-01-14 14:58:47 +01:00
setTimeout(()=>{
this.scrollToBottomClicked()
2022-01-28 16:27:46 +01:00
}, 150)
2022-01-11 15:43: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-01-13 10:02:30 +01:00
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();
2021-11-21 19:49:59 +01:00
Filesystem.mkdir({
path: IMAGE_DIR,
directory: Directory.Data,
recursive: true
});
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();
this.calculateDuration();
},
onEnd: ev => {
2021-11-05 18:19:27 +01:00
Haptics.impact({ style: ImpactStyle.Light })
this.stopRecording();
}
}, 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() {
2021-11-05 18:19:27 +01:00
Filesystem.readdir({
path: '',
directory: Directory.Data
}).then(result => {
2021-11-05 18:19:27 +01:00
console.log(result);
const temp: any[] = result.files.reverse();
2021-11-05 18:19:27 +01:00
this.storedFileNames = temp[0];
console.log(this.storedFileNames);
2021-11-05 18:19:27 +01:00
})
}
startRecording() {
if (this.recording) {
2021-11-05 18:19:27 +01:00
return;
}
this.recording = true;
VoiceRecorder.startRecording();
}
stopRecording() {
if (!this.recording) {
2021-11-05 18:19:27 +01:00
return;
}
this.recording = false;
VoiceRecorder.stopRecording().then(async (result: RecordingData) => {
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;
console.log(recordData);
this.myAudio = recordData;
const fileName = new Date().getTime() + ".wav";
await Filesystem.writeFile({
path: fileName,
directory: Directory.Data,
data: recordData,
})
}
})
}
async playFile(fileName?: any) {
2021-11-05 18:19:27 +01:00
const audioFile = await Filesystem.readFile({
path: fileName,
directory: Directory.Data
})
console.log(audioFile);
const base64sound = audioFile.data;
2021-11-05 18:19:27 +01:00
const audioRef = new Audio(`data:audio/aac;base64,${base64sound}`)
audioRef.oncanplaythrough = () => audioRef.play();
audioRef.load();
2021-10-08 15:37:24 +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) {
let body = {
"roomId": this.roomId,
"msgId": msgId,
"asUser": false,
}
if (msgId) {
2022-01-28 15:31:52 +01:00
//this.alertService.confirmDeleteMessage(body);
2021-09-30 10:41:40 +01:00
}
else {
2021-09-30 10:41:40 +01:00
this.toastService.badRequest('Não foi possível apagar');
}
this.showMessageOptions = false;
this.selectedMsgId = "";
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();
}
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
viewDocument(file: any, url?: string) {
2021-10-09 16:41:18 +01:00
if (file.type == "application/webtrix") {
2021-10-09 20:55:05 +01:00
this.openViewDocumentModal(file);
}
}
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,
SourceType: 'DOC',
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'];
2021-01-13 10:02:30 +01:00
this.dmUsers = res['members'].filter(data => data.username != this.loggedUser.me.username)
console.log(res);
console.log(this.dmUsers);
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
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();
const { capturedImage, capturedImageTitle} = await this.fileService.loadFileData(lastphoto);
2022-02-03 21:01:53 +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-02-07 20:52:07 +01:00
"image_url": capturedImage,
2022-02-04 00:57:46 +01:00
"title": capturedImageTitle ,
"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-03 21:01:53 +01:00
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;
2022-02-04 08:11:49 +01:00
const roomId = this.roomId
2022-02-03 21:01:53 +01:00
2022-02-04 00:22:35 +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-02-03 21:01:53 +01:00
file:{
"name": res.data.selected.Assunto,
"type": "application/webtrix",
"ApplicationId": res.data.selected.ApplicationType,
"DocId": res.data.selected.Id,
"Assunto": res.data.selected.Assunto,
},
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-02-08 15:45:09 +01:00
async addFileToChatMobile(types: typeof FileType[] ) {
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-02-08 17:14:14 +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);
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: [{
"title": file.path ,
"image_url": 'data:image/jpeg;base64,' +file.base64String,
"text": "description",
"title_link_download": false,
}]
})
}
2022-02-03 21:01:53 +01:00
2022-02-04 00:22:35 +01:00
2022-02-03 21:01:53 +01:00
async addFileToChat(types: typeof FileType[] ) {
2022-02-04 08:11:49 +01:00
const roomId = this.roomId
2022-02-07 13:41:27 +01:00
const file: any = await this.fileService.getFileFromDevice(types);
2022-02-08 10:21:50 +01:00
console.log('ADDFILECHAT', file)
2022-02-04 00:22:35 +01:00
const imageData = await this.fileToBase64Service.convert(file)
2022-02-08 10:21:50 +01:00
console.log('ADDFILECHAT', imageData)
2022-02-04 00:22:35 +01:00
2022-02-03 21:01:53 +01:00
const formData = new FormData();
formData.append("blobFile", file);
2022-02-04 00:22:35 +01:00
2022-02-07 17:55:00 +01:00
this.wsChatMethodsService.getDmRoom(roomId).send({
2022-02-04 00:22:35 +01:00
file: {
"type": "application/img",
"guid": '',
},
2022-02-07 20:18:48 +01:00
temporaryData: formData,
2022-02-04 00:22:35 +01:00
attachments: [{
2022-02-04 00:57:46 +01:00
"title": file.name ,
2022-02-07 20:52:07 +01:00
"image_url": imageData,
2022-02-04 00:57:46 +01:00
"text": "description",
2022-02-04 00:22:35 +01:00
"title_link_download": false,
}]
})
2022-02-03 21:01:53 +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-02-02 11:58:01 +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-02-03 21:01:53 +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
}
2021-11-17 15:34:15 +01:00
2022-01-21 16:55:05 +01:00
downloadFileMsg(msg: MessageService) {
2021-12-17 17:20:43 +01:00
console.log('FILE TYPE', msg.file.type)
this.downloadFile = "";
if (msg.file.type == "application/img") {
2022-02-03 21:01:53 +01:00
this.AttachmentsService.downloadFile(msg.file.guid).subscribe(async (event) => {
2021-12-17 17:20:43 +01:00
console.log('FILE TYPE 22', msg.file.guid)
var name = msg.file.guid;
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) {
this.downloadFile = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), ''));
2022-01-21 16:55:05 +01:00
msg.file = {
guid: msg.file.guid,
image_url: this.downloadFile,
type: msg.file.type
}
2021-12-17 17:20:43 +01:00
this.sqlservice.updateChatMsg(msg._id, this.downloadFile);
}
2022-01-21 16:55:05 +01:00
2021-12-17 17:20:43 +01:00
});
2022-01-21 16:55:05 +01:00
2021-12-17 17:20:43 +01:00
}
2022-01-21 16:55:05 +01:00
2021-12-17 17:20:43 +01:00
}
2021-11-23 10:57:07 +01:00
2021-11-17 15:34:15 +01:00
async openPreview(msg) {
2022-01-21 16:55:05 +01:00
if (msg.file.image_url === null || msg.file.image_url === '' ) {
this.downloadFileMsg(msg)
} else {
2021-12-17 17:20:43 +01:00
const modal = await this.modalController.create({
component: ViewMediaPage,
cssClass: 'modal modal-desktop',
componentProps: {
2022-01-21 16:55:05 +01:00
image: msg.file.image_url,
2021-12-17 17:20:43 +01:00
username: msg.u.name,
2022-01-21 16:55:05 +01:00
_updatedAt: msg._updatedAt
2021-12-17 17:20:43 +01:00
}
});
modal.present();
}
2022-01-21 16:55:05 +01:00
2021-11-17 15:34:15 +01:00
}
2021-11-22 13:53:37 +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
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',
// });
// }
2021-07-23 14:43:51 +01:00
}
2021-11-17 15:34:15 +01:00