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

761 lines
20 KiB
TypeScript
Raw Normal View History

2021-11-17 15:34:15 +01:00
import { AfterViewChecked, AfterViewInit, ChangeDetectorRef, Component, ElementRef, OnDestroy, OnInit, ViewChild } from '@angular/core';
2021-07-27 00:21:30 +01:00
import {ActivatedRoute, Router} from '@angular/router'
2021-12-08 19:36:41 +01:00
import { GestureController, Gesture, ModalController, NavParams, PopoverController, IonSlides, Platform } from '@ionic/angular';
2021-09-01 17:14:57 +01:00
import { map } from 'rxjs/operators';
import { ViewDocumentPage } from 'src/app/modals/view-document/view-document.page';
2021-09-21 14:05:59 +01:00
import { EventPerson } from 'src/app/models/eventperson.model';
2021-10-09 16:41:18 +01:00
import { ExpedientTaskModalPageNavParamsTask } from 'src/app/models/ExpedientTaskModalPage';
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-11-05 18:19:27 +01:00
import { Filesystem, Directory, Encoding } from '@capacitor/filesystem';
import { VoiceRecorder, VoiceRecorderPlugin, RecordingData, GenericResponse, CurrentRecordingStatus } from 'capacitor-voice-recorder';
import { Haptics, ImpactStyle } from '@capacitor/haptics';
2021-11-17 15:34:15 +01:00
import { PreviewCameraPage } from 'src/app/modals/preview-camera/preview-camera.page';
2021-12-08 19:36:41 +01:00
import { SqliteService } from 'src/app/services/sqlite.service';
import { elementAt } from 'rxjs-compat/operator/elementAt';
import { ViewMediaPage } from 'src/app/modals/view-media/view-media.page';
2021-11-21 19:49:59 +01:00
const IMAGE_DIR = 'stored-images';
2020-12-30 11:13:50 +01:00
@Component({
selector: 'app-messages',
templateUrl: './messages.page.html',
styleUrls: ['./messages.page.scss'],
})
2021-08-23 16:31:06 +01:00
export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
2021-01-27 16:01:49 +01:00
showLoader: boolean;
2021-01-13 10:02:30 +01:00
@ViewChild('scrollMe') private myScrollContainer: ElementRef;
/* @ViewChild('messageContainer') messageContainer: ElementRef; */
@ViewChild('rectangle') private rectangle: ElementRef;
2021-01-13 10:02:30 +01:00
2021-11-23 10:57:07 +01:00
canvas: any
ctx: any
2021-01-13 10:02:30 +01:00
loggedUser: any;
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-11-05 18:19:27 +01:00
chatMessageStore = ChatMessageStore;
chatUserStorage = ChatUserStorage;
2021-08-23 16:31:06 +01:00
private scrollChangeCallback: () => void;
currentPosition: any;
startPosition: number;
2021-09-24 15:39:25 +01:00
scrollToBottomBtn = false;
2021-09-21 14:05:59 +01:00
attendees: EventPerson[] = [];
longPressActive = false;
2021-09-30 10:41:40 +01:00
showMessageOptions = false;
selectedMsgId:string;
2021-01-13 10:02:30 +01:00
2021-10-09 16:41:18 +01:00
dicIndex = 0;
task: ExpedientTaskModalPageNavParamsTask;
LoadedDocument:any = null;
2021-11-05 18:19:27 +01:00
recording = false;
storedFileNames = [];
durationDisplay = '';
duration = 0;
@ViewChild('recordbtn', { read: ElementRef }) recordBtn: ElementRef;
myAudio: any;
2020-12-30 11:13:50 +01:00
constructor(
public popoverController: PopoverController,
private modalController: ModalController,
2021-03-12 11:56:54 +01:00
private navParams: NavParams,
2021-01-13 10:02:30 +01:00
private chatService: ChatService,
private authService: AuthService,
2021-04-13 14:14:55 +01:00
private alertService: AlertService,
2021-07-12 11:13:29 +01:00
private toastService: ToastService,
2021-07-27 00:21:30 +01:00
private route: Router,
private activatedRoute: ActivatedRoute,
2021-09-21 14:05:59 +01:00
private fileService: FileService,
private gestureController: GestureController,
2021-10-09 16:41:18 +01:00
private processes: ProcessesService,
2021-11-17 15:34:15 +01:00
public ThemeService: ThemeService,
2021-11-30 12:30:58 +01:00
private changeDetectorRef: ChangeDetectorRef,
2021-12-08 19:36:41 +01:00
private platform: Platform,
private sqlservice: SqliteService
2021-07-23 14:43:51 +01:00
) {
this.loggedUser = authService.ValidatedUserChat['data'];
2021-03-12 11:56:54 +01:00
this.roomId = this.navParams.get('roomId');
2021-12-08 19:36:41 +01:00
console.log('ROOM ID', this.roomId)
2021-09-03 17:02:42 +01:00
window.onresize = (event) => {
if( window.innerWidth > 701){
this.modalController.dismiss();
}
};
2021-01-13 10:02:30 +01:00
}
2020-12-30 11:13:50 +01:00
ngOnInit() {
2021-11-05 18:19:27 +01:00
this.load();
this.setStatus('online');
2021-01-13 10:02:30 +01:00
2021-11-05 18:19:27 +01:00
this.loadFiles();
VoiceRecorder.requestAudioRecordingPermission();
2021-11-21 19:49:59 +01:00
Filesystem.mkdir({
path: IMAGE_DIR,
directory: Directory.Data,
recursive: true
});
2021-12-08 19:36:41 +01:00
this.getRoomMessageDB(this.roomId);
2021-11-05 18:19:27 +01:00
}
2021-07-23 14:43:51 +01:00
2021-11-05 18:19:27 +01:00
ngAfterViewInit() {
this.scrollChangeCallback = () => this.onContentScrolled(event);
window.addEventListener('scroll', this.scrollChangeCallback, true);
2021-11-05 18:19:27 +01:00
const longpress = this.gestureController.create({
el: this.recordBtn.nativeElement,
threshold: 0,
gestureName: 'long-press',
onStart: ev => {
Haptics.impact({ style: ImpactStyle.Light })
this.startRecording();
this.calculateDuration();
},
onEnd: ev =>{
Haptics.impact({ style: ImpactStyle.Light })
this.stopRecording();
}
}, true);
longpress.enable();
}
2021-11-05 18:19:27 +01:00
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)
}
2021-11-05 18:19:27 +01:00
async loadFiles(){
Filesystem.readdir({
path: '',
directory: Directory.Data
}).then(result =>{
console.log(result);
const temp:any[] = result.files.reverse();
this.storedFileNames = temp[0];
console.log(this.storedFileNames);
2021-11-05 18:19:27 +01:00
})
}
2021-11-05 18:19:27 +01:00
startRecording(){
if(this.recording){
return;
}
this.recording = true;
VoiceRecorder.startRecording();
}
stopRecording(){
if(!this.recording){
return;
}
this.recording = false;
VoiceRecorder.stopRecording().then(async (result: RecordingData) =>{
this.recording = false;
if(result.value && result.value.recordDataBase64){
const recordData = result.value.recordDataBase64;
console.log(recordData);
this.myAudio = recordData;
const fileName = new Date().getTime() + ".wav";
await Filesystem.writeFile({
path: fileName,
directory: Directory.Data,
data: recordData,
})
}
})
}
async playFile(fileName?:any){
const audioFile = await Filesystem.readFile({
path: fileName,
directory: Directory.Data
})
console.log(audioFile);
const base64sound = audioFile.data;
2021-11-05 18:19:27 +01:00
const audioRef = new Audio(`data:audio/aac;base64,${base64sound}`)
audioRef.oncanplaythrough = () => audioRef.play();
audioRef.load();
2021-10-08 15:37:24 +01:00
}
2021-09-30 10:41:40 +01:00
handlePress(id?:string){
this.selectedMsgId = id;
this.showMessageOptions = true;
}
handleClick(){
this.showMessageOptions = false;
2021-09-30 10:41:40 +01:00
this.selectedMsgId = "";
}
deleteMessage(msgId:string){
let body = {
"roomId": this.roomId,
"msgId": msgId,
"asUser": false,
}
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-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;
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
});
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-11-05 18:19:27 +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)
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);
}
else{
2021-10-09 20:55:05 +01:00
let fullUrl = "https://www.tabularium.pt" + url;
this.fileService.viewDocumentByUrl(fullUrl);
}
}
2021-10-09 16:41:18 +01:00
docIndex(index: number){
this.dicIndex = index
}
async openViewDocumentModal(file:any){
2021-10-09 20:24:34 +01:00
let task = {
serialNumber: '',
taskStartDate: '',
isEvent: true,
workflowInstanceDataFields: {
FolderID: '',
Subject: file.Assunto,
SourceSecFsID: file.ApplicationId,
SourceType: 'DOC',
SourceID: file.DocId,
DispatchNumber: ''
2021-10-09 16:41:18 +01:00
}
2021-10-09 20:24:34 +01:00
}
2021-10-09 16:41:18 +01:00
2021-10-09 20:24:34 +01:00
let doc = {
"Id": "",
"ParentId": "",
"Source": 1,
"ApplicationId": file.ApplicationId,
"CreateDate": "",
"Data": null,
"Description":"",
"Link": null,
"SourceId": file.DocId,
"SourceName": file.Assunto,
"Stakeholders": "",
}
2021-10-09 16:41:18 +01:00
2021-10-09 20:24:34 +01:00
const modal = await this.modalController.create({
component: ViewDocumentPage,
componentProps: {
trustedUrl: '',
file: {
title: file.Assunto,
url: '',
title_link: '',
2021-10-09 16:41:18 +01:00
},
2021-10-09 20:24:34 +01:00
Document: doc,
applicationId: file.ApplicationId,
docId: file.DocId,
folderId: '',
task: task
},
cssClass: 'modal modal-desktop'
});
2021-10-09 20:24:34 +01:00
await modal.present();
2021-09-21 14:05:59 +01:00
}
2021-08-18 18:31:35 +01:00
getChatMembers() {
2021-01-27 16:01:49 +01:00
this.showLoader = true;
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-12-08 19:36:41 +01:00
getRoomMessageDB(roomId) {
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
} else {
this.sqlservice.getAllChatMSG(roomId).then((msg: any) => {
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
}
chatmsgArray.push(msgChat)
});
this.messages = chatmsgArray.reverse();
console.log('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
}
this.sqlservice.addChatMSG(chatmsg)
});
}
}
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 => {
console.log("Chat message",res)
2021-09-01 17:14:57 +01:00
2021-12-08 19:36:41 +01:00
this.transformDataMSG(res['messages'])
this.getRoomMessageDB(this.roomId);
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()
2021-12-08 19:36:41 +01:00
//this.messages = res['messages'].reverse();
//this.chatMessageStore.add(roomId, this.messages)
2021-08-24 14:07:27 +01:00
2021-11-05 18:19:27 +01:00
//console.log(this.messages);
2021-07-26 19:31:19 +01:00
// 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();
2021-11-05 18:19:27 +01:00
//console.log('Timer message running')
2021-08-19 18:54:50 +01:00
}
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-12-01 15:11:54 +01:00
2021-11-17 15:34:15 +01:00
sliderOpts = {
zoom: false,
slidesPerView: 1.5,
spaceBetween: 20,
centeredSlides: true
};
zoomActive = false;
zoomScale = 1;
2021-11-17 15:34:15 +01:00
sliderZoomOpts = {
allowSlidePrev: false,
allowSlideNext: false,
zoom: {
maxRatio: 5
},
on: {
zoomChange: (scale, imageEl, slideEl) => {
2021-11-17 15:34:15 +01:00
this.zoomActive = true;
this.zoomScale = scale/5;
this.changeDetectorRef.detectChanges();
2021-11-17 15:34:15 +01:00
}
}
}
2021-11-17 15:34:15 +01:00
async touchEnd(zoomslides: IonSlides, card) {
// Zoom back to normal
const slider = await zoomslides.getSwiper();
const zoom = slider.zoom;
zoom.out();
2021-11-17 15:34:15 +01:00
// Card back to normal
card.el.style['z-index'] = 9;
2021-11-17 15:34:15 +01:00
this.zoomActive = false;
this.changeDetectorRef.detectChanges();
}
2021-11-17 15:34:15 +01:00
touchStart(card) {
// Make card appear above backdrop
card.el.style['z-index'] = 11;
}
2021-11-23 10:57:07 +01:00
2021-11-17 15:34:15 +01:00
async openPreview(msg) {
const modal = await this.modalController.create({
component: ViewMediaPage,
2021-12-03 17:27:10 +01:00
cssClass: 'modal modal-desktop',
2021-11-17 15:34:15 +01:00
componentProps: {
image: msg.attachments[0].image_url,
2021-12-03 17:27:10 +01:00
username: msg.u.name,
2021-11-22 13:53:37 +01:00
_updatedAt: msg._updatedAt,
2021-11-17 15:34:15 +01:00
}
});
modal.present();
}
2021-11-22 13:53:37 +01:00
2021-11-29 15:48:35 +01:00
2021-11-22 13:53:37 +01:00
imageSize(img){
var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');
canvas.width=300
canvas.height=234
ctx.drawImage(img.attachments[0].image_url, 0, 0, 300, 234);
document.body.appendChild(canvas);
}
2021-11-23 10:57:07 +01:00
getPicture(img){
var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');
canvas.width=300
canvas.height=234
ctx.drawImage(img.attachments[0].image_url, 0, 0, 300, 234);
document.body.appendChild(canvas);
}
2021-11-30 12:30:58 +01:00
2021-11-30 17:56:56 +01:00
// async ShareEmail(msg){
// // Check if sharing via email is supported
// await Share.share({
// title: msg.u.username,
// text: msg._updatedAt,
// url: msg.attachments[0].image_url,
// dialogTitle: 'Share with buddies',
// });
// }
2021-07-23 14:43:51 +01:00
}
2021-11-17 15:34:15 +01:00