2022-06-08 11:56:56 +01:00
|
|
|
import { HttpClient, HttpErrorResponse, HttpHeaders } from '@angular/common/http';
|
2021-01-04 12:00:04 +01:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
|
|
|
|
import { ModalController } from '@ionic/angular';
|
2021-01-13 15:49:58 +01:00
|
|
|
import { AuthService } from 'src/app/services/auth.service';
|
|
|
|
|
import { ChatService } from 'src/app/services/chat.service';
|
2021-01-04 12:00:04 +01:00
|
|
|
import { MessagesPage } from '../messages.page';
|
2021-10-25 14:00:58 +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-01-04 12:00:04 +01:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-contacts',
|
|
|
|
|
templateUrl: './contacts.page.html',
|
|
|
|
|
styleUrls: ['./contacts.page.scss'],
|
|
|
|
|
})
|
|
|
|
|
export class ContactsPage implements OnInit {
|
|
|
|
|
showLoader: boolean;
|
2021-01-13 15:49:58 +01:00
|
|
|
loggedUser: any;
|
2021-01-04 12:00:04 +01:00
|
|
|
users = [];
|
|
|
|
|
|
2021-01-13 15:49:58 +01:00
|
|
|
contacts:any;
|
|
|
|
|
textSearch:string;
|
2021-01-14 16:51:16 +01:00
|
|
|
room:any;
|
|
|
|
|
dm:any;
|
2022-04-18 15:12:27 +01:00
|
|
|
sessionStore = SessionStore
|
2023-05-19 12:00:51 +01:00
|
|
|
userList = this.ChatSystemService.users
|
2023-09-22 17:25:27 +01:00
|
|
|
|
2021-01-04 12:00:04 +01:00
|
|
|
constructor(
|
|
|
|
|
private modalController: ModalController,
|
|
|
|
|
private http: HttpClient,
|
2021-01-13 15:49:58 +01:00
|
|
|
private chatService: ChatService,
|
|
|
|
|
private authService: AuthService,
|
2022-01-29 19:33:32 +01:00
|
|
|
public ThemeService: ThemeService,
|
2022-09-30 15:13:36 +01:00
|
|
|
public ChatSystemService: ChatSystemService,
|
2021-07-23 14:43:51 +01:00
|
|
|
)
|
|
|
|
|
{
|
2022-10-12 17:01:09 +01:00
|
|
|
this.loggedUser = SessionStore.user.ChatData['data'];
|
2021-07-23 14:43:51 +01:00
|
|
|
|
2021-01-13 15:49:58 +01:00
|
|
|
this.textSearch="";
|
2021-01-14 16:51:16 +01:00
|
|
|
this.dm=null;
|
|
|
|
|
this.room=null;
|
2021-01-13 15:49:58 +01:00
|
|
|
}
|
2021-01-04 12:00:04 +01:00
|
|
|
|
|
|
|
|
ngOnInit() {
|
2022-10-11 13:56:56 +01:00
|
|
|
// this.chatService.refreshtoken();
|
2023-03-31 14:54:03 +01:00
|
|
|
// this.loadUsers();
|
2023-09-22 17:25:27 +01:00
|
|
|
this.ChatSystemService.getUser()
|
2021-01-04 12:00:04 +01:00
|
|
|
|
|
|
|
|
}
|
2023-05-19 12:00:51 +01:00
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
})
|
2023-09-22 17:25:27 +01:00
|
|
|
|
2021-01-13 15:49:58 +01:00
|
|
|
}
|
2021-01-04 12:00:04 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
separateLetter(record, recordIndex, records){
|
|
|
|
|
if(recordIndex == 0){
|
2021-01-13 15:49:58 +01:00
|
|
|
return record.name[0];
|
2021-01-04 12:00:04 +01:00
|
|
|
}
|
|
|
|
|
|
2021-01-13 15:49:58 +01:00
|
|
|
let first_prev = records[recordIndex - 1].name[0];
|
|
|
|
|
let first_current = record.name[0];
|
2021-01-04 12:00:04 +01:00
|
|
|
|
|
|
|
|
if(first_prev != first_current){
|
|
|
|
|
return first_current;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
doRefresh(event){
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-08 14:17:22 +01:00
|
|
|
close() {
|
2022-08-10 14:32:15 +01:00
|
|
|
this.modalController.dismiss({});
|
2021-01-04 12:00:04 +01:00
|
|
|
}
|
2021-07-23 14:43:51 +01:00
|
|
|
|
2022-07-08 14:17:22 +01:00
|
|
|
clicked() {}
|
2023-08-14 21:26:23 +01:00
|
|
|
loading = false
|
2021-01-14 16:51:16 +01:00
|
|
|
|
2023-03-31 14:54:03 +01:00
|
|
|
createRoom(username:string) {
|
2023-08-14 21:26:23 +01:00
|
|
|
|
|
|
|
|
if(this.loading) {
|
2023-09-22 17:25:27 +01:00
|
|
|
return
|
2023-08-14 21:26:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.loading = true
|
2021-01-14 16:51:16 +01:00
|
|
|
let body = {
|
|
|
|
|
username: username,
|
|
|
|
|
}
|
2022-07-08 14:17:22 +01:00
|
|
|
this.chatService.createRoom(body).subscribe(async(res) => {
|
2021-01-14 16:51:16 +01:00
|
|
|
this.room = res['room'];
|
2023-08-15 10:15:08 +01:00
|
|
|
|
|
|
|
|
this.ChatSystemService.getAllRooms(() => {
|
|
|
|
|
this.getDirectMessage(this.room._id);
|
|
|
|
|
this.loading = false
|
|
|
|
|
}, this.room._id);
|
|
|
|
|
|
|
|
|
|
|
2023-08-14 21:26:23 +01:00
|
|
|
}, ()=> {
|
|
|
|
|
this.loading = false
|
2021-01-14 16:51:16 +01:00
|
|
|
});
|
2023-08-14 21:26:23 +01:00
|
|
|
|
2021-01-14 16:51:16 +01:00
|
|
|
}
|
2022-07-08 14:17:22 +01:00
|
|
|
|
|
|
|
|
getDirectMessage(roomId:any) {
|
2023-09-22 17:25:27 +01:00
|
|
|
|
2023-03-31 14:54:03 +01:00
|
|
|
this.openModal(roomId);
|
2021-07-23 14:43:51 +01:00
|
|
|
|
2021-01-04 12:00:04 +01:00
|
|
|
}
|
2022-07-08 14:17:22 +01:00
|
|
|
|
2021-04-13 11:34:52 +01:00
|
|
|
async openModal(roomId:any){
|
2021-01-04 12:00:04 +01:00
|
|
|
this.close();
|
2023-08-14 16:25:57 +01:00
|
|
|
console.log('open chat')
|
2021-07-23 14:43:51 +01:00
|
|
|
|
2021-01-04 12:00:04 +01:00
|
|
|
const modal = await this.modalController.create({
|
|
|
|
|
component: MessagesPage,
|
|
|
|
|
cssClass: 'group-messages',
|
2021-01-14 16:51:16 +01:00
|
|
|
componentProps: {
|
2021-04-13 11:34:52 +01:00
|
|
|
roomId: roomId,
|
2021-01-14 16:51:16 +01:00
|
|
|
},
|
2021-01-04 12:00:04 +01:00
|
|
|
});
|
2023-07-15 11:01:09 +01:00
|
|
|
|
2021-01-04 12:00:04 +01:00
|
|
|
modal.onDidDismiss();
|
2023-07-15 11:01:09 +01:00
|
|
|
await modal.present();
|
2021-01-04 12:00:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|