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

139 lines
3.1 KiB
TypeScript
Raw Normal View History

2022-10-12 17:01:09 +01:00
import { HttpHeaders } from '@angular/common/http';
2022-10-11 14:18:55 +01:00
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
2021-03-04 18:50:26 +01:00
import { ModalController } from '@ionic/angular';
import { ChatService } from 'src/app/services/chat.service';
import { MessagesPage } from '../messages.page';
2021-10-25 13:21:48 +01:00
import { ThemeService } from 'src/app/services/theme.service'
2022-09-30 15:13:36 +01:00
import { ChatSystemService } from 'src/app/services/chat/chat-system.service'
2022-04-18 15:12:27 +01:00
import { SessionStore } from 'src/app/store/session.service';
2021-03-04 18:50:26 +01:00
@Component({
selector: 'app-contacts',
templateUrl: './contacts.page.html',
styleUrls: ['./contacts.page.scss'],
})
export class ContactsPage implements OnInit {
loggedUser: any;
headers: HttpHeaders;
options:any;
textSearch:string;
room:any;
dm:any;
2022-04-18 15:12:27 +01:00
sessionStore = SessionStore
2022-10-11 14:18:55 +01:00
@Input() roomId: string;
2021-03-04 18:50:26 +01:00
2021-03-18 09:25:59 +01:00
@Output() openMessage:EventEmitter<any> = new EventEmitter<any>();
2022-10-11 14:18:55 +01:00
@Output() emptyTextDescriptionOpen:EventEmitter<any> = new EventEmitter<any>();
2022-10-13 14:37:03 +01:00
@Output() backToChat:EventEmitter<any> = new EventEmitter<any>();
@Output() closeAllDesktopComponents:EventEmitter<any> = new EventEmitter<any>();
2021-03-18 09:25:59 +01:00
2021-03-04 18:50:26 +01:00
constructor(
private modalController: ModalController,
private chatService: ChatService,
2022-01-29 19:33:32 +01:00
public ThemeService: ThemeService,
2022-09-30 15:13:36 +01:00
public ChatSystemService: ChatSystemService
2022-02-10 18:07:06 +01:00
) {
2022-10-12 17:01:09 +01:00
this.loggedUser = SessionStore.user.ChatData['data'];
2021-03-04 18:50:26 +01:00
this.textSearch="";
this.dm=null;
this.room=null;
}
2022-08-10 14:24:45 +01:00
async ngOnInit() {
2022-06-10 09:42:41 +01:00
2021-03-04 18:50:26 +01:00
this.loadUsers();
}
2021-03-29 16:01:58 +01:00
2022-10-11 15:35:50 +01:00
onChange(event) {
2021-03-04 18:50:26 +01:00
this.textSearch = event.detail.value;
}
2022-10-11 15:35:50 +01:00
openMessagesPage(username:string) {
2021-12-14 16:22:53 +01:00
if( window.innerWidth < 701){
2021-03-18 09:25:59 +01:00
this.createRoom(username);
}
else{
let body = {
username: username,
}
this.chatService.createRoom(body).subscribe(res => {
2022-04-28 09:32:27 +01:00
2021-03-18 09:25:59 +01:00
this.room = res['room'];
this.openMessage.emit(this.room._id);
});
}
}
2022-08-10 14:24:45 +01:00
loadUsers() {
2022-10-04 11:33:46 +01:00
this.ChatSystemService.getUser()
2021-03-04 18:50:26 +01:00
}
2022-10-11 15:35:50 +01:00
separateLetter(record, recordIndex, records) {
if(recordIndex == 0) {
2021-03-04 18:50:26 +01:00
return record.name[0];
}
let first_prev = records[recordIndex - 1].name[0];
let first_current = record.name[0];
2022-07-27 16:12:46 +01:00
if(first_prev != first_current) {
2021-03-04 18:50:26 +01:00
return first_current;
}
return null;
}
2022-07-27 16:12:46 +01:00
doRefresh(event) {
2021-03-04 18:50:26 +01:00
}
2022-07-27 16:12:46 +01:00
close() {
2022-10-13 14:37:03 +01:00
if(this.roomId) {
this.backToChat.emit({roomId: this.roomId});
} else {
this.closeAllDesktopComponents.emit();
}
2021-03-04 18:50:26 +01:00
}
2021-07-23 14:43:51 +01:00
2022-07-27 16:12:46 +01:00
clicked() {
2022-04-28 09:32:27 +01:00
2021-03-04 18:50:26 +01:00
}
createRoom(username:string){
let body = {
username: username,
}
this.chatService.createRoom(body).subscribe(res => {
2022-04-28 09:32:27 +01:00
2021-03-04 18:50:26 +01:00
this.room = res['room'];
2021-12-14 16:42:09 +01:00
this.openMessagesModal(this.room._id);
2022-09-30 15:13:36 +01:00
this.ChatSystemService.getAllRooms()
2021-03-04 18:50:26 +01:00
});
}
2021-12-14 16:42:09 +01:00
async openMessagesModal(roomId: any) {
2022-04-28 09:32:27 +01:00
2021-07-23 14:43:51 +01:00
2021-03-04 18:50:26 +01:00
const modal = await this.modalController.create({
component: MessagesPage,
2021-12-14 16:42:09 +01:00
cssClass: 'modal modal-desktop isMessagesChatOpened',
2021-03-04 18:50:26 +01:00
componentProps: {
2021-12-14 16:42:09 +01:00
roomId: roomId,
2021-03-04 18:50:26 +01:00
},
});
await modal.present();
modal.onDidDismiss();
}
async openMessages(username:string){
/* this.close(); */
let dm:any;
//Create new room
2022-10-11 15:35:50 +01:00
this.createRoom(username);
2021-07-23 14:43:51 +01:00
2021-03-04 18:50:26 +01:00
}
}