mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
change detector for room list
This commit is contained in:
+2
-2
@@ -82,9 +82,9 @@ export class RoomLocalDataSourceService {
|
||||
const createResult = await this.createRoom(data)
|
||||
|
||||
if(createResult.isOk()) {
|
||||
return this.updateRoom(data)
|
||||
} else {
|
||||
return createResult
|
||||
} else {
|
||||
return this.updateRoom(data)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ export const RoomOutPutDTOSchema = z.object({
|
||||
data: z.object({
|
||||
id: z.string(),
|
||||
roomName: z.string(),
|
||||
createdBy: z.any(),
|
||||
createdBy: z.any().nullable(),
|
||||
createdAt: z.string(),
|
||||
expirationDate: z.string().nullable(),
|
||||
roomType: z.any()
|
||||
|
||||
@@ -11,6 +11,7 @@ import { UserRemoveListInputDTO } from '../dto/room/userRemoveListInputDTO';
|
||||
import { roomMemberListDetermineChanges } from '../async/rooms/roomMembersChangeDetector';
|
||||
import { captureAndReraiseAsync } from 'src/app/services/decorators/captureAndReraiseAsync';
|
||||
import { RoomUpdateInputDTO } from '../dto/room/roomUpdateInputDTO';
|
||||
import { SessionStore } from 'src/app/store/session.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -64,17 +65,19 @@ export class RoomRepositoryService {
|
||||
const result = await this.roomRemoteDataSourceService.getRoom(id)
|
||||
|
||||
if(result.isOk()) {
|
||||
|
||||
const localListRoom = await this.roomLocalDataSourceService.getRoomList()
|
||||
const { roomsToDelete, roomsToInsert, roomsToUpdate } = roomListDetermineChanges([result.value.data], localListRoom)
|
||||
|
||||
for( const roomData of roomsToUpdate) {
|
||||
this.roomLocalDataSourceService.updateRoom(roomData)
|
||||
}
|
||||
|
||||
// ============================
|
||||
const localList = await this.roomLocalDataSourceService.getRoomMemberById(id)
|
||||
|
||||
const { membersToInsert, membersToUpdate, membersToDelete } = roomMemberListDetermineChanges(result.value.data.members, localList, id)
|
||||
|
||||
|
||||
const a = await this.roomLocalDataSourceService.createOrUpdateRoom(result.value.data)
|
||||
|
||||
if(a.isErr()) {
|
||||
return a
|
||||
}
|
||||
|
||||
for (const user of membersToInsert) {
|
||||
this.roomLocalDataSourceService.addMember({...user, roomId:id})
|
||||
}
|
||||
@@ -94,6 +97,14 @@ export class RoomRepositoryService {
|
||||
const result = await this.roomRemoteDataSourceService.createRoom(data)
|
||||
if(result.isOk()) {
|
||||
|
||||
if(!result.value.data.createdBy) {
|
||||
result.value.data.createdBy = {
|
||||
wxeMail: SessionStore.user.Email,
|
||||
wxFullName: SessionStore.user.FullName,
|
||||
wxUserId: SessionStore.user.UserId
|
||||
}
|
||||
}
|
||||
|
||||
this.roomMemoryDataSourceService.dispatch(addRoom(result.value))
|
||||
this.roomLocalDataSourceService.createRoom(result.value.data)
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user