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';
|
2021-12-16 16:36:39 +01:00
|
|
|
import { HttpClient, HttpEventType, HttpHeaders } from '@angular/common/http';
|
2021-10-05 16:29:33 +01:00
|
|
|
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'
|
2021-11-22 13:53:37 +01:00
|
|
|
import { PreviewCameraPage } from 'src/app/modals/preview-camera/preview-camera.page';
|
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 { SqliteService } from 'src/app/services/sqlite.service';
|
|
|
|
|
import { StorageService } from 'src/app/services/storage.service';
|
|
|
|
|
import { Directory, Filesystem } from '@capacitor/filesystem';
|
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;
|
2021-09-30 08:43:49 +01:00
|
|
|
@ViewChild('message-item') messageContainer: ElementRef;
|
2021-03-04 18:49:50 +01:00
|
|
|
|
|
|
|
|
loggedUser: any;
|
|
|
|
|
|
|
|
|
|
message = '';
|
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;
|
2021-09-24 15:38:50 +01:00
|
|
|
mesageItemDropdownOptions: boolean = false;
|
|
|
|
|
scrollToBottomBtn = false;
|
2021-09-30 08:43:49 +01:00
|
|
|
longPressActive = false;
|
2021-10-18 17:10:33 +01:00
|
|
|
frameUrl: any;
|
2021-12-16 16:36:39 +01:00
|
|
|
downloadFile: any;
|
2021-08-20 11:24:42 +01:00
|
|
|
|
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,
|
2021-09-30 08:43:49 +01:00
|
|
|
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,
|
|
|
|
|
private storageservice: StorageService
|
2021-07-23 14:43:51 +01:00
|
|
|
) {
|
|
|
|
|
this.loggedUser = authService.ValidatedUserChat['data'];
|
|
|
|
|
|
2021-12-16 16:36:39 +01:00
|
|
|
/* this.dm = this.navParams.get('dm'); */
|
2021-03-12 11:56:54 +01:00
|
|
|
}
|
|
|
|
|
ngOnChanges(changes: SimpleChanges): void {
|
2021-10-12 10:17:56 +01:00
|
|
|
this.load();
|
2021-07-23 14:43:51 +01:00
|
|
|
|
2021-03-12 11:56:54 +01:00
|
|
|
//throw new Error('Method not implemented.');
|
2021-03-04 18:49:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
|
|
2021-07-26 09:44:11 +01:00
|
|
|
this.scrollToBottom();
|
2021-03-04 18:49:50 +01:00
|
|
|
|
|
|
|
|
/* setInterval(()=>{ */
|
2021-12-16 16:36:39 +01:00
|
|
|
this.load();
|
2021-03-04 18:49:50 +01:00
|
|
|
/* }, 9000); */
|
2021-03-12 11:56:54 +01:00
|
|
|
console.log(this.roomId);
|
2021-07-26 19:31:19 +01:00
|
|
|
console.log("Chat route", this.route.url)
|
2021-07-26 15:56:57 +01:00
|
|
|
|
2021-08-23 16:31:06 +01:00
|
|
|
this.setStatus('online');
|
2021-07-26 19:31:19 +01:00
|
|
|
}
|
|
|
|
|
|
2021-12-16 16:36:39 +01:00
|
|
|
onPressingMessage() {
|
2021-09-30 08:43:49 +01:00
|
|
|
const gesture = this.gestureController.create({
|
|
|
|
|
el: this.messageContainer.nativeElement,
|
|
|
|
|
gestureName: 'long-press',
|
2021-12-16 16:36:39 +01:00
|
|
|
onStart: ev => {
|
2021-09-30 08:43:49 +01:00
|
|
|
this.longPressActive = true;
|
|
|
|
|
console.log('Pressing');
|
|
|
|
|
},
|
|
|
|
|
onEnd: ev => {
|
|
|
|
|
this.longPressActive = false;
|
|
|
|
|
console.log('Stop pressing');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-16 16:36:39 +01:00
|
|
|
setStatus(status: string) {
|
2021-08-23 16:31:06 +01:00
|
|
|
let body = {
|
|
|
|
|
message: '',
|
|
|
|
|
status: status,
|
|
|
|
|
}
|
|
|
|
|
this.chatService.setUserStatus(body).subscribe(res => {
|
|
|
|
|
console.log(res);
|
|
|
|
|
})
|
2021-03-04 18:49:50 +01:00
|
|
|
}
|
2021-07-23 14:43:51 +01:00
|
|
|
|
2021-12-16 16:36:39 +01:00
|
|
|
notImplemented() {
|
2021-04-13 14:14:55 +01:00
|
|
|
this.alertService.presentAlert('Funcionalidade em desenvolvimento');
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-16 16:36:39 +01:00
|
|
|
load = () => {
|
2021-07-26 19:31:19 +01:00
|
|
|
this.checktimeOut = true;
|
2021-07-26 15:56:57 +01:00
|
|
|
this.serverLongPull();
|
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
|
|
|
|
2021-07-26 09:44:11 +01:00
|
|
|
scrollToBottom(): void {
|
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
|
|
|
}
|
|
|
|
|
|
2021-09-24 15:38:50 +01:00
|
|
|
scrollToBottomClicked(): void {
|
|
|
|
|
try {
|
|
|
|
|
this.myScrollContainer.nativeElement.scrollTop = this.myScrollContainer.nativeElement.scrollHeight;
|
|
|
|
|
//this.scrollingOnce = false;
|
2021-12-16 16:36:39 +01:00
|
|
|
} catch (err) { }
|
2021-09-24 15:38:50 +01:00
|
|
|
}
|
|
|
|
|
|
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;
|
2021-09-24 15:38:50 +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:38:50 +01:00
|
|
|
|
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) {
|
2021-09-24 15:38:50 +01:00
|
|
|
this.scrollToBottomBtn = true;
|
|
|
|
|
}
|
2021-12-16 16:36:39 +01:00
|
|
|
else {
|
2021-09-24 15:38:50 +01:00
|
|
|
this.scrollToBottomBtn = false;
|
|
|
|
|
}
|
2021-08-23 16:31:06 +01:00
|
|
|
this.currentPosition = scroll;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
|
this.checktimeOut = false;
|
|
|
|
|
this.setStatus('away');
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-19 09:10:38 +01:00
|
|
|
sendMessage() {
|
|
|
|
|
|
2021-10-19 09:41:06 +01:00
|
|
|
//this.synchro.$send({})
|
2021-03-04 18:49:50 +01:00
|
|
|
|
|
|
|
|
let body = {
|
2021-07-23 14:43:51 +01:00
|
|
|
"message":
|
|
|
|
|
{
|
|
|
|
|
"rid": this.roomId, "msg": this.message
|
2021-03-04 18:49:50 +01:00
|
|
|
}
|
|
|
|
|
}
|
2021-07-23 14:43:51 +01:00
|
|
|
|
2021-12-16 16:36:39 +01:00
|
|
|
this.chatService.sendMessage(body).subscribe(res => {
|
2021-08-23 16:31:06 +01:00
|
|
|
this.scrollingOnce = true;
|
2021-03-04 18:49:50 +01:00
|
|
|
});
|
|
|
|
|
this.message = "";
|
|
|
|
|
}
|
2021-07-23 14:43:51 +01:00
|
|
|
|
2021-12-16 16:36:39 +01:00
|
|
|
deleteMessage(msgId: string) {
|
2021-09-28 15:23:51 +01:00
|
|
|
let body = {
|
|
|
|
|
"roomId": this.roomId,
|
|
|
|
|
"msgId": msgId,
|
|
|
|
|
"asUser": false,
|
|
|
|
|
}
|
|
|
|
|
this.alertService.confirmDeleteMessage(body);
|
|
|
|
|
/* this.chatService.deleteMessage(body).subscribe(res=>{
|
|
|
|
|
console.log(res);
|
|
|
|
|
}); */
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-16 16:36:39 +01:00
|
|
|
|
|
|
|
|
getMessageDB() {
|
|
|
|
|
this.storageservice.get('chatmsg').then((msg) => {
|
|
|
|
|
let msgArray =[];
|
|
|
|
|
msgArray = msg;
|
|
|
|
|
msgArray.filter(data => data._id != this.roomId);
|
|
|
|
|
this.messages = msgArray.reverse();
|
|
|
|
|
console.log("MSG CHAT WEB", this.messages)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
transformData(res) {
|
|
|
|
|
let mgsArray = [];
|
|
|
|
|
res.forEach(async 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: element.file.guid,
|
|
|
|
|
path: `${IMAGE_DIR}/${element.file.guid}`,
|
|
|
|
|
data: `data:image/jpeg;base64,${readFile.data}`,
|
|
|
|
|
}, */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mgsArray.push(chatmsg)
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.storageservice.store('chatmsg',mgsArray);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loadMessages() {
|
2021-07-26 10:52:14 +01:00
|
|
|
//this.showLoader = true;
|
2021-08-24 14:07:27 +01:00
|
|
|
const roomId = this.roomId
|
2021-03-12 11:56:54 +01:00
|
|
|
this.chatService.getRoomMessages(this.roomId).subscribe(res => {
|
2021-07-26 12:12:59 +01:00
|
|
|
console.log(res);
|
2021-12-16 16:36:39 +01:00
|
|
|
this.transformData(res['messages']);
|
|
|
|
|
this.getMessageDB();
|
|
|
|
|
//this.getFileFromLakeFS();
|
|
|
|
|
/* this.messages = res['messages'].reverse();
|
|
|
|
|
this.chatMessageStore.add(roomId, this.messages) */
|
2021-08-24 14:07:27 +01:00
|
|
|
|
2021-03-04 18:49:50 +01:00
|
|
|
console.log(this.messages);
|
2021-07-26 15:56:57 +01:00
|
|
|
//this.serverLongPull(res)
|
2021-07-26 10:52:14 +01:00
|
|
|
/* this.chatService.subscribe(this.roomId).then(res => {
|
|
|
|
|
console.log("Real fake msg", res)
|
|
|
|
|
}); */
|
|
|
|
|
//this.showLoader = false;
|
2021-03-04 18:49:50 +01:00
|
|
|
})
|
|
|
|
|
}
|
2021-07-26 10:52:14 +01:00
|
|
|
|
2021-12-16 16:36:39 +01:00
|
|
|
async viewDocument(msg: any, url?: string) {
|
|
|
|
|
console.log('FILE TYPE',msg.file.type)
|
|
|
|
|
this.downloadFile = "";
|
|
|
|
|
if (msg.file.type == "application/img") {
|
|
|
|
|
this.fileService.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) {
|
|
|
|
|
this.downloadFile = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), ''));
|
|
|
|
|
console.log('FILE TYPE 44',this.downloadFile)
|
|
|
|
|
|
|
|
|
|
console.log('TRY ARRAY BUFFER NAME', name);
|
|
|
|
|
console.log('TRY ARRAY BUFFER', this.downloadFile);
|
|
|
|
|
|
|
|
|
|
await Filesystem.writeFile({
|
|
|
|
|
path: `${IMAGE_DIR}/${name}`,
|
|
|
|
|
data: this.downloadFile,
|
|
|
|
|
directory: Directory.Data
|
|
|
|
|
}).then((foo) => {
|
|
|
|
|
console.log('SAVED FILE WEB', foo )
|
|
|
|
|
}).catch((error) =>{
|
|
|
|
|
console.log('SAVED FILE WEB error ', error )
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const readFile = await Filesystem.readdir({
|
|
|
|
|
path: `${IMAGE_DIR}/${name}`,
|
|
|
|
|
directory: Directory.Data,
|
|
|
|
|
}).then((foo) => {
|
|
|
|
|
console.log('GET FILE WEB', foo )
|
|
|
|
|
});
|
|
|
|
|
|
2021-12-17 10:14:08 +01:00
|
|
|
this.storageservice.get('chatmsg').then(async (msg) => {
|
2021-12-16 16:36:39 +01:00
|
|
|
let msgArray =[];
|
|
|
|
|
msgArray = msg;
|
|
|
|
|
msgArray.filter(data => data._id != this.roomId);
|
|
|
|
|
this.messages = msgArray.reverse();
|
|
|
|
|
console.log("MSG CHAT WEB", this.messages)
|
|
|
|
|
|
|
|
|
|
let newmgsArray = [];
|
|
|
|
|
msgArray.forEach(async element => {
|
|
|
|
|
console.log('GET FILE TRANSFORM',element.file.guid )
|
2021-12-17 10:14:08 +01:00
|
|
|
try {
|
|
|
|
|
if(element.file.guid == msg.file.guid) {
|
|
|
|
|
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: this.downloadFile
|
|
|
|
|
}
|
|
|
|
|
newmgsArray.push(chatmsg)
|
2021-12-16 16:36:39 +01:00
|
|
|
}
|
2021-12-17 10:14:08 +01:00
|
|
|
} catch (error) {
|
|
|
|
|
|
2021-12-16 16:36:39 +01:00
|
|
|
}
|
|
|
|
|
});
|
2021-12-17 10:14:08 +01:00
|
|
|
await this.storageservice.remove('chatmsg');
|
|
|
|
|
await this.storageservice.store('chatmsg',newmgsArray);
|
2021-12-16 16:36:39 +01:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.getMessageDB();
|
|
|
|
|
});
|
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;
|
|
|
|
|
fullUrl = "https://www.tabularium.pt" + url;
|
|
|
|
|
//fullUrl = "http://www.africau.edu/images/default/sample.pdf";
|
|
|
|
|
|
|
|
|
|
this.frameUrl = fullUrl;
|
|
|
|
|
//this.fileService.viewDocumentByUrl(fullUrl);
|
|
|
|
|
this.chatService.getDocumentDetails(fullUrl);
|
|
|
|
|
}
|
2021-09-21 14:05:59 +01:00
|
|
|
}
|
|
|
|
|
|
2021-10-09 20:55:05 +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
|
|
|
}
|
|
|
|
|
|
2021-10-05 16:29:33 +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-05 16:29:33 +01:00
|
|
|
},
|
2021-10-09 20:24:34 +01:00
|
|
|
cssClass: 'modal modal-desktop'
|
2021-10-05 16:29:33 +01:00
|
|
|
});
|
|
|
|
|
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) {
|
2021-03-18 16:30:03 +01:00
|
|
|
console.log('mobile');
|
|
|
|
|
this.openChatOptions(ev);
|
|
|
|
|
}
|
2021-12-16 16:36:39 +01:00
|
|
|
else {
|
2021-03-18 16:30:03 +01:00
|
|
|
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
|
|
|
|
2021-03-18 16:30:03 +01:00
|
|
|
|
2021-12-16 16:36:39 +01:00
|
|
|
takePicture() {
|
2021-10-07 15:30:36 +01:00
|
|
|
const roomId = this.roomId
|
|
|
|
|
this.fileService.addCameraPictureToChat(roomId);
|
2021-10-06 17:27:49 +01:00
|
|
|
}
|
2021-12-16 16:36:39 +01:00
|
|
|
addImage() {
|
2021-12-06 16:00:57 +01:00
|
|
|
const roomId = this.roomId;
|
2021-10-07 15:30:36 +01:00
|
|
|
this.fileService.addPictureToChat(roomId);
|
2021-12-06 16:00:57 +01:00
|
|
|
//this.fileService.loadPicture();
|
|
|
|
|
//this.fileService.addPictureToChat(roomId);
|
2021-10-06 17:27:49 +01:00
|
|
|
}
|
2021-12-16 16:36:39 +01:00
|
|
|
addFile() {
|
2021-10-06 17:27:49 +01:00
|
|
|
this.fileService.addDocumentToChat(this.roomId);
|
|
|
|
|
}
|
2021-12-16 16:36:39 +01:00
|
|
|
addFileWebtrix() {
|
2021-10-06 17:27:49 +01:00
|
|
|
this.fileService.addDocGestaoDocumentalToChat(this.roomId);
|
|
|
|
|
}
|
2021-12-16 16:36:39 +01:00
|
|
|
bookMeeting() {
|
2021-10-06 17:27:49 +01:00
|
|
|
let data = {
|
|
|
|
|
roomId: this.roomId,
|
|
|
|
|
members: this.members
|
|
|
|
|
}
|
|
|
|
|
this.openNewEventPage.emit(data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-03-18 16:30:03 +01:00
|
|
|
async _openChatOptions() {
|
|
|
|
|
|
|
|
|
|
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 16:30:03 +01:00
|
|
|
const modal = await this.modalController.create({
|
|
|
|
|
enterAnimation,
|
|
|
|
|
leaveAnimation,
|
2021-08-18 18:58:02 +01:00
|
|
|
component: ChatOptionsFeaturesPage,
|
2021-03-18 16:30:03 +01:00
|
|
|
cssClass: 'model profile-modal search-submodal',
|
|
|
|
|
componentProps: {
|
|
|
|
|
roomId: this.roomId,
|
2021-08-20 11:58:28 +01:00
|
|
|
members: this.members,
|
2021-03-18 16:30:03 +01:00
|
|
|
}
|
|
|
|
|
});
|
2021-08-20 11:58:28 +01:00
|
|
|
await modal.present();
|
2021-12-16 16:36:39 +01:00
|
|
|
modal.onDidDismiss().then((res) => {
|
2021-08-20 11:58:28 +01:00
|
|
|
console.log(res['data']);
|
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') {
|
2021-09-23 12:13:20 +01:00
|
|
|
this.fileService.addCameraPictureToChat(this.roomId);
|
|
|
|
|
//this.loadPicture();
|
|
|
|
|
}
|
2021-12-16 16:36:39 +01:00
|
|
|
else if (res['data'] == 'add-picture') {
|
2021-09-21 14:05:59 +01:00
|
|
|
this.fileService.addPictureToChat(this.roomId);
|
|
|
|
|
//this.loadPicture();
|
|
|
|
|
}
|
2021-12-16 16:36:39 +01:00
|
|
|
else if (res['data'] == 'add-document') {
|
2021-09-21 14:05:59 +01:00
|
|
|
this.fileService.addDocumentToChat(this.roomId);
|
|
|
|
|
//this.loadDocument();
|
|
|
|
|
}
|
2021-12-16 16:36:39 +01:00
|
|
|
else if (res['data'] == 'documentoGestaoDocumental') {
|
2021-09-21 14:05:59 +01:00
|
|
|
|
|
|
|
|
this.fileService.addDocGestaoDocumentalToChat(this.roomId);
|
|
|
|
|
this.showLoader = false;
|
|
|
|
|
//this.addDocGestaoDocumental();
|
|
|
|
|
}
|
2021-09-23 12:37:30 +01:00
|
|
|
this.loadMessages();
|
2021-08-20 11:58:28 +01:00
|
|
|
|
|
|
|
|
});
|
2021-03-18 16:30:03 +01:00
|
|
|
}
|
|
|
|
|
|
2021-08-24 14:07:27 +01:00
|
|
|
async serverLongPull() {
|
|
|
|
|
|
2021-09-23 12:13:20 +01:00
|
|
|
const roomId = this.roomId;
|
|
|
|
|
|
2021-07-26 15:56:57 +01:00
|
|
|
this.chatService.getRoomMessages(this.roomId).subscribe(async res => {
|
2021-09-28 15:23:51 +01:00
|
|
|
//console.log(res['success']);
|
2021-07-26 15:56:57 +01:00
|
|
|
|
2021-09-23 12:13:20 +01:00
|
|
|
|
2021-12-16 16:36:39 +01:00
|
|
|
if (res['success'] == true) {
|
|
|
|
|
// Show Error
|
|
|
|
|
//showMessage(response.statusText);
|
|
|
|
|
this.loadMessages()
|
|
|
|
|
this.messages = res['messages'].reverse();
|
|
|
|
|
this.chatMessageStore.add(roomId, this.messages)
|
2021-09-23 12:13:20 +01:00
|
|
|
|
2021-12-16 16:36:39 +01:00
|
|
|
//console.log(this.messages);
|
|
|
|
|
// Reconnect in one second
|
|
|
|
|
if (this.route.url != "/home/chat") {
|
|
|
|
|
console.log("Timer message stop")
|
2021-09-23 12:13:20 +01:00
|
|
|
}
|
2021-12-16 16:36:39 +01:00
|
|
|
else {
|
|
|
|
|
if (document.querySelector('app-messages')) {
|
|
|
|
|
await new Promise(resolve => setTimeout(resolve, 5000));
|
|
|
|
|
await this.serverLongPull();
|
|
|
|
|
this.getDirectMessages.emit();
|
|
|
|
|
console.log('Timer message running')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} /* else {
|
2021-08-19 13:00:20 +01:00
|
|
|
// Got message
|
|
|
|
|
//let message = await response.text();
|
|
|
|
|
//this.loadMessages()
|
|
|
|
|
await this.serverLongPull();
|
2021-09-23 12:13:20 +01:00
|
|
|
} */
|
2021-12-16 16:36:39 +01:00
|
|
|
}, (error) => {
|
|
|
|
|
console.log(error);
|
|
|
|
|
this.serverLongPull();
|
2021-09-23 12:13:20 +01:00
|
|
|
|
2021-12-16 16:36:39 +01:00
|
|
|
});
|
|
|
|
|
} sliderOpts = {
|
2021-11-22 13:53:37 +01:00
|
|
|
zoom: false,
|
|
|
|
|
slidesPerView: 1.5,
|
|
|
|
|
spaceBetween: 20,
|
|
|
|
|
centeredSlides: true
|
|
|
|
|
};
|
|
|
|
|
zoomActive = false;
|
2021-12-16 16:36:39 +01:00
|
|
|
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();
|
|
|
|
|
}
|
2021-11-22 13:53:37 +01:00
|
|
|
}
|
2021-07-26 10:52:14 +01:00
|
|
|
}
|
2021-12-06 16:00:57 +01:00
|
|
|
|
2021-12-16 16:36:39 +01:00
|
|
|
async touchEnd(zoomslides: IonSlides, card) {
|
|
|
|
|
// Zoom back to normal
|
|
|
|
|
const slider = await zoomslides.getSwiper();
|
|
|
|
|
const zoom = slider.zoom;
|
|
|
|
|
zoom.out();
|
2021-12-06 16:00:57 +01:00
|
|
|
|
2021-12-16 16:36:39 +01:00
|
|
|
// Card back to normal
|
|
|
|
|
card.el.style['z-index'] = 9;
|
2021-12-06 16:00:57 +01:00
|
|
|
|
2021-12-16 16:36:39 +01:00
|
|
|
this.zoomActive = false;
|
|
|
|
|
this.changeDetectorRef.detectChanges();
|
|
|
|
|
}
|
2021-12-06 16:00:57 +01:00
|
|
|
|
2021-12-16 16:36:39 +01:00
|
|
|
touchStart(card) {
|
|
|
|
|
// Make card appear above backdrop
|
|
|
|
|
card.el.style['z-index'] = 11;
|
|
|
|
|
}
|
2021-07-26 10:52:14 +01:00
|
|
|
|
2021-11-22 13:53:37 +01:00
|
|
|
async openPreview(msg) {
|
|
|
|
|
const modal = await this.modalController.create({
|
2021-12-16 16:36:39 +01:00
|
|
|
component: ViewMediaPage,
|
2021-12-07 17:25:09 +01:00
|
|
|
cssClass: 'modal modal-desktop',
|
2021-11-22 13:53:37 +01:00
|
|
|
componentProps: {
|
|
|
|
|
image: msg.attachments[0].image_url,
|
2021-12-17 09:40:28 +01:00
|
|
|
username: msg.u.name,
|
2021-11-22 13:53:37 +01:00
|
|
|
_updatedAt: msg._updatedAt
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
modal.present();
|
|
|
|
|
}
|
2021-03-04 18:49:50 +01:00
|
|
|
}
|
2021-03-12 11:56:54 +01:00
|
|
|
|
2021-11-22 13:53:37 +01:00
|
|
|
|
|
|
|
|
|