mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 12:37:53 +00:00
135 lines
2.9 KiB
TypeScript
135 lines
2.9 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
|
|
userList = this.ChatSystemService.users
|
|
|
|
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();
|
|
this.ChatSystemService.getUser()
|
|
|
|
}
|
|
|
|
onChange(event) {
|
|
|
|
this.textSearch = event.detail.value.toLowerCase();
|
|
|
|
this.userList = this.ChatSystemService.users.filter((e) => {
|
|
const username = e.name.toLowerCase()
|
|
return username.includes(this.textSearch)
|
|
})
|
|
|
|
}
|
|
|
|
|
|
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() {}
|
|
loading = false
|
|
|
|
createRoom(username:string) {
|
|
|
|
if(this.loading) {
|
|
return
|
|
}
|
|
|
|
this.loading = true
|
|
let body = {
|
|
username: username,
|
|
}
|
|
this.chatService.createRoom(body).subscribe(async(res) => {
|
|
this.room = res['room'];
|
|
|
|
this.ChatSystemService.getAllRooms(() => {
|
|
this.getDirectMessage(this.room._id);
|
|
this.loading = false
|
|
}, this.room._id);
|
|
|
|
|
|
}, ()=> {
|
|
this.loading = false
|
|
});
|
|
|
|
}
|
|
|
|
getDirectMessage(roomId:any) {
|
|
|
|
this.openModal(roomId);
|
|
|
|
}
|
|
|
|
async openModal(roomId:any){
|
|
this.close();
|
|
console.log('open chat')
|
|
|
|
const modal = await this.modalController.create({
|
|
component: MessagesPage,
|
|
cssClass: 'group-messages',
|
|
componentProps: {
|
|
roomId: roomId,
|
|
},
|
|
});
|
|
|
|
modal.onDidDismiss();
|
|
await modal.present();
|
|
}
|
|
|
|
}
|