- +
- {{header}} + {{ header }}
- -
-

{{user.name}}

+ +
+

{{ user.wxFullName }}

- +
- + -
+ diff --git a/src/app/shared/chat/messages/contacts/contacts.page.ts b/src/app/shared/chat/messages/contacts/contacts.page.ts index da84e3fc6..965520619 100644 --- a/src/app/shared/chat/messages/contacts/contacts.page.ts +++ b/src/app/shared/chat/messages/contacts/contacts.page.ts @@ -6,6 +6,10 @@ 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'; +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'; +import { RoomRepositoryService } from 'src/app/services/Repositorys/chat/repository/room-repository.service'; +import { HttpErrorResponse } from '@angular/common/http'; @@ -22,20 +26,21 @@ export class ContactsPage implements OnInit { loggedUser: any; headers: HttpHeaders; - options:any; - textSearch:string; - room:any; - dm:any; + options: any; + textSearch: string; + room: any; + dm: any; sessionStore = SessionStore loading = false @Input() roomId: string; - @Output() openMessage:EventEmitter = new EventEmitter(); - @Output() emptyTextDescriptionOpen:EventEmitter = new EventEmitter(); - @Output() backToChat:EventEmitter = new EventEmitter(); - @Output() closeAllDesktopComponents:EventEmitter = new EventEmitter(); + @Output() openMessage: EventEmitter = new EventEmitter(); + @Output() emptyTextDescriptionOpen: EventEmitter = new EventEmitter(); + @Output() backToChat: EventEmitter = new EventEmitter(); + @Output() closeAllDesktopComponents: EventEmitter = new EventEmitter(); - userList = this.ChatSystemService.users + userList: UserContacts[]; + originalUserList: any[] = []; CoolList = [] @@ -43,51 +48,38 @@ export class ContactsPage implements OnInit { private modalController: ModalController, private chatService: ChatService, public ThemeService: ThemeService, - public ChatSystemService: ChatSystemService + public ChatSystemService: ChatSystemService, + private contactsRepositoryService: ContactRepositoryService, + private roomRepositoryService: RoomRepositoryService ) { this.loggedUser = SessionStore.user.ChatData['data']; - this.textSearch=""; - this.dm=null; - this.room=null; + this.textSearch = ""; + this.dm = null; + this.room = null; } async ngOnInit() { - + this.loadUsers(); } onChange(event) { - this.textSearch = event.detail.value.toLowerCase(); + this.userList = this.originalUserList.filter((e) => { + const username = e.wxFullName.toLowerCase(); + return username.includes(this.textSearch); + }); - this.userList = this.ChatSystemService.users.filter((e) => { - const username = e.name.toLowerCase() - return username.includes(this.textSearch) - }) - - - const alfa = {} - - for (let user of this.userList) { - - let firstCharacter = user.name.charAt(0); - - if(!alfa[firstCharacter]) { - alfa[firstCharacter] = [user] - } else { - alfa[firstCharacter].push(user) - } - - } - + this.userList.sort((a, b) => a.wxFullName.toLowerCase().localeCompare(b.wxFullName.toLowerCase())); } - openMessagesPage(username:string) { - if( window.innerWidth < 701){ + openMessagesPage(username: string) { + this.createRoom(username); + /* if (window.innerWidth < 701) { this.createRoom(username); } - else{ - let body = { + else { + let body = { username: username, } @@ -100,27 +92,45 @@ export class ContactsPage implements OnInit { this.loading = false }, this.room._id); - - }, ()=> { + + }, () => { this.loading = false - }); - } + }); + }*/ } - loadUsers() { - this.ChatSystemService.getUser() + async loadUsers() { + 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; + } } separateLetter(record, recordIndex, records) { - if(recordIndex == 0) { - return record.name[0]; + const normalize = (str) => str.normalize('NFD').replace(/[\u0300-\u036f]/g, ''); + + if (recordIndex == 0) { + return normalize(record.wxFullName[0]).toUpperCase(); } - let first_prev = records[recordIndex - 1].name[0]; - let first_current = record.name[0]; + let firstPrev = normalize(records[recordIndex - 1].wxFullName[0]).toUpperCase(); + let firstCurrent = normalize(record.wxFullName[0]).toUpperCase(); - if(first_prev != first_current) { - return first_current; + if (firstPrev !== firstCurrent) { + return firstCurrent; } return null; } @@ -129,33 +139,47 @@ export class ContactsPage implements OnInit { } close() { - if(this.roomId) { - this.backToChat.emit({roomId: this.roomId}); + if (this.roomId) { + this.backToChat.emit({ roomId: this.roomId }); } else { this.closeAllDesktopComponents.emit(); } - + } clicked() { - + } - createRoom(username:string){ - let body = { - username: username, + async createRoom(username: string) { + const result = await this.roomRepositoryService.create({ + roomName: username, + createdBy: SessionStore.user.UserId, + roomType: 0, + expirationDate: null + }) + + + console.log(result) + + if(result.isOk()) { + + // this.addGroupMessage.emit(result); + + } else if(result.error instanceof HttpErrorResponse) { + } - this.chatService.createRoom(body).subscribe(res => { - - this.room = res['room']; - this.openMessagesModal(this.room._id); - this.ChatSystemService.getAllRooms() - }); + /* this.chatService.createRoom(body).subscribe(res => { + + this.room = res['room']; + this.openMessagesModal(this.room._id); + this.ChatSystemService.getAllRooms() + }); */ } async openMessagesModal(roomId: any) { - + const modal = await this.modalController.create({ component: MessagesPage, @@ -169,10 +193,10 @@ export class ContactsPage implements OnInit { await modal.present(); } - async openMessages(username:string){ + async openMessages(username: string) { /* this.close(); */ - let dm:any; + let dm: any; //Create new room this.createRoom(username);