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

787 lines
22 KiB
TypeScript
Raw Normal View History

2021-12-16 16:36:39 +01:00
import { AfterViewChecked, AfterViewInit, Component, ElementRef, ChangeDetectorRef, EventEmitter, Input, OnChanges, OnDestroy, OnInit, Output, SimpleChanges, ViewChild } from '@angular/core';
2021-11-22 13:53:37 +01:00
import { AnimationController, GestureController, IonSlides, ModalController, PopoverController } from '@ionic/angular';
2021-04-13 14:14:55 +01:00
import { AlertService } from 'src/app/services/alert.service';
2021-03-04 18:49:50 +01:00
import { AuthService } from 'src/app/services/auth.service';
import { ChatService } from 'src/app/services/chat.service';
2021-07-12 11:13:29 +01:00
import { ToastService } from 'src/app/services/toast.service';
2021-03-04 18:49: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-03-12 11:56:54 +01:00
import { ContactsPage } from '../new-group/contacts/contacts.page';
2021-07-26 19:31:19 +01:00
import { Router } from '@angular/router';
2021-08-18 18:58:02 +01:00
import { ChatOptionsFeaturesPage } from 'src/app/modals/chat-options-features/chat-options-features.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-06 16:53:58 +01:00
import { TimeService } from 'src/app/services/functions/time.service';
2021-09-21 14:05:59 +01:00
import { FileService } from 'src/app/services/functions/file.service';
2022-02-07 13:41:27 +01:00
import { HttpClient, HttpEventType } from '@angular/common/http';
import { ViewDocumentPage } from 'src/app/modals/view-document/view-document.page';
2021-10-23 09:53:21 +01:00
import { ThemeService } from 'src/app/services/theme.service'
import { ViewMediaPage } from 'src/app/modals/view-media/view-media.page';
2021-12-16 16:36:39 +01:00
import { SqliteService } from 'src/app/services/sqlite.service';
import { StorageService } from 'src/app/services/storage.service';
import { Directory, Filesystem } from '@capacitor/filesystem';
import { ViewEventPage } from 'src/app/modals/view-event/view-event.page';
2022-01-05 21:27:26 +01:00
import { Storage } from '@ionic/storage';
2022-01-20 14:31:49 +01:00
import { WsChatMethodsService } from 'src/app/services/chat/ws-chat-methods.service'
2022-01-14 14:50:47 +01:00
import { WsChatService } from 'src/app/services/chat/ws-chat.service'
2022-01-20 14:31:49 +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 { FileType } from 'src/app/models/fileType';
import { SearchPage } from 'src/app/pages/search/search.page';
import { ProcessesService } from 'src/app/services/processes.service';
2022-02-04 00:22:35 +01:00
import { FileToBase64Service } from 'src/app/services/file/file-to-base64.service';
2022-02-09 13:59:41 +01:00
import { Camera, CameraResultType, CameraSource } from '@capacitor/camera';
2022-02-10 19:47:16 +01:00
import { DocumentViewer, DocumentViewerOptions} from '@ionic-native/document-viewer';
2021-03-04 18:49:50 +01:00
2021-12-16 16:36:39 +01:00
const IMAGE_DIR = 'stored-images';
2021-03-04 18:49: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, OnChanges, AfterViewInit, OnDestroy {
2021-03-04 18:49:50 +01:00
showLoader: boolean;
@ViewChild('scrollMe') private myScrollContainer: ElementRef;
@ViewChild('message-item') messageContainer: ElementRef;
2021-03-04 18:49:50 +01:00
loggedUser: any;
2021-12-16 16:36:39 +01:00
messages: any;
dm: any;
userPresence = '';
dmUsers: any;
2021-07-26 19:31:19 +01:00
checktimeOut: boolean;
2021-12-16 16:36:39 +01:00
members: any;
downloadProgess = 0;
2021-03-04 18:49:50 +01:00
2021-12-16 16:36:39 +01:00
@Input() roomId: string;
@Input() showMessages: string;
2021-07-23 14:43:51 +01:00
2021-12-16 16:36:39 +01:00
@Output() openNewEventPage: EventEmitter<any> = new EventEmitter<any>();
@Output() getDirectMessages: EventEmitter<any> = new EventEmitter<any>();
2021-08-20 11:58:28 +01:00
2021-08-19 09:10:38 +01:00
2021-08-24 14:07:27 +01:00
chatMessageStore = ChatMessageStore
chatUserStorage = ChatUserStorage
2021-12-16 16:36:39 +01:00
scrollingOnce: boolean = true;
2021-08-23 16:31:06 +01:00
private scrollChangeCallback: () => void;
currentPosition: any;
startPosition: number;
mesageItemDropdownOptions: boolean = false;
scrollToBottomBtn = false;
longPressActive = false;
2021-10-18 17:10:33 +01:00
frameUrl: any;
2021-12-16 16:36:39 +01:00
downloadFile: any;
2022-01-20 14:31:49 +01:00
massages: MessageService[] = []
2021-08-20 11:24:42 +01:00
2022-02-24 14:59:47 +01:00
showAvatar = true
2021-03-04 18:49:50 +01:00
constructor(
public popoverController: PopoverController,
private modalController: ModalController,
2021-03-12 11:56:54 +01:00
/* private navParams: NavParams, */
2021-03-04 18:49:50 +01:00
private chatService: ChatService,
private authService: AuthService,
2021-03-18 09:25:59 +01:00
private animationController: AnimationController,
2021-04-13 14:14:55 +01:00
private alertService: AlertService,
2021-07-12 11:13:29 +01:00
private toastService: ToastService,
2021-09-06 16:53:58 +01:00
private route: Router,
private timeService: TimeService,
2021-09-21 14:05:59 +01:00
private fileService: FileService,
private gestureController: GestureController,
2021-12-16 16:36:39 +01:00
private http: HttpClient,
2021-11-22 13:53:37 +01:00
public ThemeService: ThemeService,
2021-12-16 16:36:39 +01:00
private changeDetectorRef: ChangeDetectorRef,
private sqliteservice: SqliteService,
2021-12-23 07:43:52 +01:00
private storageservice: StorageService,
private router: Router,
2022-01-19 09:12:30 +01:00
private storage: Storage,
2022-01-14 14:50:47 +01:00
public wsChatMethodsService: WsChatMethodsService,
2022-02-03 21:01:53 +01:00
public WsChatService: WsChatService,
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,
2022-02-04 00:22:35 +01:00
private fileToBase64Service: FileToBase64Service,
2021-07-23 14:43:51 +01:00
) {
2022-01-12 14:48:17 +01:00
2021-07-23 14:43:51 +01:00
this.loggedUser = authService.ValidatedUserChat['data'];
2021-03-12 11:56:54 +01:00
}
ngOnChanges(changes: SimpleChanges): void {
2022-02-09 17:06:12 +01:00
this.wsChatMethodsService.getDmRoom(this.roomId).loadHistory({})
2022-01-14 14:58:47 +01:00
2022-01-29 19:21:46 +01:00
this.wsChatMethodsService.getDmRoom(this.roomId).scrollDown = this.scrollToBottomClicked
2022-01-20 14:31:49 +01:00
2022-01-29 19:21:46 +01:00
this.wsChatMethodsService.openRoom(this.roomId)
2022-02-04 00:22:35 +01:00
this.wsChatMethodsService.getDmRoom(this.roomId).uploadAttachment = async (formData) => {
let guid: any = await this.AttachmentsService.uploadFile(formData).toPromise()
}
2022-02-24 14:59:47 +01:00
this.showAvatar = false
2022-01-20 14:31:49 +01:00
setTimeout(() => {
2022-01-14 14:58:47 +01:00
this.scrollToBottomClicked()
2022-02-24 14:59:47 +01:00
this.showAvatar = true
2022-01-29 19:21:46 +01:00
}, 150)
2022-01-20 14:31:49 +01:00
2021-03-04 18:49:50 +01:00
}
ngOnInit() {
2021-07-26 09:44:11 +01:00
this.scrollToBottom();
2022-01-20 14:31:49 +01:00
2022-02-03 16:36:05 +01:00
this.getChatMembers();
2022-01-20 14:31:49 +01:00
2021-07-26 19:31:19 +01:00
}
2022-01-20 14:31:49 +01:00
2021-12-16 16:36:39 +01:00
onPressingMessage() {
const gesture = this.gestureController.create({
el: this.messageContainer.nativeElement,
gestureName: 'long-press',
2021-12-16 16:36:39 +01:00
onStart: ev => {
this.longPressActive = true;
console.log('Pressing');
},
onEnd: ev => {
this.longPressActive = false;
console.log('Stop pressing');
}
});
}
2021-12-16 16:36:39 +01:00
load = () => {
2021-07-26 19:31:19 +01:00
this.checktimeOut = true;
2021-03-04 18:49:50 +01:00
this.getChatMembers();
}
2021-03-12 11:56:54 +01:00
2021-12-16 16:36:39 +01:00
doRefresh(ev: any) {
2021-03-04 18:49:50 +01:00
this.load();
ev.target.complete();
}
2021-07-23 14:43:51 +01:00
2022-01-13 10:26:40 +01:00
scrollToBottom = () => {
2021-03-04 18:49:50 +01:00
try {
2021-12-16 16:36:39 +01:00
if (this.scrollingOnce) {
2021-08-23 16:31:06 +01:00
this.myScrollContainer.nativeElement.scrollTop = this.myScrollContainer.nativeElement.scrollHeight;
//this.scrollingOnce = false;
}
2021-12-16 16:36:39 +01:00
} catch (err) { }
2021-08-23 16:31:06 +01:00
}
2022-01-14 14:50:47 +01:00
scrollToBottomClicked = () => {
console.log('scroll')
try {
this.myScrollContainer.nativeElement.scrollTop = this.myScrollContainer.nativeElement.scrollHeight;
//this.scrollingOnce = false;
2021-12-16 16:36:39 +01:00
} catch (err) { }
}
2021-08-23 16:31:06 +01:00
ngAfterViewInit() {
this.scrollChangeCallback = () => this.onContentScrolled(event);
window.addEventListener('scroll', this.scrollChangeCallback, true);
}
2021-12-16 16:36:39 +01:00
onContentScrolled(e) {
2021-08-23 16:31:06 +01:00
this.startPosition = e.srcElement.scrollTop;
let scroll = e.srcElement.scrollTop;
let windowHeight = e.srcElement.scrollHeight;
let containerHeight = windowHeight - e.srcElement.clientHeight;
2021-08-23 16:31:06 +01:00
if (scroll > this.currentPosition) {
//alert('BOTTOM');
} else {
//alert('UP');
this.scrollingOnce = false;
2021-07-12 11:13:29 +01:00
}
2021-12-16 16:36:39 +01:00
if ((containerHeight - 100) > scroll) {
this.scrollToBottomBtn = true;
}
2021-12-16 16:36:39 +01:00
else {
this.scrollToBottomBtn = false;
}
2021-08-23 16:31:06 +01:00
this.currentPosition = scroll;
}
ngOnDestroy() {
this.checktimeOut = false;
window.removeEventListener('scroll', this.scrollChangeCallback, true);
2021-07-26 09:44:11 +01:00
}
2021-07-23 14:43:51 +01:00
2021-12-16 16:36:39 +01:00
openBookMeetingComponent() {
2021-08-20 11:58:28 +01:00
let data = {
roomId: this.roomId,
members: this.members
}
this.openNewEventPage.emit(data);
}
2021-12-16 16:36:39 +01:00
showDateDuration(start: any) {
2021-09-06 16:53:58 +01:00
return this.timeService.showDateDuration(start);
}
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-03-04 18:49:50 +01:00
sendMessage() {
2022-02-04 00:22:35 +01:00
this.wsChatMethodsService.getDmRoom(this.roomId).send({})
2021-03-04 18:49:50 +01:00
}
2021-07-23 14:43:51 +01:00
2022-02-10 18:07:06 +01:00
deleteMessage(msgId: string) {
const room = this.wsChatMethodsService.getDmRoom(this.roomId)
2022-01-28 15:31:52 +01:00
this.alertService.confirmDeleteMessage(msgId, room);
2021-09-28 15:23:51 +01:00
}
2022-01-20 14:31:49 +01:00
async viewDocument(msg: any, url?: string) {
if (msg.file.type == "application/img") {
2022-02-03 21:01:53 +01:00
let response: any = await this.AttachmentsService.getFile(msg.file.guid).toPromise();
2021-12-07 10:59:12 +01:00
console.log(response);
2021-12-14 14:58:34 +01:00
alert(response);
2021-07-26 10:52:14 +01:00
2021-12-07 10:59:12 +01:00
//this.openPreview(msg);
2021-12-06 16:00:57 +01:00
}
2021-12-16 16:36:39 +01:00
else if (msg.file.type == "application/webtrix") {
this.openViewDocumentModal(msg.file);
}
else {
let fullUrl;
2022-01-05 21:27:26 +01:00
fullUrl = "https://gabinetedigitalchat.dyndns.info" + url;
2021-12-16 16:36:39 +01:00
//fullUrl = "http://www.africau.edu/images/default/sample.pdf";
this.frameUrl = fullUrl;
2022-02-03 21:01:53 +01:00
2021-12-16 16:36:39 +01:00
this.chatService.getDocumentDetails(fullUrl);
}
2021-09-21 14:05:59 +01:00
}
2022-01-28 19:09:37 +01:00
2021-12-16 16:36:39 +01:00
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: ''
}
}
let doc = {
2021-12-16 16:36:39 +01:00
"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
}
const modal = await this.modalController.create({
component: ViewDocumentPage,
componentProps: {
2021-10-09 20:24:34 +01:00
trustedUrl: '',
file: {
title: file.Assunto,
url: '',
title_link: '',
},
Document: doc,
applicationId: file.ApplicationId,
docId: file.DocId,
folderId: '',
task: task
},
2021-10-09 20:24:34 +01:00
cssClass: 'modal modal-desktop'
});
await modal.present();
}
2021-08-24 14:07:27 +01:00
getChatMembers() {
2021-03-12 11:56:54 +01:00
console.log(this.roomId);
2021-07-23 14:43:51 +01:00
2021-07-26 12:12:59 +01:00
//this.showLoader = true;
2021-12-16 16:36:39 +01:00
this.chatService.getMembers(this.roomId).subscribe(res => {
2021-08-20 11:58:28 +01:00
this.members = res['members'];
2021-03-04 18:49:50 +01:00
this.dmUsers = res['members'].filter(data => data.username != this.loggedUser.me.username)
console.log(res);
console.log(this.dmUsers);
this.showLoader = false;
});
}
async openMessagesOptions(ev: any) {
const popover = await this.popoverController.create({
component: MessagesOptionsPage,
componentProps: {
roomId: this.dm._id,
},
cssClass: 'messages-options',
event: ev,
translucent: true,
});
return await popover.present();
}
2021-12-16 16:36:39 +01:00
async addContacts() {
2021-03-04 18:49:50 +01:00
const modal = await this.modalController.create({
component: ContactsPage,
2021-07-23 14:43:51 +01:00
componentProps: {},
2021-03-04 18:49:50 +01:00
cssClass: 'contacts',
backdropDismiss: false
});
await modal.present();
modal.onDidDismiss();
}
2021-12-16 16:36:39 +01:00
openSendMessageOptions(ev?: any) {
if (window.innerWidth < 701) {
console.log('mobile');
this.openChatOptions(ev);
}
2021-12-16 16:36:39 +01:00
else {
console.log('desktop');
this._openChatOptions();
}
}
2021-03-04 18:49:50 +01:00
async openChatOptions(ev: any) {
const popover = await this.popoverController.create({
component: ChatOptionsPopoverPage,
cssClass: 'chat-options-popover',
event: ev,
translucent: true
});
return await popover.present();
}
2021-03-18 09:25:59 +01:00
async _openMessagesOptions() {
const enterAnimation = (baseEl: any) => {
const backdropAnimation = this.animationController.create()
.addElement(baseEl.querySelector('ion-backdrop')!)
.fromTo('opacity', '0.01', 'var(--backdrop-opacity)');
const wrapperAnimation = this.animationController.create()
.addElement(baseEl.querySelector('.modal-wrapper')!)
.keyframes([
{ offset: 0, opacity: '1', right: '-100%' },
{ offset: 1, opacity: '1', right: '0px' }
]);
return this.animationController.create()
.addElement(baseEl)
.easing('ease-out')
.duration(500)
.addAnimation([backdropAnimation, wrapperAnimation]);
}
const leaveAnimation = (baseEl: any) => {
return enterAnimation(baseEl).direction('reverse');
}
2021-07-23 14:43:51 +01:00
2021-03-18 09:25:59 +01:00
/* const popover = await this.popoverController.create({
component: MessagesOptionsPage,
componentProps: {
roomId: this.dm._id,
},
cssClass: 'messages-options',
event: ev,
translucent: true,
});
return await popover.present(); */
const modal = await this.modalController.create({
enterAnimation,
leaveAnimation,
component: MessagesOptionsPage,
cssClass: 'model profile-modal search-submodal',
componentProps: {
roomId: this.roomId,
}
});
return await modal.present();
}
2021-07-23 14:43:51 +01:00
2022-02-09 13:59:41 +01:00
async takePictureMobile() {
const roomId = this.roomId
const file = await Camera.getPhoto({
quality: 90,
// allowEditing: true,
resultType: CameraResultType.Base64,
source: CameraSource.Camera
});
console.log('ADDFILECHAT', file)
//const imageData = await this.fileToBase64Service.convert(file)
//console.log('ADDFILECHAT', imageData)
const response = await fetch('data:image/jpeg;base64,'+ file.base64String!);
const blob = await response.blob();
const formData = new FormData();
formData.append("blobFile", blob);
2022-02-11 15:08:27 +01:00
2022-02-09 13:59:41 +01:00
this.wsChatMethodsService.getDmRoom(roomId).send({
file: {
"type": "application/img",
"guid": '',
},
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
async takePicture() {
2021-10-07 15:30:36 +01:00
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();
const { capturedImage, capturedImageTitle} = await this.fileService.loadFileData(lastphoto);
2022-02-07 17:55:00 +01:00
const base64 = await fetch(capturedImage);
2022-02-09 13:59:41 +01:00
console.log('imsge take picture', image)
2022-02-07 17:55:00 +01:00
const blob = await base64.blob();
const formData = new FormData();
formData.append("blobFile", blob);
2022-02-03 21:01:53 +01:00
2022-02-07 20:18:48 +01:00
console.log('formData', formData)
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",
2022-02-08 17:44:15 +01:00
"guid": ''
2022-02-04 00:22:35 +01:00
},
2022-02-07 20:18:48 +01:00
temporaryData: formData,
2022-02-04 00:22:35 +01:00
attachments: [{
2022-02-04 00:54:41 +01:00
"title": capturedImageTitle ,
2022-02-07 20:52:07 +01:00
"image_url": capturedImage,
2022-02-04 00:54:41 +01:00
"text": "description",
2022-02-04 00:22:35 +01:00
"title_link_download": false,
}]
})
}
2022-02-11 15:08:27 +01:00
2022-02-03 21:01:53 +01:00
async addImage() {
2022-02-09 13:59:41 +01:00
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 addFile() {
this.addFileToChat(['.doc', '.docx', '.pdf'])
}
2022-02-03 21:01:53 +01:00
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,
2022-02-03 21:01:53 +01:00
"title_link_download": true,
2022-02-04 08:00:10 +01:00
"type": "webtrix",
"text": res.data.selected.DocTypeDesc,
"thumb_url": "https://static.ichimura.ed.jp/uploads/2017/10/pdf-icon.png",
2022-02-07 17:55:00 +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-03 21:01:53 +01:00
2022-02-09 13:59:41 +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)
const response = await fetch('data:image/jpeg;base64,'+ file.base64String!);
const blob = await response.blob();
const formData = new FormData();
formData.append("blobFile", blob);
2022-02-11 15:08:27 +01:00
2022-02-09 13:59:41 +01:00
this.wsChatMethodsService.getDmRoom(roomId).send({
file: {
"type": "application/img",
2022-02-09 14:39:59 +01:00
"guid": ''
2022-02-09 13:59:41 +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-11 15:08:27 +01:00
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-10 19:47:16 +01:00
console.log('Add file', file)
/* const imageData = await this.fileToBase64Service.convert(file).then((filee) => {
console.log('Add file', filee)
}) */
const blob = new Blob([file],{type: file.type})
console.log('Add file', blob)
2022-02-11 15:08:27 +01:00
2022-02-03 21:01:53 +01:00
const formData = new FormData();
2022-02-10 19:47:16 +01:00
formData.append("blobFile", blob);
2022-02-11 15:08:27 +01:00
2022-02-07 17:55:00 +01:00
this.wsChatMethodsService.getDmRoom(roomId).send({
2022-02-04 00:22:35 +01:00
file: {
2022-02-10 19:47:16 +01:00
"type": file.type,
2022-02-04 00:22:35 +01:00
"guid": '',
},
attachments: [{
2022-02-04 00:54:41 +01:00
"title": file.name ,
2022-02-07 20:35:52 +01:00
"name": file.name ,
// "text": "description",
2022-02-10 19:47:16 +01:00
"image_url": file, // rocketchat
2022-02-04 00:22:35 +01:00
"title_link_download": false,
2022-02-07 20:18:48 +01:00
}],
temporaryData: formData
2022-02-04 00:22:35 +01:00
})
2022-02-07 20:35:52 +01:00
}
2022-02-11 15:08:27 +01:00
2022-02-03 21:01:53 +01:00
2021-12-16 16:36:39 +01:00
bookMeeting() {
let data = {
roomId: this.roomId,
members: this.members
}
this.openNewEventPage.emit(data);
}
2022-02-04 00:22:35 +01:00
chatsend() {
2022-02-03 21:01:53 +01:00
}
async _openChatOptions() {
2022-02-03 21:01:53 +01:00
const roomId = this.roomId;
const enterAnimation = (baseEl: any) => {
const backdropAnimation = this.animationController.create()
.addElement(baseEl.querySelector('ion-backdrop')!)
.fromTo('opacity', '0.01', 'var(--backdrop-opacity)');
const wrapperAnimation = this.animationController.create()
.addElement(baseEl.querySelector('.modal-wrapper')!)
.keyframes([
{ offset: 0, opacity: '1', right: '-100%' },
{ offset: 1, opacity: '1', right: '0px' }
]);
return this.animationController.create()
.addElement(baseEl)
.easing('ease-out')
.duration(500)
.addAnimation([backdropAnimation, wrapperAnimation]);
}
const leaveAnimation = (baseEl: any) => {
return enterAnimation(baseEl).direction('reverse');
}
2021-07-23 14:43:51 +01:00
const modal = await this.modalController.create({
enterAnimation,
leaveAnimation,
2021-08-18 18:58:02 +01:00
component: ChatOptionsFeaturesPage,
cssClass: 'model profile-modal search-submodal',
componentProps: {
roomId: this.roomId,
2021-08-20 11:58:28 +01:00
members: this.members,
}
});
2021-08-20 11:58:28 +01:00
await modal.present();
2022-02-03 21:01:53 +01:00
modal.onDidDismiss().then( async (res) => {
2021-08-20 11:58:28 +01:00
console.log(res['data']);
2022-02-11 15:08:27 +01:00
2022-02-03 21:01:53 +01:00
2021-12-16 16:36:39 +01:00
if (res['data'] == 'meeting') {
2021-08-20 11:58:28 +01:00
//this.closeAllDesktopComponents.emit();
let data = {
roomId: this.roomId,
members: this.members
}
this.openNewEventPage.emit(data);
}
2021-12-16 16:36:39 +01:00
else if (res['data'] == 'take-picture') {
2022-02-03 21:01:53 +01:00
2022-02-09 13:59:41 +01:00
this.takePictureMobile()
2022-02-03 21:01:53 +01:00
2021-09-23 12:13:20 +01:00
}
2021-12-16 16:36:39 +01:00
else if (res['data'] == 'add-picture') {
2022-02-03 21:01:53 +01:00
this.addImage()
2021-09-21 14:05:59 +01:00
}
2021-12-16 16:36:39 +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
}
2021-12-16 16:36:39 +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()
2022-02-11 15:08:27 +01:00
2021-09-21 14:05:59 +01:00
this.showLoader = false;
}
2021-08-20 11:58:28 +01:00
});
}
2021-09-23 12:13:20 +01:00
2021-07-26 10:52:14 +01:00
2022-01-20 15:33:55 +01:00
downloadFileMsg(msg: MessageService) {
2021-12-23 07:40:01 +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-23 07:40:01 +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-28 15:31:52 +01:00
2022-01-20 15:33:55 +01:00
msg.file = {
guid: msg.file.guid,
image_url: this.downloadFile,
type: msg.file.type
}
2021-12-23 07:40:01 +01:00
2022-01-20 14:31:49 +01:00
await this.storage.set(msg.file.guid, this.downloadFile).then(() => {
console.log('IMAGE SAVED')
});
2021-12-23 07:40:01 +01:00
}
});
}
}
2022-02-10 19:47:16 +01:00
pdfPreviwe() {
const options: DocumentViewerOptions = {
title: 'My App'
};
DocumentViewer.viewDocument
}
2021-11-22 13:53:37 +01:00
async openPreview(msg) {
2022-02-11 15:08:27 +01:00
console.log(msg);
2022-01-20 15:33:55 +01:00
2022-02-11 15:08:27 +01:00
if (msg.attachments[0].image_url === null || msg.attachments[0].image_url === '' ) {
2022-01-12 17:02:41 +01:00
this.downloadFileMsg(msg)
2022-01-20 14:31:49 +01:00
2022-01-12 17:02:41 +01:00
} else {
2021-12-23 07:40:01 +01:00
const modal = await this.modalController.create({
component: ViewMediaPage,
cssClass: 'modal modal-desktop',
componentProps: {
2022-02-11 15:08:27 +01:00
image: msg.attachments[0].image_url,
2021-12-23 07:40:01 +01:00
username: msg.u.name,
_updatedAt: msg._updatedAt
}
});
modal.present();
}
2022-01-05 21:27:26 +01:00
2021-11-22 13:53:37 +01:00
}
2022-02-16 15:52:59 +01:00
testEditMessage(msg:MessageService) {
msg.receptorReceive()
// alert('cool!')
}
2021-03-04 18:49:50 +01:00
}
2021-03-12 11:56:54 +01:00
2021-11-22 13:53:37 +01:00