Files
doneit-web/src/app/shared/chat/messages/contacts/contacts.page.ts
T

196 lines
5.2 KiB
TypeScript
Raw Normal View History

2022-10-12 17:01:09 +01:00
import { HttpHeaders } from '@angular/common/http';
2022-10-11 14:18:55 +01:00
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
2021-03-04 18:50:26 +01:00
import { ModalController } from '@ionic/angular';
import { ChatService } from 'src/app/services/chat.service';
import { MessagesPage } from '../messages.page';
2021-10-25 13:21:48 +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';
2024-06-05 10:32:56 +01:00
import { ContactRepositoryService } from 'src/app/services/Repositorys/contacts/repository/contacts-repository.service';
import { UserContacts } from 'src/app/services/Repositorys/contacts/data-source/contacts-data-source.service';
2024-06-05 11:57:19 +01:00
import { RoomRepositoryService } from 'src/app/services/Repositorys/chat/repository/room-repository.service';
2021-03-04 18:50:26 +01:00
2023-08-20 22:00:23 +01:00
class UserToSelect {
}
2021-03-04 18:50:26 +01:00
@Component({
selector: 'app-contacts',
templateUrl: './contacts.page.html',
styleUrls: ['./contacts.page.scss'],
})
export class ContactsPage implements OnInit {
loggedUser: any;
headers: HttpHeaders;
2024-06-05 10:32:56 +01:00
options: any;
textSearch: string;
room: any;
dm: any;
2022-04-18 15:12:27 +01:00
sessionStore = SessionStore
2023-08-15 10:15:08 +01:00
loading = false
2022-10-11 14:18:55 +01:00
@Input() roomId: string;
2021-03-04 18:50:26 +01:00
2024-06-05 10:32:56 +01:00
@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>();
2021-03-18 09:25:59 +01:00
2024-06-05 10:32:56 +01:00
userList: UserContacts[];
originalUserList: any[] = [];
2023-05-19 12:00:51 +01:00
2023-08-20 22:00:23 +01:00
CoolList = []
2021-03-04 18:50:26 +01:00
constructor(
private modalController: ModalController,
private chatService: ChatService,
2022-01-29 19:33:32 +01:00
public ThemeService: ThemeService,
2024-06-05 10:32:56 +01:00
public ChatSystemService: ChatSystemService,
2024-06-05 11:57:19 +01:00
private contactsRepositoryService: ContactRepositoryService,
private roomRepositoryService: RoomRepositoryService
2022-02-10 18:07:06 +01:00
) {
2022-10-12 17:01:09 +01:00
this.loggedUser = SessionStore.user.ChatData['data'];
2024-06-05 10:32:56 +01:00
this.textSearch = "";
this.dm = null;
this.room = null;
2021-03-04 18:50:26 +01:00
}
2022-08-10 14:24:45 +01:00
async ngOnInit() {
2024-06-05 10:32:56 +01:00
2021-03-04 18:50:26 +01:00
this.loadUsers();
}
2021-03-29 16:01:58 +01:00
2022-10-11 15:35:50 +01:00
onChange(event) {
2023-05-19 12:00:51 +01:00
this.textSearch = event.detail.value.toLowerCase();
2024-06-05 10:32:56 +01:00
this.userList = this.originalUserList.filter((e) => {
const username = e.wxFullName.toLowerCase();
return username.includes(this.textSearch);
});
2023-05-19 12:00:51 +01:00
2024-06-05 10:32:56 +01:00
this.userList.sort((a, b) => a.wxFullName.toLowerCase().localeCompare(b.wxFullName.toLowerCase()));
2021-03-04 18:50:26 +01:00
}
2024-06-05 10:32:56 +01:00
openMessagesPage(username: string) {
2024-06-05 11:57:19 +01:00
this.createRoom(username);
/* if (window.innerWidth < 701) {
2021-03-18 09:25:59 +01:00
this.createRoom(username);
}
2024-06-05 10:32:56 +01:00
else {
2024-06-05 11:57:19 +01:00
let body = {
2021-03-18 09:25:59 +01:00
username: username,
}
2023-08-15 10:15:08 +01:00
this.loading = true
2021-03-18 09:25:59 +01:00
this.chatService.createRoom(body).subscribe(res => {
this.room = res['room'];
2023-08-15 10:15:08 +01:00
this.ChatSystemService.getAllRooms(() => {
this.openMessage.emit(this.room._id);
this.loading = false
}, this.room._id);
2024-06-05 10:32:56 +01:00
}, () => {
2023-08-15 10:15:08 +01:00
this.loading = false
2024-06-05 11:57:19 +01:00
});
}*/
2021-03-18 09:25:59 +01:00
}
2024-06-05 10:32:56 +01:00
async loadUsers() {
2024-06-05 11:57:19 +01:00
try {
let users = await this.contactsRepositoryService.getUsers();
if (users.isOk()) {
const userData = users.value.data.result;
console.log(userData)
this.originalUserList = userData;
this.userList = [...this.originalUserList];
this.userList.sort((a, b) => a.wxFullName.toLowerCase().localeCompare(b.wxFullName.toLowerCase()));
console.log('User data loaded successfully:', this.originalUserList);
} else {
console.error('Failed to fetch users:', users.error);
}
this.loading = false;
} catch (error) {
console.error('Error loading users', error);
this.loading = false;
2024-06-05 10:32:56 +01:00
}
2021-03-04 18:50:26 +01:00
}
2022-10-11 15:35:50 +01:00
separateLetter(record, recordIndex, records) {
2024-06-05 10:32:56 +01:00
const normalize = (str) => str.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
if (recordIndex == 0) {
return normalize(record.wxFullName[0]).toUpperCase();
2021-03-04 18:50:26 +01:00
}
2024-06-05 10:32:56 +01:00
let firstPrev = normalize(records[recordIndex - 1].wxFullName[0]).toUpperCase();
let firstCurrent = normalize(record.wxFullName[0]).toUpperCase();
2021-03-04 18:50:26 +01:00
2024-06-05 10:32:56 +01:00
if (firstPrev !== firstCurrent) {
return firstCurrent;
2021-03-04 18:50:26 +01:00
}
return null;
}
2022-07-27 16:12:46 +01:00
doRefresh(event) {
2021-03-04 18:50:26 +01:00
}
2022-07-27 16:12:46 +01:00
close() {
2024-06-05 10:32:56 +01:00
if (this.roomId) {
this.backToChat.emit({ roomId: this.roomId });
2022-10-13 14:37:03 +01:00
} else {
this.closeAllDesktopComponents.emit();
}
2024-06-05 10:32:56 +01:00
2021-03-04 18:50:26 +01:00
}
2021-07-23 14:43:51 +01:00
2022-07-27 16:12:46 +01:00
clicked() {
2024-06-05 10:32:56 +01:00
2021-03-04 18:50:26 +01:00
}
2024-06-05 11:57:19 +01:00
async createRoom(username: string) {
2021-03-04 18:50:26 +01:00
let body = {
2024-06-05 11:57:19 +01:00
roomName: username,
createdBy: SessionStore.user.UserId,
roomType: 0,
expirationDate: ""
2021-03-04 18:50:26 +01:00
}
2024-06-05 11:57:19 +01:00
let room = await this.roomRepositoryService.create(body)
console.log(room)
/* this.chatService.createRoom(body).subscribe(res => {
this.room = res['room'];
this.openMessagesModal(this.room._id);
this.ChatSystemService.getAllRooms()
}); */
2021-03-04 18:50:26 +01:00
}
2021-12-14 16:42:09 +01:00
async openMessagesModal(roomId: any) {
2024-06-05 10:32:56 +01:00
2021-07-23 14:43:51 +01:00
2021-03-04 18:50:26 +01:00
const modal = await this.modalController.create({
component: MessagesPage,
2021-12-14 16:42:09 +01:00
cssClass: 'modal modal-desktop isMessagesChatOpened',
2021-03-04 18:50:26 +01:00
componentProps: {
2021-12-14 16:42:09 +01:00
roomId: roomId,
2021-03-04 18:50:26 +01:00
},
});
2023-07-15 11:01:09 +01:00
2021-03-04 18:50:26 +01:00
modal.onDidDismiss();
2023-07-15 11:01:09 +01:00
await modal.present();
2021-03-04 18:50:26 +01:00
}
2024-06-05 10:32:56 +01:00
async openMessages(username: string) {
2021-03-04 18:50:26 +01:00
/* this.close(); */
2024-06-05 10:32:56 +01:00
let dm: any;
2021-03-04 18:50:26 +01:00
//Create new room
2022-10-11 15:35:50 +01:00
this.createRoom(username);
2021-07-23 14:43:51 +01:00
2021-03-04 18:50:26 +01:00
}
}