mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-20 13:26:08 +00:00
999 lines
28 KiB
TypeScript
999 lines
28 KiB
TypeScript
import { Component, ElementRef, OnInit, ViewChild, AfterViewChecked, AfterViewInit, OnDestroy, ChangeDetectorRef, } from '@angular/core';
|
|
import { ActionSheetController, IonSlides, MenuController, ModalController, NavParams, PopoverController, Platform } from '@ionic/angular';
|
|
import { AlertService } from 'src/app/services/alert.service';
|
|
import { AuthService } from 'src/app/services/auth.service';
|
|
import { ChatService } from 'src/app/services/chat.service';
|
|
import { ChatOptionsPopoverPage } from 'src/app/shared/popover/chat-options-popover/chat-options-popover.page';
|
|
import { ChatPopoverPage } from 'src/app/shared/popover/chat-popover/chat-popover.page';
|
|
import { ContactsPage } from '../new-group/contacts/contacts.page';
|
|
import { NewGroupPage } from '../new-group/new-group.page';
|
|
import { GroupContactsPage } from './group-contacts/group-contacts.page';
|
|
import { Router } from '@angular/router'
|
|
import { EditGroupPage } from '../edit-group/edit-group.page';
|
|
import { TimeService } from 'src/app/services/functions/time.service';
|
|
import { FileLoaderService } from 'src/app/services/file/file-loader.service';
|
|
import { FileToBase64Service } from 'src/app/services/file/file-to-base64.service';
|
|
import { FileService } from 'src/app/services/functions/file.service';
|
|
import { ToastService } from 'src/app/services/toast.service';
|
|
import { environment } from 'src/environments/environment';
|
|
import { NewEventPage } from '../../agenda/new-event/new-event.page';
|
|
import { EventPerson } from 'src/app/models/eventperson.model';
|
|
import { ViewDocumentPage } from 'src/app/modals/view-document/view-document.page';
|
|
import { ThemeService } from 'src/app/services/theme.service'
|
|
import { ViewMediaPage } from 'src/app/modals/view-media/view-media.page';
|
|
import { ViewEventPage } from 'src/app/modals/view-event/view-event.page';
|
|
import { HttpEventType } from '@angular/common/http';
|
|
import { SqliteService } from 'src/app/services/sqlite.service';
|
|
import { WsChatMethodsService } from 'src/app/services/chat/ws-chat-methods.service';
|
|
import { AttachmentsService } from 'src/app/services/attachments.service';
|
|
import { FileType } from 'src/app/models/fileType';
|
|
import { Storage } from '@ionic/storage';
|
|
|
|
import { CameraService } from 'src/app/services/camera.service';
|
|
import { SearchPage } from 'src/app/pages/search/search.page';
|
|
import { ProcessesService } from 'src/app/services/processes.service';
|
|
import { VoiceRecorder, VoiceRecorderPlugin, RecordingData, GenericResponse, CurrentRecordingStatus } from 'capacitor-voice-recorder';
|
|
import { Filesystem, Directory, Encoding } from '@capacitor/filesystem';
|
|
import { DomSanitizer } from '@angular/platform-browser';
|
|
|
|
@Component({
|
|
selector: 'app-group-messages',
|
|
templateUrl: './group-messages.page.html',
|
|
styleUrls: ['./group-messages.page.scss'],
|
|
})
|
|
export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
|
|
|
|
|
|
|
showLoader: boolean;
|
|
isGroupCreated: boolean;
|
|
loggedUser: any;
|
|
|
|
room: any;
|
|
roomName: any;
|
|
members: any;
|
|
contacts: string[] = [" Ana M.", "Andre F.", "Bruno G.", "Catarina T", "Tiago"];
|
|
allUsers: any[] = [];
|
|
|
|
roomId: string;
|
|
loggedUserChat: any;
|
|
eventSelectedDate: Date = new Date();
|
|
|
|
scrollingOnce: boolean = true;
|
|
private scrollChangeCallback: () => void;
|
|
currentPosition: any;
|
|
startPosition: number;
|
|
|
|
capturedImage: any;
|
|
capturedImageTitle: any;
|
|
attendees: EventPerson[] = [];
|
|
scrollToBottomBtn = false;
|
|
|
|
longPressActive = false;
|
|
showMessageOptions = false;
|
|
selectedMsgId: string;
|
|
roomCountDownDate: any;
|
|
downloadFile: any;
|
|
|
|
@ViewChild('scrollMe') private myScrollContainer: ElementRef;
|
|
|
|
recording = false;
|
|
allowTyping = true;
|
|
storedFileNames = [];
|
|
lastAudioRecorded = '';
|
|
audioRecorded:any = "";
|
|
audioDownloaded:any = "";
|
|
durationDisplay = '';
|
|
duration = 0;
|
|
|
|
constructor(
|
|
private menu: MenuController,
|
|
private modalController: ModalController,
|
|
private actionSheetController: ActionSheetController,
|
|
public popoverController: PopoverController,
|
|
private chatService: ChatService,
|
|
private navParams: NavParams,
|
|
private authService: AuthService,
|
|
private alertService: AlertService,
|
|
private route: Router,
|
|
private timeService: TimeService,
|
|
private fileLoaderService: FileLoaderService,
|
|
private fileToBase64Service: FileToBase64Service,
|
|
private fileService: FileService,
|
|
private toastService: ToastService,
|
|
public ThemeService: ThemeService,
|
|
private changeDetectorRef: ChangeDetectorRef,
|
|
private sqlservice: SqliteService,
|
|
private platform: Platform,
|
|
public wsChatMethodsService: WsChatMethodsService,
|
|
private AttachmentsService: AttachmentsService,
|
|
private storage: Storage,
|
|
private processesService: ProcessesService,
|
|
private CameraService: CameraService,
|
|
private sanitiser: DomSanitizer,
|
|
) {
|
|
this.loggedUserChat = authService.ValidatedUserChat['data'];
|
|
this.isGroupCreated = true;
|
|
this.roomId = this.navParams.get('roomId');
|
|
window.onresize = (event) => {
|
|
if (window.innerWidth > 701) {
|
|
this.modalController.dismiss();
|
|
}
|
|
};
|
|
|
|
this.wsChatMethodsService.getGroupRoom(this.roomId).loadHistory({});
|
|
this.wsChatMethodsService.getGroupRoom(this.roomId).scrollDown = this.scrollToBottomClicked;
|
|
this.wsChatMethodsService.openRoom(this.roomId)
|
|
|
|
setTimeout(() => {
|
|
this.scrollToBottomClicked()
|
|
}, 50)
|
|
|
|
}
|
|
|
|
ngOnInit() {
|
|
console.log(this.roomId);
|
|
this.loggedUser = this.loggedUserChat;
|
|
this.getRoomInfo();
|
|
this.scrollToBottom();
|
|
this.serverLongPull();
|
|
this.setStatus('online');
|
|
this.getChatMembers();
|
|
|
|
this.getRoomMessageDB(this.roomId);
|
|
this.wsChatMethodsService.getUserOfRoom(this.roomId).then((value) => {
|
|
console.log('MEMBER', value)
|
|
})
|
|
VoiceRecorder.requestAudioRecordingPermission();
|
|
//this.loadFiles();
|
|
}
|
|
|
|
setStatus(status: string) {
|
|
let body = {
|
|
message: '',
|
|
status: status,
|
|
}
|
|
this.chatService.setUserStatus(body).subscribe(res => {
|
|
console.log(res);
|
|
})
|
|
}
|
|
|
|
deleteMessage(msgId: string) {
|
|
const room = this.wsChatMethodsService.getGroupRoom(this.roomId)
|
|
this.alertService.confirmDeleteMessage(msgId, room);
|
|
}
|
|
|
|
ngAfterViewInit() {
|
|
this.scrollChangeCallback = () => this.onContentScrolled(event);
|
|
window.addEventListener('scroll', this.scrollChangeCallback, true);
|
|
this.roomCountDownDate = this.timeService.countDownDate(this.room.customFields.countDownDate, this.room._id);
|
|
}
|
|
|
|
handlePress(id?: string) {
|
|
this.selectedMsgId = id;
|
|
this.showMessageOptions = true;
|
|
}
|
|
|
|
handleClick() {
|
|
this.showMessageOptions = false;
|
|
this.selectedMsgId = "";
|
|
}
|
|
|
|
onContentScrolled(e) {
|
|
this.startPosition = e.srcElement.scrollTop;
|
|
let scroll = e.srcElement.scrollTop;
|
|
let windowHeight = e.srcElement.scrollHeight;
|
|
let containerHeight = windowHeight - e.srcElement.clientHeight;
|
|
|
|
if (scroll > this.currentPosition) {
|
|
//alert('BOTTOM');
|
|
} else {
|
|
//alert('UP');
|
|
this.scrollingOnce = false;
|
|
}
|
|
if ((containerHeight - 100) > scroll) {
|
|
this.scrollToBottomBtn = true;
|
|
}
|
|
else {
|
|
this.scrollToBottomBtn = false;
|
|
}
|
|
this.currentPosition = scroll;
|
|
}
|
|
|
|
calculateDuration() {
|
|
if (!this.recording) {
|
|
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');
|
|
this.durationDisplay = `${minutes}:${seconds}`;
|
|
|
|
setTimeout(() => {
|
|
this.calculateDuration();
|
|
}, 1000)
|
|
}
|
|
|
|
async getFile(fileName?:any){
|
|
const audioFile = await Filesystem.readFile({
|
|
path: fileName,
|
|
directory: Directory.Data
|
|
})
|
|
//console.log(audioFile);
|
|
const base64sound = audioFile.data;
|
|
|
|
//Converting base64 to blob
|
|
const base64 = await fetch(base64sound);
|
|
//console.log(base64);
|
|
|
|
const base64Response = await fetch(`data:audio/ogg;base64,${base64sound}`);
|
|
//console.log(base64Response);
|
|
|
|
this.audioRecorded = base64Response.url;
|
|
|
|
console.log(this.audioRecorded);
|
|
|
|
}
|
|
|
|
async loadFiles() {
|
|
|
|
this.storage.get('fileName').then((fileName) => {
|
|
this.lastAudioRecorded = fileName;
|
|
})
|
|
|
|
this.storage.get('recordData').then((recordData) => {
|
|
console.log(recordData);
|
|
if(recordData.value.recordDataBase64.includes('data:audio')){
|
|
this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(recordData.value.recordDataBase64);
|
|
}
|
|
else{
|
|
this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(`data:${recordData.value.mimeType};base64,${recordData.value.recordDataBase64}`);
|
|
}
|
|
});
|
|
}
|
|
|
|
startRecording() {
|
|
console.log('Recording');
|
|
|
|
if (this.recording) {
|
|
return;
|
|
}
|
|
this.recording = true;
|
|
VoiceRecorder.startRecording();
|
|
this.calculateDuration();
|
|
}
|
|
|
|
stopRecording() {
|
|
this.deleteRecording();
|
|
this.allowTyping = false;
|
|
console.log('Stop');
|
|
if (!this.recording) {
|
|
return;
|
|
}
|
|
this.recording = false;
|
|
VoiceRecorder.stopRecording().then(async (result: RecordingData) => {
|
|
console.log(result);
|
|
this.recording = false;
|
|
if (result.value && result.value.recordDataBase64) {
|
|
const recordData = result.value.recordDataBase64;
|
|
//console.log(recordData);
|
|
const fileName = new Date().getTime() + ".mp3";
|
|
//Save file
|
|
this.storage.set('fileName',fileName);
|
|
this.storage.set('recordData',result).then(() => {
|
|
console.log('Audio recorded saved');
|
|
})
|
|
}
|
|
})
|
|
setTimeout(async () => {
|
|
this.loadFiles();
|
|
}, 1000);
|
|
}
|
|
|
|
async deleteRecording(){
|
|
this.storage.remove('fileName');
|
|
this.storage.remove('recordData');
|
|
|
|
this.allowTyping = true;
|
|
this.lastAudioRecorded = '';
|
|
this.loadFiles();
|
|
}
|
|
|
|
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);
|
|
});
|
|
}
|
|
|
|
ngOnDestroy() {
|
|
window.removeEventListener('scroll', this.scrollChangeCallback, true);
|
|
}
|
|
|
|
scrollToBottom(): void {
|
|
try {
|
|
if (this.scrollingOnce) {
|
|
this.myScrollContainer.nativeElement.scrollTop = this.myScrollContainer.nativeElement.scrollHeight;
|
|
//this.scrollingOnce = false;
|
|
}
|
|
} catch (err) { }
|
|
}
|
|
|
|
scrollToBottomClicked = () => {
|
|
try {
|
|
this.myScrollContainer.nativeElement.scrollTop = this.myScrollContainer.nativeElement.scrollHeight;
|
|
} catch (err) { }
|
|
}
|
|
|
|
getRoomInfo() {
|
|
this.showLoader = true;
|
|
this.chatService.getRoomInfo(this.roomId).subscribe(room => {
|
|
this.room = room['room'];
|
|
this.roomName = this.room.name.split('-').join(' ');
|
|
if (this.room.customFields.countDownDate) {
|
|
this.roomCountDownDate = this.timeService.countDownDateTimer(this.room.customFields.countDownDate, this.room._id);
|
|
}
|
|
this.getGroupContacts(this.room);
|
|
this.showLoader = false;
|
|
});
|
|
}
|
|
|
|
async getChatMembers() {
|
|
//return await this.chatService.getMembers(roomId).toPromise();
|
|
this.chatService.getAllUsers().subscribe(res => {
|
|
console.log(res);
|
|
|
|
this.allUsers = res['users'].filter(data => data.username != this.loggedUserChat.me.username);
|
|
console.log(this.allUsers);
|
|
});
|
|
}
|
|
|
|
/* load(){
|
|
this.getGroupContacts();
|
|
this.loadGroupMessages();
|
|
} */
|
|
|
|
close() {
|
|
this.modalController.dismiss();
|
|
this.deleteRecording();
|
|
}
|
|
|
|
doRefresh(ev: any) {
|
|
this.getRoomInfo();
|
|
ev.target.complete();
|
|
}
|
|
|
|
getGroupContacts(room: any) {
|
|
this.showLoader = true;
|
|
//If group is private call getGroupMembers
|
|
if (this.room.t === 'p') {
|
|
this.chatService.getGroupMembers(this.roomId).subscribe(res => {
|
|
console.log(res);
|
|
this.members = res['members'];
|
|
this.showLoader = false;
|
|
});
|
|
}
|
|
//Otherwise call getChannelMembers for públic groups
|
|
else {
|
|
this.chatService.getChannelMembers(this.roomId).subscribe(res => {
|
|
console.log(res);
|
|
this.members = res['members'];
|
|
this.showLoader = false;
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
showDateDuration(start: any) {
|
|
return this.timeService.showDateDuration(start);
|
|
}
|
|
countDownDate(date: any, roomId: string) {
|
|
this.roomCountDownDate = this.timeService.countDownDate(date, roomId);
|
|
return this.timeService.countDownDateTimer(date, roomId);
|
|
}
|
|
|
|
addZero(i) {
|
|
if (i < 10) {
|
|
i = "0" + i;
|
|
}
|
|
return i;
|
|
}
|
|
|
|
sendMessage() {
|
|
this.wsChatMethodsService.getGroupRoom(this.roomId).send({})
|
|
}
|
|
|
|
async sendAudio(fileName) {
|
|
|
|
const roomId = this.roomId
|
|
this.storage.get('recordData').then((recordData) => {
|
|
console.log(recordData);
|
|
if(recordData.value.recordDataBase64.includes('data:audio')){
|
|
this.audioRecorded = recordData.value.recordDataBase64;
|
|
}
|
|
else{
|
|
this.audioRecorded = `data:${recordData.value.mimeType};base64,${recordData.value.recordDataBase64}`;
|
|
}
|
|
});
|
|
|
|
//Converting base64 to blob
|
|
const base64Response = await fetch(this.audioRecorded);
|
|
const blob = await base64Response.blob();
|
|
|
|
const formData = new FormData();
|
|
formData.append("blobFile", blob);
|
|
|
|
this.wsChatMethodsService.getGroupRoom(roomId).send({
|
|
file: {
|
|
"type": "application/audio",
|
|
/* "guid": '', */
|
|
},
|
|
attachments: [{
|
|
"title": fileName ,
|
|
"title_link": this.audioRecorded,
|
|
"title_link_download": true,
|
|
"type": "file"
|
|
}],
|
|
temporaryData: formData
|
|
})
|
|
this.deleteRecording();
|
|
|
|
}
|
|
|
|
|
|
async openOptions() {
|
|
const modal = await this.popoverController.create({
|
|
component: ChatPopoverPage,
|
|
cssClass: 'chat-popover',
|
|
componentProps: {
|
|
roomId: this.roomId,
|
|
members: this.members,
|
|
},
|
|
});
|
|
await modal.present();
|
|
modal.onDidDismiss().then(res => {
|
|
if (res.data == 'leave') {
|
|
console.log('saiu do grupo');
|
|
//this.wsChatMethodsService.subscribeToRoomUpdate(this.roomId, this.room);
|
|
}
|
|
else if (res.data == 'cancel') {
|
|
console.log('cancel');
|
|
}
|
|
else if (res.data == 'edit') {
|
|
this.editGroup(this.roomId);
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
viewDocument(file: any, url?: string) {
|
|
|
|
if (file.type == "application/webtrix") {
|
|
this.openViewDocumentModal(file);
|
|
}
|
|
else {
|
|
let fullUrl = "https://www.tabularium.pt" + url;
|
|
this.fileService.viewDocumentByUrl(fullUrl);
|
|
}
|
|
}
|
|
|
|
async openViewDocumentModal(file: any) {
|
|
|
|
let task = {
|
|
serialNumber: '',
|
|
taskStartDate: '',
|
|
isEvent: true,
|
|
workflowInstanceDataFields: {
|
|
FolderID: '',
|
|
Subject: file.Assunto,
|
|
SourceSecFsID: file.ApplicationId,
|
|
SourceType: 'DOC',
|
|
SourceID: file.DocId,
|
|
DispatchNumber: ''
|
|
}
|
|
}
|
|
|
|
let doc = {
|
|
"Id": "",
|
|
"ParentId": "",
|
|
"Source": 1,
|
|
"ApplicationId": file.ApplicationId,
|
|
"CreateDate": "",
|
|
"Data": null,
|
|
"Description": "",
|
|
"Link": null,
|
|
"SourceId": file.DocId,
|
|
"SourceName": file.Assunto,
|
|
"Stakeholders": "",
|
|
}
|
|
|
|
const modal = await this.modalController.create({
|
|
component: ViewDocumentPage,
|
|
componentProps: {
|
|
trustedUrl: '',
|
|
file: {
|
|
title: file.Assunto,
|
|
url: '',
|
|
title_link: '',
|
|
},
|
|
Document: doc,
|
|
applicationId: file.ApplicationId,
|
|
docId: file.DocId,
|
|
folderId: '',
|
|
task: task
|
|
},
|
|
cssClass: 'modal modal-desktop'
|
|
});
|
|
await modal.present();
|
|
|
|
}
|
|
|
|
async bookMeeting() {
|
|
this.attendees = this.members.map((val) => {
|
|
return {
|
|
Name: val.name,
|
|
EmailAddress: val.username + "@" + environment.domain,
|
|
IsRequired: "true",
|
|
}
|
|
});
|
|
console.log(this.attendees);
|
|
this.popoverController.dismiss();
|
|
if (window.innerWidth <= 1024) {
|
|
const modal = await this.modalController.create({
|
|
component: NewEventPage,
|
|
componentProps: {
|
|
attendees: this.attendees,
|
|
},
|
|
cssClass: 'modal modal-desktop',
|
|
backdropDismiss: false
|
|
});
|
|
await modal.present();
|
|
modal.onDidDismiss().then((data) => {
|
|
if (data) {
|
|
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async takePicture() {
|
|
const roomId = this.roomId
|
|
|
|
const image = await this.CameraService.takePicture();
|
|
await this.fileService.saveImage(image)
|
|
const lastphoto: any = await this.fileService.loadFiles();
|
|
const { capturedImage, capturedImageTitle } = await this.fileService.loadFileData(lastphoto);
|
|
const base64 = await fetch(capturedImage);
|
|
const blob = await base64.blob();
|
|
const formData = new FormData();
|
|
formData.append("blobFile", blob);
|
|
|
|
this.wsChatMethodsService.getGroupRoom(roomId).send({
|
|
file: {
|
|
"type": "application/img",
|
|
"guid": ''
|
|
},
|
|
temporaryData: formData,
|
|
attachments: [{
|
|
"title": capturedImageTitle,
|
|
//"image_url": capturedImage, // rocketchat
|
|
"text": "description",
|
|
"title_link_download": false,
|
|
}]
|
|
})
|
|
|
|
}
|
|
|
|
async addImage() {
|
|
this.addFileToChat(['image/apng', 'image/jpeg', 'image/png'])
|
|
}
|
|
|
|
async addFile() {
|
|
this.addFileToChat(['.doc', '.docx', '.pdf'])
|
|
}
|
|
|
|
async addFileWebtrix() {
|
|
const modal = await this.modalController.create({
|
|
component: SearchPage,
|
|
cssClass: 'group-messages modal-desktop search-modal search-modal-to-desktop',
|
|
componentProps: {
|
|
type: 'AccoesPresidenciais & ArquivoDespachoElect',
|
|
select: true,
|
|
showSearchInput: true,
|
|
}
|
|
});
|
|
await modal.present();
|
|
modal.onDidDismiss().then(async res => {
|
|
const data = res.data;
|
|
|
|
if (data.selected) {
|
|
|
|
this.wsChatMethodsService.getGroupRoom(this.roomId).send({
|
|
file: {
|
|
"name": res.data.selected.Assunto,
|
|
"type": "application/webtrix",
|
|
"ApplicationId": res.data.selected.ApplicationType,
|
|
"DocId": res.data.selected.Id,
|
|
"Assunto": res.data.selected.Assunto,
|
|
},
|
|
attachments: [{
|
|
"title": res.data.selected.Assunto,
|
|
"description": res.data.selected.DocTypeDesc,
|
|
// "title_link": url_no_options,
|
|
"title_link_download": true,
|
|
//"thumb_url": "assets/images/webtrix-logo.png",
|
|
// "message_link": url_no_options,
|
|
"type": "webtrix",
|
|
//"thumb_url": "assets/images/webtrix-logo.png",
|
|
"text": res.data.selected.DocTypeDesc,
|
|
"thumb_url": "https://static.ichimura.ed.jp/uploads/2017/10/pdf-icon.png",
|
|
}]
|
|
})
|
|
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
async addFileToChat(types: typeof FileType[] ) {
|
|
|
|
const roomId = this.roomId
|
|
|
|
const file: any = await this.fileService.getFileFromDevice(types);
|
|
console.log('Add file', file)
|
|
/* const imageData = await this.fileToBase64Service.convert(file).then((filee) => {
|
|
console.log('Add file', filee)
|
|
}) */
|
|
const response = await fetch(file);
|
|
const blob = await response.blob();
|
|
console.log('Add file', blob)
|
|
|
|
const formData = new FormData();
|
|
formData.append("blobFile", blob);
|
|
|
|
this.wsChatMethodsService.getGroupRoom(roomId).send({
|
|
file: {
|
|
"type": file.type,
|
|
"guid": '',
|
|
},
|
|
attachments: [{
|
|
"title": file.name ,
|
|
"name": file.name ,
|
|
// "text": "description",
|
|
//"image_url": file.base64String, // rocketchat
|
|
"title_link_download": false,
|
|
}],
|
|
temporaryData: formData
|
|
})
|
|
|
|
|
|
}
|
|
|
|
async openChatOptions(ev?: any) {
|
|
console.log(this.members);
|
|
const roomId = this.roomId;
|
|
|
|
const popover = await this.popoverController.create({
|
|
component: ChatOptionsPopoverPage,
|
|
cssClass: 'chat-options-popover',
|
|
event: ev,
|
|
componentProps: {
|
|
room: this.room,
|
|
members: this.members,
|
|
eventSelectedDate: new Date(),
|
|
},
|
|
translucent: true
|
|
});
|
|
await popover.present();
|
|
await popover.onDidDismiss().then(async (res) => {
|
|
console.log(res['data']);
|
|
if (res['data'] == 'meeting') {
|
|
this.bookMeeting();
|
|
}
|
|
else if (res['data'] == 'take-picture') {
|
|
this.takePicture()
|
|
}
|
|
else if (res['data'] == 'add-picture') {
|
|
this.addImage()
|
|
|
|
}
|
|
else if (res['data'] == 'add-document') {
|
|
this.addFile()
|
|
}
|
|
else if (res['data'] == 'documentoGestaoDocumental') {
|
|
|
|
this.addFileWebtrix()
|
|
}
|
|
});
|
|
}
|
|
|
|
async addContacts() {
|
|
console.log(this.members);
|
|
|
|
const modal = await this.modalController.create({
|
|
component: GroupContactsPage,
|
|
componentProps: {
|
|
isCreated: this.isGroupCreated,
|
|
room: this.room,
|
|
members: this.members,
|
|
name: this.room.name,
|
|
},
|
|
cssClass: 'contacts',
|
|
backdropDismiss: false
|
|
});
|
|
|
|
await modal.present();
|
|
|
|
modal.onDidDismiss().then(() => {
|
|
this.getRoomInfo();
|
|
});
|
|
}
|
|
|
|
async editGroup(roomId) {
|
|
const modal = await this.modalController.create({
|
|
component: EditGroupPage,
|
|
cssClass: 'modal modal-desktop',
|
|
componentProps: {
|
|
roomId: roomId,
|
|
},
|
|
});
|
|
await modal.present();
|
|
modal.onDidDismiss().then((res) => {
|
|
console.log(res.data);
|
|
this.getRoomInfo();
|
|
//this.modalController.dismiss(res.data);
|
|
});
|
|
}
|
|
|
|
/* async actionSheet() {
|
|
const actionSheet = await this.actionSheetController.create({
|
|
cssClass: 'my-custom-class',
|
|
buttons: [{
|
|
text: 'Sair do grupo',
|
|
handler: () => {
|
|
console.log('Delete clicked');
|
|
}
|
|
}, {
|
|
text: 'Alterar nome do grupo1',
|
|
handler: () => {
|
|
console.log('Alterar nome do grupo');
|
|
this.openChangeGroupName()
|
|
}
|
|
}, {
|
|
text: 'Apagar o grupo',
|
|
handler: () => {
|
|
console.log('Play clicked');
|
|
}
|
|
},
|
|
]
|
|
});
|
|
await actionSheet.present();
|
|
}
|
|
*/
|
|
|
|
getRoomMessageDB(roomId) {
|
|
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
|
|
} else {
|
|
this.sqlservice.getAllChatMSG(roomId).then((msg: any) => {
|
|
console.log('ALL MSG DBBB', msg)
|
|
let chatmsgArray = [];
|
|
let array = []
|
|
msg.forEach(element => {
|
|
console.log('CHANNEL ELEMENT', element.channels)
|
|
|
|
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),
|
|
_updatedAt: element.UpdatedAt,
|
|
image_url: this.isJson(element.image_url)
|
|
}
|
|
|
|
chatmsgArray.push(msgChat)
|
|
});
|
|
|
|
// this.messages = chatmsgArray;
|
|
console.log('GROUP CHAT MSG FROM DB', chatmsgArray)
|
|
})
|
|
}
|
|
}
|
|
|
|
isJson(str) {
|
|
try {
|
|
JSON.parse(str);
|
|
} catch (e) {
|
|
return "";
|
|
}
|
|
return JSON.parse(str);
|
|
}
|
|
|
|
transformDataMSG(res) {
|
|
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
|
|
} else {
|
|
res.forEach(element => {
|
|
|
|
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,
|
|
_updatedAt: element._updatedAt,
|
|
/* image_url: {
|
|
name: name,
|
|
path: `${IMAGE_DIR}/${name}`,
|
|
data: `data:image/jpeg;base64,${readFile.data}`,
|
|
}, */
|
|
}
|
|
|
|
this.sqlservice.addChatMSG(chatmsg)
|
|
|
|
});
|
|
}
|
|
|
|
}
|
|
|
|
async serverLongPull() {
|
|
this.chatService.getPrivateGroupMessages(this.roomId).subscribe(async res => {
|
|
|
|
if (res == 502) {
|
|
// Connection timeout
|
|
// happens when the connection was pending for too long
|
|
// let's reconnect
|
|
await this.serverLongPull();
|
|
} else if (res != 200) {
|
|
// Show Error
|
|
//showMessage(response.statusText);
|
|
//this.loadMessages()
|
|
let msgOnly = res['messages'].filter(data => data.t != 'au');
|
|
//this.messages = msgOnly.reverse();
|
|
// console.log('MOBILE MSG ROCKET',this.messages);
|
|
this.transformDataMSG(msgOnly.reverse());
|
|
this.getRoomMessageDB(this.roomId);
|
|
// Reconnect in one second
|
|
if (this.route.url != "/home/chat") {
|
|
console.log("Timer message stop")
|
|
} else {
|
|
//Check if modal is opened
|
|
if (document.querySelector('.isGroupChatOpened')) {
|
|
await new Promise(resolve => setTimeout(resolve, 5000));
|
|
await this.serverLongPull();
|
|
console.log('Timer message running')
|
|
}
|
|
}
|
|
|
|
} else {
|
|
// Got message
|
|
//let message = await response.text();
|
|
//this.loadMessages()
|
|
await this.serverLongPull();
|
|
}
|
|
});
|
|
}
|
|
|
|
sliderOpts = {
|
|
zoom: false,
|
|
slidesPerView: 1.5,
|
|
spaceBetween: 20,
|
|
centeredSlides: true
|
|
};
|
|
zoomActive = false;
|
|
zoomScale = 1;
|
|
|
|
sliderZoomOpts = {
|
|
allowSlidePrev: false,
|
|
allowSlideNext: false,
|
|
zoom: {
|
|
maxRatio: 5
|
|
},
|
|
on: {
|
|
zoomChange: (scale, imageEl, slideEl) => {
|
|
this.zoomActive = true;
|
|
this.zoomScale = scale / 5;
|
|
this.changeDetectorRef.detectChanges();
|
|
}
|
|
}
|
|
}
|
|
|
|
async touchEnd(zoomslides: IonSlides, card) {
|
|
// Zoom back to normal
|
|
const slider = await zoomslides.getSwiper();
|
|
const zoom = slider.zoom;
|
|
zoom.out();
|
|
|
|
// Card back to normal
|
|
card.el.style['z-index'] = 9;
|
|
|
|
this.zoomActive = false;
|
|
this.changeDetectorRef.detectChanges();
|
|
}
|
|
|
|
touchStart(card) {
|
|
// Make card appear above backdrop
|
|
card.el.style['z-index'] = 11;
|
|
}
|
|
|
|
downloadFileMsg(msg) {
|
|
console.log('FILE TYPE', msg.file.type)
|
|
this.downloadFile = "";
|
|
// if (msg.file.type == "application/img") {
|
|
this.AttachmentsService.downloadFile(msg.file.guid).subscribe(async (event) => {
|
|
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) {
|
|
if (msg.file.type == "application/img") {
|
|
this.downloadFile = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), ''));
|
|
} else {
|
|
|
|
this.downloadFile = event.body;
|
|
}
|
|
|
|
msg.attachments[0] = {
|
|
image_url: this.downloadFile,
|
|
name: msg.attachments[0].name,
|
|
title: msg.attachments[0].title,
|
|
title_link_download: msg.attachments[0].title_link_download,
|
|
ts: msg.attachments[0].ts
|
|
}
|
|
this.sqlservice.updateChatMsg(msg._id, this.downloadFile);
|
|
}
|
|
});
|
|
console.log('FILE TYPE 44', this.downloadFile)
|
|
//}
|
|
}
|
|
|
|
async openPreview(msg) {
|
|
|
|
if (!msg.attachments[0].image_url ||msg.attachments[0].image_url === null || msg.attachments[0].image_url === '') {
|
|
this.downloadFileMsg(msg)
|
|
|
|
} else {
|
|
const modal = await this.modalController.create({
|
|
component: ViewMediaPage,
|
|
cssClass: 'modal modal-desktop',
|
|
componentProps: {
|
|
image: msg.attachments[0].image_url,
|
|
type: msg.file.type,
|
|
username: msg.u.name,
|
|
_updatedAt: msg._updatedAt
|
|
}
|
|
});
|
|
modal.present();
|
|
}
|
|
|
|
}
|
|
}
|
|
|