mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-20 21:35:50 +00:00
170 lines
4.0 KiB
TypeScript
170 lines
4.0 KiB
TypeScript
import { HttpErrorResponse, HttpHeaders } from '@angular/common/http';
|
|
import { Component, EventEmitter, OnInit, Output } from '@angular/core';
|
|
import { ModalController } from '@ionic/angular';
|
|
import { AuthService } from 'src/app/services/auth.service';
|
|
import { ChatService } from 'src/app/services/chat.service';
|
|
import { MessagesPage } from '../messages.page';
|
|
import { ThemeService } from 'src/app/services/theme.service'
|
|
import { WsChatMethodsService} from 'src/app/services/chat/ws-chat-methods.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 {
|
|
showLoader: boolean;
|
|
loggedUser: any;
|
|
users = [];
|
|
|
|
headers: HttpHeaders;
|
|
options:any;
|
|
contacts:any;
|
|
textSearch:string;
|
|
room:any;
|
|
dm:any;
|
|
sessionStore = SessionStore
|
|
|
|
@Output() openMessage:EventEmitter<any> = new EventEmitter<any>();
|
|
@Output() emptyTextDescriptionOpen:EventEmitter<any> = new EventEmitter<any>();
|
|
|
|
constructor(
|
|
private modalController: ModalController,
|
|
private chatService: ChatService,
|
|
private authService: AuthService,
|
|
public ThemeService: ThemeService,
|
|
public WsChatMethodsService: WsChatMethodsService
|
|
) {
|
|
this.loggedUser = authService.ValidatedUserChat['data'];
|
|
this.textSearch="";
|
|
this.dm=null;
|
|
this.room=null;
|
|
}
|
|
|
|
async ngOnInit() {
|
|
|
|
this.loadUsers();
|
|
await this.chatService.refreshtoken();
|
|
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.options = {
|
|
headers: this.headers,
|
|
};
|
|
this.chatService.getAllUsers().subscribe((res:any)=> {
|
|
|
|
//this.contacts = res.users.filter(data => data.username != this.sessionStore.user.UserName);
|
|
this.contacts = res.users.filter(data => data.username != this.sessionStore.user.UserName);
|
|
this.users = this.contacts.sort((a,b) => {
|
|
if(a.name < b.name){
|
|
return -1;
|
|
}
|
|
if(a.name > b.name){
|
|
return 1;
|
|
}
|
|
return 0;
|
|
});
|
|
this.showLoader = false;
|
|
});
|
|
}
|
|
|
|
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() {
|
|
this.emptyTextDescriptionOpen.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.WsChatMethodsService.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);
|
|
//Get direct messages (dm)
|
|
/* this.getDirectMessage(this.room._id); */
|
|
|
|
|
|
|
|
/* const modal = await this.modalController.create({
|
|
component: MessagesPage,
|
|
cssClass: 'group-messages',
|
|
backdropDismiss: false,
|
|
componentProps: {
|
|
dm: dm,
|
|
},
|
|
});
|
|
await modal.present();
|
|
modal.onDidDismiss(); */
|
|
}
|
|
|
|
}
|