mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-20 05:16:07 +00:00
139 lines
3.1 KiB
TypeScript
139 lines
3.1 KiB
TypeScript
import { HttpHeaders } from '@angular/common/http';
|
|
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
|
|
import { ModalController } from '@ionic/angular';
|
|
import { ChatService } from 'src/app/services/chat.service';
|
|
import { MessagesPage } from '../messages.page';
|
|
import { ThemeService } from 'src/app/services/theme.service'
|
|
import { ChatSystemService } from 'src/app/services/chat/chat-system.service'
|
|
import { SessionStore } from 'src/app/store/session.service';
|
|
|
|
@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;
|
|
sessionStore = SessionStore
|
|
@Input() roomId: string;
|
|
|
|
@Output() openMessage:EventEmitter<any> = new EventEmitter<any>();
|
|
@Output() emptyTextDescriptionOpen:EventEmitter<any> = new EventEmitter<any>();
|
|
@Output() backToChat:EventEmitter<any> = new EventEmitter<any>();
|
|
@Output() closeAllDesktopComponents:EventEmitter<any> = new EventEmitter<any>();
|
|
|
|
constructor(
|
|
private modalController: ModalController,
|
|
private chatService: ChatService,
|
|
public ThemeService: ThemeService,
|
|
public ChatSystemService: ChatSystemService
|
|
) {
|
|
this.loggedUser = SessionStore.user.ChatData['data'];
|
|
this.textSearch="";
|
|
this.dm=null;
|
|
this.room=null;
|
|
}
|
|
|
|
async ngOnInit() {
|
|
|
|
this.loadUsers();
|
|
}
|
|
|
|
onChange(event) {
|
|
this.textSearch = event.detail.value;
|
|
}
|
|
|
|
openMessagesPage(username:string) {
|
|
if( window.innerWidth < 701){
|
|
this.createRoom(username);
|
|
}
|
|
else{
|
|
let body = {
|
|
username: username,
|
|
}
|
|
this.chatService.createRoom(body).subscribe(res => {
|
|
|
|
this.room = res['room'];
|
|
this.openMessage.emit(this.room._id);
|
|
});
|
|
}
|
|
}
|
|
|
|
loadUsers() {
|
|
this.ChatSystemService.getUser()
|
|
}
|
|
|
|
separateLetter(record, recordIndex, records) {
|
|
if(recordIndex == 0) {
|
|
return record.name[0];
|
|
}
|
|
|
|
let first_prev = records[recordIndex - 1].name[0];
|
|
let first_current = record.name[0];
|
|
|
|
if(first_prev != first_current) {
|
|
return first_current;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
doRefresh(event) {
|
|
}
|
|
|
|
close() {
|
|
if(this.roomId) {
|
|
this.backToChat.emit({roomId: this.roomId});
|
|
} else {
|
|
this.closeAllDesktopComponents.emit();
|
|
}
|
|
|
|
}
|
|
|
|
clicked() {
|
|
|
|
}
|
|
|
|
createRoom(username:string){
|
|
let body = {
|
|
username: username,
|
|
}
|
|
this.chatService.createRoom(body).subscribe(res => {
|
|
|
|
this.room = res['room'];
|
|
this.openMessagesModal(this.room._id);
|
|
this.ChatSystemService.getAllRooms()
|
|
});
|
|
}
|
|
|
|
async openMessagesModal(roomId: any) {
|
|
|
|
|
|
|
|
const modal = await this.modalController.create({
|
|
component: MessagesPage,
|
|
cssClass: 'modal modal-desktop isMessagesChatOpened',
|
|
componentProps: {
|
|
roomId: roomId,
|
|
},
|
|
});
|
|
await modal.present();
|
|
modal.onDidDismiss();
|
|
}
|
|
|
|
async openMessages(username:string){
|
|
/* this.close(); */
|
|
|
|
let dm:any;
|
|
//Create new room
|
|
this.createRoom(username);
|
|
|
|
}
|
|
|
|
}
|