2021-01-04 12:00:04 +01:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
|
|
|
|
import { ModalController } from '@ionic/angular';
|
2021-10-25 14:00:58 +01:00
|
|
|
import { ThemeService } from 'src/app/services/theme.service'
|
2022-04-18 15:12:27 +01:00
|
|
|
import { SessionStore } from 'src/app/store/session.service';
|
2024-08-16 17:17:32 +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';
|
|
|
|
|
import { HttpErrorHandle } from 'src/app/services/http-error-handle.service';
|
|
|
|
|
import { ToastService } from 'src/app/services/toast.service';
|
2024-08-19 16:01:58 +01:00
|
|
|
import { ChatServiceService } from 'src/app/module/chat/domain/chat-service.service'
|
2024-08-26 14:47:03 +01:00
|
|
|
import { MessageEntity } from 'src/app/core/chat/entity/message';
|
|
|
|
|
import { RoomType } from "src/app/core/chat/entity/group";
|
2024-09-18 11:47:23 +01:00
|
|
|
import { RoomViewModel } from '../../../store/model/room';
|
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 {
|
2024-08-16 17:17:32 +01:00
|
|
|
loading: 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
|
2024-08-16 17:17:32 +01:00
|
|
|
userList: UserContacts[] = []
|
|
|
|
|
|
|
|
|
|
currentMembers:UserContacts[];
|
|
|
|
|
allChatUsers: UserContacts[] = [];
|
|
|
|
|
userContainer: {[key: string]: ( UserContacts & {isChecked: boolean})[] } = {}
|
|
|
|
|
|
|
|
|
|
selectedUsers: number[] =[]
|
|
|
|
|
SessionStore = SessionStore
|
2023-09-22 17:25:27 +01:00
|
|
|
|
2021-01-04 12:00:04 +01:00
|
|
|
constructor(
|
|
|
|
|
private modalController: ModalController,
|
2022-01-29 19:33:32 +01:00
|
|
|
public ThemeService: ThemeService,
|
2024-08-16 17:17:32 +01:00
|
|
|
private contactsRepositoryService: ContactRepositoryService,
|
|
|
|
|
private httpErrorHandle: HttpErrorHandle,
|
|
|
|
|
private toastService: ToastService,
|
2024-08-19 16:01:58 +01:00
|
|
|
private chatServiceService: ChatServiceService
|
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
|
|
|
|
2024-08-16 17:17:32 +01:00
|
|
|
ngOnInit(): void {
|
|
|
|
|
this.loadUsers()
|
2021-01-04 12:00:04 +01:00
|
|
|
}
|
2023-05-19 12:00:51 +01:00
|
|
|
|
2024-08-16 17:17:32 +01:00
|
|
|
get hasMemberToUpload() {
|
|
|
|
|
return this.selectedUsers.length >= 1
|
|
|
|
|
}
|
2023-05-19 12:00:51 +01:00
|
|
|
|
2024-08-16 17:17:32 +01:00
|
|
|
async updateGroup() {
|
2023-05-19 12:00:51 +01:00
|
|
|
|
2024-08-16 17:17:32 +01:00
|
|
|
}
|
2023-09-22 17:25:27 +01:00
|
|
|
|
2024-08-16 17:17:32 +01:00
|
|
|
openGroupMessagesPage() {
|
|
|
|
|
// this.openGroupMessage.emit(this.roomId)
|
2021-01-13 15:49:58 +01:00
|
|
|
}
|
2021-01-04 12:00:04 +01:00
|
|
|
|
2024-08-16 17:17:32 +01:00
|
|
|
async loadUsers() {
|
2021-01-04 12:00:04 +01:00
|
|
|
|
2024-08-16 17:17:32 +01:00
|
|
|
this.loading = true
|
2024-09-18 11:47:23 +01:00
|
|
|
const getallChatUsers = await this.chatServiceService.getContactList()
|
2021-01-04 12:00:04 +01:00
|
|
|
|
|
|
|
|
|
2024-08-16 17:17:32 +01:00
|
|
|
if(getallChatUsers.isOk()) {
|
2021-01-04 12:00:04 +01:00
|
|
|
|
2024-09-18 11:47:23 +01:00
|
|
|
this.allChatUsers = getallChatUsers.value.sort((a,b) => {
|
2024-08-16 17:17:32 +01:00
|
|
|
if(a.wxFullName < b.wxFullName) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if(a.wxFullName > b.wxFullName) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
});
|
2021-01-04 12:00:04 +01:00
|
|
|
|
2021-07-23 14:43:51 +01:00
|
|
|
|
2024-08-16 17:17:32 +01:00
|
|
|
for(const user of this.allChatUsers) {
|
|
|
|
|
const firstLetter = user.wxFullName.charAt(0)
|
2021-01-14 16:51:16 +01:00
|
|
|
|
2024-08-16 17:17:32 +01:00
|
|
|
if(!this.userContainer[firstLetter]) {
|
|
|
|
|
user['isChecked'] = false
|
|
|
|
|
this.userContainer[firstLetter] = [user as any]
|
|
|
|
|
} else {
|
|
|
|
|
const userIds = this.userContainer[firstLetter].map( e => e.wxUserId)
|
|
|
|
|
if(!userIds.includes(user.wxUserId)) {
|
|
|
|
|
user['isChecked'] = false
|
|
|
|
|
this.userContainer[firstLetter].push(user as any)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-08-14 21:26:23 +01:00
|
|
|
|
|
|
|
|
|
2021-01-14 16:51:16 +01:00
|
|
|
}
|
2024-08-16 17:17:32 +01:00
|
|
|
else if (getallChatUsers.isErr() ) {
|
|
|
|
|
console.log(getallChatUsers.error)
|
|
|
|
|
} else {
|
|
|
|
|
this.toastService._badRequest("Pedimos desculpa mas não foi possível executar a acção. Por favor, contacte o apoio técnico.")
|
|
|
|
|
}
|
2023-08-15 10:15:08 +01:00
|
|
|
|
|
|
|
|
|
2024-08-16 17:17:32 +01:00
|
|
|
this.loading = false;
|
|
|
|
|
}
|
2023-08-14 21:26:23 +01:00
|
|
|
|
2024-08-16 17:17:32 +01:00
|
|
|
doRefresh(ev) {
|
|
|
|
|
ev.target.complete();
|
2021-01-14 16:51:16 +01:00
|
|
|
}
|
2022-07-08 14:17:22 +01:00
|
|
|
|
2024-08-16 17:17:32 +01:00
|
|
|
FilterUserListedByTextSearch() {
|
|
|
|
|
return this.allChatUsers.filter( e => e.wxFullName.toLowerCase().includes(this.textSearch.toLowerCase())).sort((a,b) => {
|
|
|
|
|
if(a.wxFullName < b.wxFullName) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if(a.wxFullName > b.wxFullName) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-09-22 17:25:27 +01:00
|
|
|
|
2021-07-23 14:43:51 +01:00
|
|
|
|
2024-08-16 17:17:32 +01:00
|
|
|
onChangeCheckBox(user: UserContacts & {isChecked: boolean}) {
|
|
|
|
|
if(user.isChecked) {
|
|
|
|
|
this.selectedUsers.push(user.wxUserId)
|
|
|
|
|
} else {
|
|
|
|
|
this.selectedUsers = this.selectedUsers.filter(e => e!= user.wxUserId)
|
|
|
|
|
}
|
2021-01-04 12:00:04 +01:00
|
|
|
}
|
2022-07-08 14:17:22 +01:00
|
|
|
|
2024-08-16 17:17:32 +01:00
|
|
|
onChange(event) {
|
|
|
|
|
this.textSearch = event.detail.value;
|
|
|
|
|
|
|
|
|
|
const filteredUserList: (UserContacts & {isChecked: boolean})[] = this.FilterUserListedByTextSearch() as any
|
2021-07-23 14:43:51 +01:00
|
|
|
|
2024-08-16 17:17:32 +01:00
|
|
|
const userContainer = {}
|
|
|
|
|
for(const user of filteredUserList) {
|
|
|
|
|
const firstLetter = user.wxFullName.charAt(0)
|
2023-07-15 11:01:09 +01:00
|
|
|
|
2024-08-16 17:17:32 +01:00
|
|
|
if(!userContainer[firstLetter]) {
|
|
|
|
|
user.isChecked = this.selectedUsers.includes(user.wxUserId)
|
|
|
|
|
userContainer[firstLetter] = [user]
|
|
|
|
|
} else {
|
|
|
|
|
user.isChecked = this.selectedUsers.includes(user.wxUserId)
|
|
|
|
|
userContainer[firstLetter].push(user)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
this.userContainer = userContainer
|
2021-01-04 12:00:04 +01:00
|
|
|
}
|
|
|
|
|
|
2024-08-16 17:17:32 +01:00
|
|
|
|
|
|
|
|
close() {
|
2024-10-07 13:27:49 +01:00
|
|
|
this.modalController.dismiss(null);
|
2024-08-16 17:17:32 +01:00
|
|
|
}
|
2024-08-19 16:01:58 +01:00
|
|
|
|
2024-09-18 11:47:23 +01:00
|
|
|
async select(user: UserContacts) {
|
2024-08-26 14:47:03 +01:00
|
|
|
|
2024-08-19 16:01:58 +01:00
|
|
|
|
2024-09-18 11:47:23 +01:00
|
|
|
// const result = await this.chatServiceService.sendMessage(message, RoomType.Direct)
|
|
|
|
|
|
|
|
|
|
const result = await this.chatServiceService.roomCreateLocalDirectMessage({
|
|
|
|
|
roomName: user.wxFullName,
|
|
|
|
|
receiverId: user.wxUserId,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if(result.isOk()) {
|
|
|
|
|
|
|
|
|
|
const room = await this.chatServiceService.roomGetLocalById({
|
|
|
|
|
$roomId: result.value
|
|
|
|
|
})
|
2024-08-19 16:01:58 +01:00
|
|
|
|
2024-09-18 11:47:23 +01:00
|
|
|
if(room.isOk()) {
|
2024-08-19 16:01:58 +01:00
|
|
|
|
2024-09-18 11:47:23 +01:00
|
|
|
this.modalController.dismiss(new RoomViewModel(room.value))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
2024-09-18 19:13:59 +01:00
|
|
|
const room = await this.chatServiceService.roomGetLocalById({
|
|
|
|
|
$roomId: user.wxUserId.toString()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if(room.isOk()) {
|
|
|
|
|
this.modalController.dismiss(new RoomViewModel(room.value))
|
|
|
|
|
}
|
2024-09-18 11:47:23 +01:00
|
|
|
}
|
2024-08-26 14:47:03 +01:00
|
|
|
|
2024-08-19 16:01:58 +01:00
|
|
|
}
|
2021-01-04 12:00:04 +01:00
|
|
|
}
|