2021-08-23 16:31:06 +01:00
|
|
|
import { AfterViewChecked, AfterViewInit, Component, ElementRef, OnDestroy, OnInit, ViewChild } from '@angular/core';
|
2021-07-27 00:21:30 +01:00
|
|
|
import {ActivatedRoute, Router} from '@angular/router'
|
2021-09-30 08:43:49 +01:00
|
|
|
import { GestureController, Gesture, ModalController, NavParams, PopoverController } from '@ionic/angular';
|
2021-09-01 17:14:57 +01:00
|
|
|
import { map } from 'rxjs/operators';
|
2021-10-05 16:29:33 +01:00
|
|
|
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';
|
|
|
|
|
import { SearchDocumentDetails, SearchFolderDetails } from 'src/app/models/search-document';
|
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-09-30 08:43:49 +01:00
|
|
|
|
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;
|
2021-09-30 08:43:49 +01:00
|
|
|
/* @ViewChild('messageContainer') messageContainer: ElementRef; */
|
|
|
|
|
@ViewChild('rectangle') private rectangle: ElementRef;
|
2021-01-13 10:02:30 +01:00
|
|
|
|
|
|
|
|
loggedUser: any;
|
2020-12-30 11:13:50 +01:00
|
|
|
|
2021-01-04 16:03:41 +01:00
|
|
|
message = '';
|
2021-01-13 10:02:30 +01:00
|
|
|
messages:any;
|
|
|
|
|
userPresence='';
|
|
|
|
|
dmUsers:any;
|
2021-03-12 11:56:54 +01:00
|
|
|
roomId:string;
|
2021-07-23 14:43:51 +01:00
|
|
|
el:any;
|
2021-08-18 18:58:02 +01:00
|
|
|
members:any;
|
2021-08-23 16:31:06 +01:00
|
|
|
scrollingOnce:boolean = true;
|
2021-07-23 14:43:51 +01:00
|
|
|
|
2021-08-24 14:07: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[] = [];
|
2021-09-30 08:43:49 +01:00
|
|
|
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;
|
|
|
|
|
|
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,
|
2021-09-30 08:43:49 +01:00
|
|
|
private gestureController: GestureController,
|
2021-10-09 16:41:18 +01:00
|
|
|
private processes: ProcessesService,
|
2021-10-23 09:53:21 +01:00
|
|
|
public ThemeService: ThemeService
|
2021-07-23 14:43:51 +01:00
|
|
|
) {
|
2021-07-27 00:21:30 +01:00
|
|
|
/* this.activatedRoute.paramMap.subscribe(params => {
|
|
|
|
|
if(params["params"].SerialNumber) {
|
|
|
|
|
this.roomId = params["params"].roomId;
|
|
|
|
|
}
|
|
|
|
|
}); */
|
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-09-03 17:02:42 +01:00
|
|
|
|
|
|
|
|
window.onresize = (event) => {
|
|
|
|
|
if( window.innerWidth > 701){
|
|
|
|
|
this.modalController.dismiss();
|
|
|
|
|
}
|
|
|
|
|
};
|
2021-01-13 10:02:30 +01:00
|
|
|
}
|
2020-12-30 11:13:50 +01:00
|
|
|
|
|
|
|
|
ngOnInit() {
|
2021-01-13 10:02:30 +01:00
|
|
|
|
2021-01-20 10:23:59 +01:00
|
|
|
/* setInterval(()=>{ */
|
2021-01-27 16:01:49 +01:00
|
|
|
this.load();
|
|
|
|
|
/* }, 9000); */
|
2021-07-26 09:44:11 +01:00
|
|
|
/* this.el = document.getElementById("scrollToBottom");
|
|
|
|
|
this.el.scrollTop = this.el.scrollHeight - this.el.scrollTop; */
|
2021-07-23 14:43:51 +01:00
|
|
|
|
2021-08-23 16:31:06 +01:00
|
|
|
this.setStatus('online');
|
2021-09-30 08:43:49 +01:00
|
|
|
//this.onPressingMessage();
|
|
|
|
|
|
|
|
|
|
/* setInterval(()=>{
|
|
|
|
|
const gesture = this.gestureController.create({
|
|
|
|
|
el: this.rectangle.nativeElement,
|
|
|
|
|
gestureName:'my-gesture',
|
|
|
|
|
onMove: (detail) => { this.onMove(detail); }
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
gesture.enable();
|
|
|
|
|
}, 9000); */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngAfterViewInit() {
|
|
|
|
|
this.scrollChangeCallback = () => this.onContentScrolled(event);
|
|
|
|
|
window.addEventListener('scroll', this.scrollChangeCallback, true);
|
|
|
|
|
|
2021-10-08 15:37:24 +01:00
|
|
|
// const gesture = this.gestureController.create({
|
|
|
|
|
// el: this.rectangle.nativeElement,
|
|
|
|
|
// gestureName:'long-press',
|
|
|
|
|
// onStart: () => { alert('OP') },
|
|
|
|
|
// /* onMove () => {
|
|
|
|
|
// console.log('Move');
|
|
|
|
|
// }, */
|
|
|
|
|
// onEnd: () => {
|
|
|
|
|
// console.log('ENNNNNDS');
|
|
|
|
|
// },
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
|
|
// gesture.enable();
|
2021-09-30 08:43:49 +01:00
|
|
|
}
|
|
|
|
|
|
2021-09-30 10:41:40 +01:00
|
|
|
handlePress(id?:string){
|
|
|
|
|
this.selectedMsgId = id;
|
2021-09-30 08:43:49 +01:00
|
|
|
this.showMessageOptions = true;
|
|
|
|
|
/* if(!this.showMessageOptions){
|
|
|
|
|
this.showMessageOptions = true;
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
this.showMessageOptions = false;
|
|
|
|
|
} */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handleClick(){
|
|
|
|
|
this.showMessageOptions = false;
|
2021-09-30 10:41:40 +01:00
|
|
|
this.selectedMsgId = "";
|
2021-09-30 08:43:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* onPressingMessage(){
|
|
|
|
|
const gesture = this.gestureController.create({
|
|
|
|
|
el: this.messageContainer.nativeElement,
|
|
|
|
|
gestureName: 'long-press',
|
|
|
|
|
onStart: ev =>{
|
|
|
|
|
this.longPressActive = true;
|
|
|
|
|
console.log('Pressing');
|
|
|
|
|
},
|
|
|
|
|
onEnd: ev => {
|
|
|
|
|
this.longPressActive = false;
|
|
|
|
|
console.log('Stop pressing');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
gesture.enable(true);
|
|
|
|
|
} */
|
|
|
|
|
|
|
|
|
|
deleteMessage(msgId:string){
|
|
|
|
|
let body = {
|
|
|
|
|
"roomId": this.roomId,
|
|
|
|
|
"msgId": msgId,
|
|
|
|
|
"asUser": false,
|
|
|
|
|
}
|
2021-09-30 10:41:40 +01:00
|
|
|
if(msgId){
|
|
|
|
|
this.alertService.confirmDeleteMessage(body);
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
this.toastService.badRequest('Não foi possível apagar');
|
|
|
|
|
}
|
|
|
|
|
this.showMessageOptions = false;
|
|
|
|
|
this.selectedMsgId = "";
|
2021-08-23 16:31:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setStatus(status:string){
|
|
|
|
|
let body = {
|
|
|
|
|
message: '',
|
|
|
|
|
status: status,
|
|
|
|
|
}
|
|
|
|
|
this.chatService.setUserStatus(body).subscribe(res => {
|
|
|
|
|
console.log(res);
|
|
|
|
|
})
|
2021-01-13 10:02:30 +01:00
|
|
|
}
|
2021-04-13 14:14:55 +01:00
|
|
|
|
|
|
|
|
notImplemented(){
|
|
|
|
|
this.alertService.presentAlert('Funcionalidade em desenvolvimento');
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-12 11:56:54 +01:00
|
|
|
close(){
|
|
|
|
|
this.modalController.dismiss();
|
|
|
|
|
}
|
2021-07-26 09:55:57 +01:00
|
|
|
|
2021-01-27 16:01:49 +01:00
|
|
|
load(){
|
2021-07-26 19:31:19 +01:00
|
|
|
this.serverLongPull();
|
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
|
|
|
|
2021-01-27 16:01:49 +01:00
|
|
|
doRefresh(ev:any){
|
|
|
|
|
this.load();
|
|
|
|
|
ev.target.complete();
|
|
|
|
|
}
|
2021-07-23 14:43:51 +01:00
|
|
|
|
|
|
|
|
scrollToBottom(): void {
|
2021-01-13 10:02:30 +01:00
|
|
|
try {
|
2021-08-23 16:31:06 +01:00
|
|
|
if(this.scrollingOnce){
|
|
|
|
|
this.myScrollContainer.nativeElement.scrollTop = this.myScrollContainer.nativeElement.scrollHeight;
|
|
|
|
|
//this.scrollingOnce = false;
|
|
|
|
|
}
|
2021-07-23 14:43:51 +01:00
|
|
|
} catch(err) { }
|
2021-01-13 10:02:30 +01:00
|
|
|
}
|
|
|
|
|
|
2021-09-24 15:39:25 +01:00
|
|
|
scrollToBottomClicked(): void {
|
|
|
|
|
try {
|
|
|
|
|
this.myScrollContainer.nativeElement.scrollTop = this.myScrollContainer.nativeElement.scrollHeight;
|
|
|
|
|
} catch(err) { }
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-30 08:43:49 +01:00
|
|
|
|
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;
|
|
|
|
|
}
|
2021-09-24 15:39:25 +01:00
|
|
|
if((containerHeight - 100) > scroll){
|
|
|
|
|
this.scrollToBottomBtn = true;
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
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() {
|
2021-01-13 10:02:30 +01:00
|
|
|
let body = {
|
2021-07-23 14:43:51 +01:00
|
|
|
"message":
|
|
|
|
|
{
|
|
|
|
|
"rid": this.roomId, "msg": this.message
|
2021-01-13 10:02:30 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this.chatService.sendMessage(body).subscribe(res=> {
|
2021-08-23 16:31:06 +01:00
|
|
|
//this.loadMessages();
|
|
|
|
|
this.scrollingOnce = true;
|
2021-01-13 10:02:30 +01:00
|
|
|
});
|
2021-01-13 11:05:21 +01:00
|
|
|
this.message = "";
|
2021-01-13 10:02:30 +01:00
|
|
|
}
|
2021-07-23 14:43:51 +01:00
|
|
|
|
2021-08-18 18:31:35 +01:00
|
|
|
loadMessages() {
|
2021-01-27 16:01:49 +01:00
|
|
|
this.showLoader = true;
|
2021-09-21 14:05:59 +01:00
|
|
|
const roomId = this.roomId;
|
2021-09-01 17:14:57 +01:00
|
|
|
|
2021-03-11 16:21:09 +01:00
|
|
|
this.chatService.getRoomMessages(this.roomId).subscribe(res => {
|
2021-01-14 16:51:16 +01:00
|
|
|
/* console.log(res); */
|
2021-01-13 10:02:30 +01:00
|
|
|
this.messages = res['messages'].reverse();
|
2021-08-24 14:07:27 +01:00
|
|
|
this.chatMessageStore.add(roomId, this.messages)
|
2021-01-27 12:45:48 +01:00
|
|
|
console.log(this.messages);
|
2021-02-11 10:40:12 +01:00
|
|
|
this.showLoader = false;
|
2021-01-13 10:02:30 +01:00
|
|
|
})
|
|
|
|
|
}
|
2021-09-21 14:05:59 +01:00
|
|
|
|
2021-10-09 20:55:05 +01:00
|
|
|
viewDocument(file:any, url?:string){
|
2021-10-09 16:41:18 +01:00
|
|
|
console.log(file);
|
|
|
|
|
|
2021-10-09 20:55:05 +01:00
|
|
|
if(file.type == "application/webtrix") {
|
|
|
|
|
this.openViewDocumentModal(file);
|
2021-10-05 16:29:33 +01:00
|
|
|
}
|
|
|
|
|
else{
|
2021-10-09 20:55:05 +01:00
|
|
|
let fullUrl = "https://www.tabularium.pt" + url;
|
|
|
|
|
this.fileService.viewDocumentByUrl(fullUrl);
|
2021-10-05 16:29:33 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-09 16:41:18 +01:00
|
|
|
docIndex(index: number){
|
|
|
|
|
this.dicIndex = index
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-05 16:29:33 +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: ''
|
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 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-05 16:29:33 +01:00
|
|
|
});
|
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;
|
2021-03-11 16:21:09 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2021-08-20 17:00:48 +01:00
|
|
|
showDateDuration(start:any){
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
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 );
|
|
|
|
|
|
|
|
|
|
if(totalDays == 0){
|
|
|
|
|
if(start.getDate() == new Date().getDate()){
|
|
|
|
|
let time = start.getHours() + ":" + this.addZero(start.getUTCMinutes());
|
|
|
|
|
return time;
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
return 'Ontem';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
let date = start.getDate() + "/" + (start.getMonth()+1) + "/" + start.getFullYear();
|
|
|
|
|
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(){
|
|
|
|
|
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)=>{
|
|
|
|
|
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){
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-18 18:58:02 +01:00
|
|
|
async openChatOptions(ev?: any) {
|
2021-10-07 15:30:36 +01:00
|
|
|
const roomId = this.roomId
|
2021-08-18 18:58:02 +01:00
|
|
|
console.log(this.members);
|
|
|
|
|
|
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();
|
|
|
|
|
popover.onDidDismiss().then((res)=>{
|
|
|
|
|
console.log(res['data']);
|
|
|
|
|
if(res['data'] == 'meeting'){
|
|
|
|
|
this.bookMeeting();
|
|
|
|
|
}
|
|
|
|
|
else if(res['data'] == 'take-picture'){
|
2021-10-07 15:30:36 +01:00
|
|
|
this.fileService.addCameraPictureToChat(roomId);
|
2021-09-21 14:05:59 +01:00
|
|
|
//this.loadPicture();
|
|
|
|
|
}
|
|
|
|
|
else if(res['data'] == 'add-picture'){
|
2021-10-08 15:37:24 +01:00
|
|
|
this.fileService.addPictureToChatMobile(roomId);
|
2021-09-21 14:05:59 +01:00
|
|
|
//this.loadPicture();
|
|
|
|
|
}
|
|
|
|
|
else if(res['data'] == 'add-document'){
|
|
|
|
|
this.fileService.addDocumentToChat(this.roomId);
|
|
|
|
|
//this.loadDocument();
|
|
|
|
|
}
|
|
|
|
|
else if(res['data'] == 'documentoGestaoDocumental'){
|
|
|
|
|
|
|
|
|
|
this.fileService.addDocGestaoDocumentalToChat(this.roomId);
|
|
|
|
|
//this.addDocGestaoDocumental();
|
|
|
|
|
}
|
2021-09-23 12:37:30 +01:00
|
|
|
this.loadMessages();
|
2021-09-21 14:05:59 +01:00
|
|
|
|
|
|
|
|
});
|
2020-12-30 11:13:50 +01:00
|
|
|
}
|
|
|
|
|
|
2021-08-18 18:31:35 +01:00
|
|
|
async serverLongPull() {
|
2021-08-24 14:07:27 +01:00
|
|
|
|
|
|
|
|
const roomId = this.roomId
|
2021-09-01 17:14:57 +01:00
|
|
|
|
2021-09-02 13:19:50 +01:00
|
|
|
/* this.chatService.getRoomMessages(roomId).subscribe(res=>{
|
2021-09-01 17:14:57 +01:00
|
|
|
console.log(res);
|
|
|
|
|
|
2021-09-02 13:19:50 +01:00
|
|
|
}) */
|
2021-09-01 17:14:57 +01:00
|
|
|
|
|
|
|
|
|
2021-09-02 13:19:50 +01:00
|
|
|
this.chatService.getRoomMessages(roomId).subscribe(async res => {
|
2021-09-07 12:09:01 +01:00
|
|
|
console.log("Chat message",res)
|
2021-09-01 17:14:57 +01:00
|
|
|
|
2021-07-26 19:31:19 +01:00
|
|
|
|
|
|
|
|
if (res == 502) {
|
|
|
|
|
// Connection timeout
|
2021-08-30 10:24:46 +01:00
|
|
|
// happens when the synchro was pending for too long
|
2021-07-26 19:31:19 +01:00
|
|
|
// let's reconnect
|
|
|
|
|
await this.serverLongPull();
|
2021-09-23 12:13:20 +01:00
|
|
|
}
|
|
|
|
|
else if (res != 200) {
|
2021-07-26 19:31:19 +01:00
|
|
|
// Show Error
|
|
|
|
|
//showMessage(response.statusText);
|
|
|
|
|
//this.loadMessages()
|
|
|
|
|
this.messages = res['messages'].reverse();
|
2021-08-24 14:07:27 +01:00
|
|
|
this.chatMessageStore.add(roomId, this.messages)
|
|
|
|
|
|
2021-07-26 19:31:19 +01:00
|
|
|
console.log(this.messages);
|
|
|
|
|
// Reconnect in one second
|
|
|
|
|
if(this.route.url != "/home/chat"){
|
|
|
|
|
console.log("Timer message stop")
|
|
|
|
|
} else {
|
2021-08-19 18:54:50 +01:00
|
|
|
//Check if modal is opened
|
2021-08-20 11:24:42 +01:00
|
|
|
if(document.querySelector('.isMessagesChatOpened')){
|
|
|
|
|
await new Promise(resolve => setTimeout(resolve, 5000));
|
2021-08-19 18:54:50 +01:00
|
|
|
await this.serverLongPull();
|
|
|
|
|
console.log('Timer message running')
|
|
|
|
|
}
|
2021-07-26 19:31:19 +01:00
|
|
|
}
|
2021-07-26 20:52:03 +01:00
|
|
|
|
2021-07-26 19:31:19 +01:00
|
|
|
} else {
|
|
|
|
|
// Got message
|
|
|
|
|
//let message = await response.text();
|
|
|
|
|
//this.loadMessages()
|
|
|
|
|
await this.serverLongPull();
|
|
|
|
|
}
|
2021-09-02 13:19:50 +01:00
|
|
|
});
|
2021-07-26 19:31:19 +01:00
|
|
|
}
|
|
|
|
|
|
2021-07-23 14:43:51 +01:00
|
|
|
}
|