contactList chat done

This commit is contained in:
Eudes Inácio
2024-06-05 10:32:56 +01:00
parent 39f89a92a5
commit b38a4e4112
4 changed files with 114 additions and 65 deletions
@@ -0,0 +1,34 @@
import { Injectable } from '@angular/core';
import { HttpService } from 'src/app/services/http.service';
import { MessageOutPutDTO } from '../../chat/dto/message/messageOutputDTO';
import { MessageListInputDTO } from '../../chat/dto/message/messageListInputDTO';
import { DataSourceReturn } from '../../type';
export interface UserContacts {
wxUserId: number;
wxFullName: string;
wxeMail: string | null;
userPhoto: string | null;
}
export interface UserList {
success: boolean;
message: string;
data: UserContacts[];
}
@Injectable({
providedIn: 'root'
})
export class ContactsDataSourceService {
private baseUrl = 'https://gdapi-dev.dyndns.info/stage/api/v2'; // Your base URL
constructor(private httpService: HttpService) {}
async getUsers() {
return await this.httpService.get<UserList>(`${this.baseUrl}/Users`);
}
}
@@ -0,0 +1,18 @@
import { Injectable } from '@angular/core';
import { ContactsDataSourceService } from '../data-source/contacts-data-source.service';
@Injectable({
providedIn: 'root'
})
export class ContactRepositoryService {
constructor(
private constactsDataSourceService: ContactsDataSourceService,
) {}
async getUsers() {
const result = await this.constactsDataSourceService.getUsers();
return result;
}
}
@@ -31,19 +31,19 @@
<div class="main-content"> <div class="main-content">
<ion-progress-bar class="position-absolute" type="indeterminate" *ngIf="loading"></ion-progress-bar> <ion-progress-bar class="position-absolute" type="indeterminate" *ngIf="loading"></ion-progress-bar>
<ion-virtual-scroll [items]="userList" approxItemHeight="70px" [headerFn]="separateLetter"> <ion-virtual-scroll [items]="userList" approxItemHeight="70px" [headerFn]="separateLetter">
<div class="item-divider" *virtualHeader="let header"> <div class="item-divider" *virtualHeader="let header">
<ion-label>{{header}}</ion-label> <ion-label>{{ header }}</ion-label>
</div> </div>
<div (click)="openMessagesPage(user.username)" *virtualItem="let user" class="item-user cursor-pointer"> <div (click)="openMessagesPage(user.wxFullName)" *virtualItem="let user" class="item-user cursor-pointer">
<p>{{user.name}}</p> <p>{{ user.wxFullName }}</p>
<span class="icon"> <span class="icon">
<ion-icon class="{{user.status}}" slot="end" name="ellipse"></ion-icon> <ion-icon [class]="user.status" slot="end" name="ellipse"></ion-icon>
</span> </span>
</div> </div>
</ion-virtual-scroll> </ion-virtual-scroll>
</div> </div>
</ion-content> </ion-content>
@@ -6,6 +6,8 @@ import { MessagesPage } from '../messages.page';
import { ThemeService } from 'src/app/services/theme.service' import { ThemeService } from 'src/app/services/theme.service'
import { ChatSystemService } from 'src/app/services/chat/chat-system.service' import { ChatSystemService } from 'src/app/services/chat/chat-system.service'
import { SessionStore } from 'src/app/store/session.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';
@@ -22,20 +24,21 @@ export class ContactsPage implements OnInit {
loggedUser: any; loggedUser: any;
headers: HttpHeaders; headers: HttpHeaders;
options:any; options: any;
textSearch:string; textSearch: string;
room:any; room: any;
dm:any; dm: any;
sessionStore = SessionStore sessionStore = SessionStore
loading = false loading = false
@Input() roomId: string; @Input() roomId: string;
@Output() openMessage:EventEmitter<any> = new EventEmitter<any>(); @Output() openMessage: EventEmitter<any> = new EventEmitter<any>();
@Output() emptyTextDescriptionOpen:EventEmitter<any> = new EventEmitter<any>(); @Output() emptyTextDescriptionOpen: EventEmitter<any> = new EventEmitter<any>();
@Output() backToChat:EventEmitter<any> = new EventEmitter<any>(); @Output() backToChat: EventEmitter<any> = new EventEmitter<any>();
@Output() closeAllDesktopComponents:EventEmitter<any> = new EventEmitter<any>(); @Output() closeAllDesktopComponents: EventEmitter<any> = new EventEmitter<any>();
userList = this.ChatSystemService.users userList: UserContacts[];
originalUserList: any[] = [];
CoolList = [] CoolList = []
@@ -43,50 +46,35 @@ export class ContactsPage implements OnInit {
private modalController: ModalController, private modalController: ModalController,
private chatService: ChatService, private chatService: ChatService,
public ThemeService: ThemeService, public ThemeService: ThemeService,
public ChatSystemService: ChatSystemService public ChatSystemService: ChatSystemService,
private contactsRepositoryService: ContactRepositoryService
) { ) {
this.loggedUser = SessionStore.user.ChatData['data']; this.loggedUser = SessionStore.user.ChatData['data'];
this.textSearch=""; this.textSearch = "";
this.dm=null; this.dm = null;
this.room=null; this.room = null;
} }
async ngOnInit() { async ngOnInit() {
this.loadUsers(); this.loadUsers();
} }
onChange(event) { onChange(event) {
this.textSearch = event.detail.value.toLowerCase(); 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) => { this.userList.sort((a, b) => a.wxFullName.toLowerCase().localeCompare(b.wxFullName.toLowerCase()));
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)
}
}
} }
openMessagesPage(username:string) { openMessagesPage(username: string) {
if( window.innerWidth < 701){ if (window.innerWidth < 701) {
this.createRoom(username); this.createRoom(username);
} }
else{ else {
let body = { let body = {
username: username, username: username,
} }
@@ -100,27 +88,36 @@ export class ContactsPage implements OnInit {
this.loading = false this.loading = false
}, this.room._id); }, this.room._id);
}, ()=> { }, () => {
this.loading = false this.loading = false
}); });
} }
} }
loadUsers() { async loadUsers() {
this.ChatSystemService.getUser() /* this.ChatSystemService.getUser() */
let users = await this.contactsRepositoryService.getUsers()
if (users.isOk()) {
this.originalUserList = users.value.data
this.userList = [...this.originalUserList];
this.userList.sort((a, b) => a.wxFullName.toLowerCase().localeCompare(b.wxFullName.toLowerCase()));
console.log(users.value.data)
}
} }
separateLetter(record, recordIndex, records) { separateLetter(record, recordIndex, records) {
if(recordIndex == 0) { const normalize = (str) => str.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
return record.name[0];
if (recordIndex == 0) {
return normalize(record.wxFullName[0]).toUpperCase();
} }
let first_prev = records[recordIndex - 1].name[0]; let firstPrev = normalize(records[recordIndex - 1].wxFullName[0]).toUpperCase();
let first_current = record.name[0]; let firstCurrent = normalize(record.wxFullName[0]).toUpperCase();
if(first_prev != first_current) { if (firstPrev !== firstCurrent) {
return first_current; return firstCurrent;
} }
return null; return null;
} }
@@ -129,24 +126,24 @@ export class ContactsPage implements OnInit {
} }
close() { close() {
if(this.roomId) { if (this.roomId) {
this.backToChat.emit({roomId: this.roomId}); this.backToChat.emit({ roomId: this.roomId });
} else { } else {
this.closeAllDesktopComponents.emit(); this.closeAllDesktopComponents.emit();
} }
} }
clicked() { clicked() {
} }
createRoom(username:string){ createRoom(username: string) {
let body = { let body = {
username: username, username: username,
} }
this.chatService.createRoom(body).subscribe(res => { this.chatService.createRoom(body).subscribe(res => {
this.room = res['room']; this.room = res['room'];
this.openMessagesModal(this.room._id); this.openMessagesModal(this.room._id);
this.ChatSystemService.getAllRooms() this.ChatSystemService.getAllRooms()
@@ -155,7 +152,7 @@ export class ContactsPage implements OnInit {
async openMessagesModal(roomId: any) { async openMessagesModal(roomId: any) {
const modal = await this.modalController.create({ const modal = await this.modalController.create({
component: MessagesPage, component: MessagesPage,
@@ -169,10 +166,10 @@ export class ContactsPage implements OnInit {
await modal.present(); await modal.present();
} }
async openMessages(username:string){ async openMessages(username: string) {
/* this.close(); */ /* this.close(); */
let dm:any; let dm: any;
//Create new room //Create new room
this.createRoom(username); this.createRoom(username);