mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 12:37:53 +00:00
Merge branch 'feature/chat-new-api-eudes' into feature/chat-new-api-peter
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
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';
|
||||
|
||||
|
||||
export interface UserContacts {
|
||||
wxUserId: number;
|
||||
wxFullName: string;
|
||||
wxeMail: string | null;
|
||||
userPhoto: string | null;
|
||||
}
|
||||
|
||||
export interface UserListResult {
|
||||
total: number,
|
||||
result: UserContacts[]
|
||||
}
|
||||
|
||||
export interface UserList {
|
||||
success: boolean;
|
||||
message: string;
|
||||
data: UserListResult;
|
||||
}
|
||||
|
||||
@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">
|
||||
<ion-progress-bar class="position-absolute" type="indeterminate" *ngIf="loading"></ion-progress-bar>
|
||||
<ion-virtual-scroll [items]="userList" approxItemHeight="70px" [headerFn]="separateLetter">
|
||||
|
||||
|
||||
<div class="item-divider" *virtualHeader="let header">
|
||||
<ion-label>{{header}}</ion-label>
|
||||
<ion-label>{{ header }}</ion-label>
|
||||
</div>
|
||||
|
||||
<div (click)="openMessagesPage(user.username)" *virtualItem="let user" class="item-user cursor-pointer">
|
||||
<p>{{user.name}}</p>
|
||||
|
||||
<div (click)="openMessagesPage(user.wxFullName)" *virtualItem="let user" class="item-user cursor-pointer">
|
||||
<p>{{ user.wxFullName }}</p>
|
||||
<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>
|
||||
</div>
|
||||
|
||||
|
||||
</ion-virtual-scroll>
|
||||
|
||||
</div>
|
||||
|
||||
</ion-content>
|
||||
|
||||
@@ -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<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>();
|
||||
@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>();
|
||||
|
||||
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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user