change detector for room list

This commit is contained in:
Peter Maquiran
2024-06-11 17:29:04 +01:00
parent 540cbbc911
commit 39bc8979a8
5 changed files with 51 additions and 28 deletions
@@ -14,7 +14,7 @@
</div>
<div>
<button class="btn-no-color adicionar" (click)="updateGroup()">
<ion-label>Adicionar bug</ion-label>
<ion-label>Adicionar</ion-label>
</button>
</div>
</div>
@@ -82,6 +82,8 @@ export class GroupContactsPage implements OnInit {
const getallChatUsers = await this.contactsRepositoryService.getUsers()
const getRoomById = await this.RoomRepositoryService.getRoomById(this.roomId)
console.log({getallChatUsers, getRoomById})
if(getallChatUsers.isOk() && getRoomById.isOk()) {
this.allChatUsers = getallChatUsers.value.data.result.sort((a,b) => {
@@ -96,6 +98,8 @@ export class GroupContactsPage implements OnInit {
const currentMemberToMap = await this.RoomRepositoryService.getRoomMemberById(this.roomId)
console.log({currentMemberToMap})
this.currentMembers = currentMemberToMap.map((e)=> ({
userPhoto: e.user.userPhoto,
wxeMail: e.user.wxeMail,
@@ -103,33 +107,41 @@ export class GroupContactsPage implements OnInit {
wxUserId: e.user.wxUserId
}))
const currentMemberIds = this.currentMembers.map(e => e.wxUserId)
const allSelectableUsers = this.allChatUsers.filter(e => !currentMemberIds.includes(e.wxUserId))
for(const user of allSelectableUsers) {
const firstLetter = user.wxFullName.charAt(0)
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)
}
}
}
}
else if (getRoomById.isErr() && getRoomById.error instanceof HttpResponse) {
this.httpErrorHandle.httpStatusHandle(getRoomById.error)
} else if (getallChatUsers.isErr() && getallChatUsers.error instanceof HttpResponse) {
this.httpErrorHandle.httpStatusHandle(getallChatUsers.error)
} else if (getRoomById.isErr() ) {
console.log(getRoomById.error)
} 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.")
}
const currentMemberIds = this.currentMembers.map(e => e.wxUserId)
const allSelectableUsers = this.allChatUsers.filter(e => !currentMemberIds.includes(e.wxUserId))
for(const user of allSelectableUsers) {
const firstLetter = user.wxFullName.charAt(0)
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)
}
}
}
this.showLoader = false;
}