mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-20 05:16:07 +00:00
144 lines
3.2 KiB
TypeScript
144 lines
3.2 KiB
TypeScript
import { HttpClient, HttpErrorResponse, HttpHeaders } from '@angular/common/http';
|
|
import { Component, OnInit } 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 { 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 {
|
|
showLoader: boolean;
|
|
loggedUser: any;
|
|
users = [];
|
|
|
|
contacts:any;
|
|
textSearch:string;
|
|
room:any;
|
|
dm:any;
|
|
sessionStore = SessionStore
|
|
|
|
constructor(
|
|
private modalController: ModalController,
|
|
private http: HttpClient,
|
|
private chatService: ChatService,
|
|
private authService: AuthService,
|
|
public ThemeService: ThemeService,
|
|
public ChatSystemService: ChatSystemService,
|
|
)
|
|
{
|
|
this.loggedUser = SessionStore.user.ChatData['data'];
|
|
|
|
this.textSearch="";
|
|
this.dm=null;
|
|
this.room=null;
|
|
}
|
|
|
|
ngOnInit() {
|
|
// this.chatService.refreshtoken();
|
|
this.loadUsers();
|
|
|
|
}
|
|
onChange(event){
|
|
this.textSearch = event.detail.value;
|
|
}
|
|
|
|
loadUsers(){
|
|
|
|
this.chatService.getAllUsers().subscribe((res:any) => {
|
|
|
|
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;
|
|
}, (error) =>{
|
|
// this.chatService.refreshtoken();
|
|
});
|
|
}
|
|
|
|
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.modalController.dismiss({});
|
|
}
|
|
|
|
clicked() {}
|
|
|
|
createRoom(username:string){
|
|
let body = {
|
|
username: username,
|
|
}
|
|
this.chatService.createRoom(body).subscribe(async(res) => {
|
|
|
|
this.room = res['room'];
|
|
|
|
await this.ChatSystemService.getAllRooms();
|
|
this.getDirectMessage(this.room._id);
|
|
});
|
|
}
|
|
|
|
getDirectMessage(roomId:any) {
|
|
|
|
|
|
this.chatService.getAllDirectMessages().subscribe(res=>{
|
|
let result = res['ims'].filter(data => data._id == roomId);
|
|
|
|
|
|
this.dm = result[0];
|
|
|
|
this.openModal(this.dm._id);
|
|
});
|
|
}
|
|
|
|
async openModal(roomId:any){
|
|
this.close();
|
|
|
|
|
|
const modal = await this.modalController.create({
|
|
component: MessagesPage,
|
|
cssClass: 'group-messages',
|
|
componentProps: {
|
|
roomId: roomId,
|
|
},
|
|
});
|
|
await modal.present();
|
|
modal.onDidDismiss();
|
|
}
|
|
|
|
async openMessages(username:string){
|
|
|
|
let dm:any;
|
|
this.createRoom(username);
|
|
|
|
}
|
|
|
|
}
|