mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
fix chat estracture
This commit is contained in:
@@ -2,18 +2,18 @@ import { TableRoom } from "../../../data-source/room/rooom-local-data-source.ser
|
||||
import { RoomListItemOutPutDTO, RoomListOutPutDTO } from "../../../dto/room/roomListOutputDTO";
|
||||
|
||||
export function roomListDetermineChanges(serverRooms: RoomListItemOutPutDTO[], localRooms: TableRoom[]) {
|
||||
const serverRoomMap = new Map(serverRooms.map(room => [room.id, room]));
|
||||
const serverRoomMap = new Map(serverRooms.map(room => [room.chatRoom.id, room]));
|
||||
const localRoomMap = new Map(localRooms.map(room => [room.id, room]));
|
||||
|
||||
const roomsToInsert = serverRooms.filter(room => !localRoomMap.has(room.id));
|
||||
const roomsToInsert = serverRooms.filter(room => !localRoomMap.has(room.chatRoom.id));
|
||||
const roomsToUpdate = serverRooms.filter(room => {
|
||||
const localRoom = localRoomMap.get(room.id);
|
||||
const localRoom = localRoomMap.get(room.chatRoom.id);
|
||||
return localRoom && (
|
||||
room.roomName !== localRoom.roomName ||
|
||||
room.createdBy.wxUserId !== localRoom.createdBy.wxUserId ||
|
||||
room.createdAt !== localRoom.createdAt ||
|
||||
room.expirationDate !== localRoom.expirationDate ||
|
||||
room.roomType !== localRoom.roomType
|
||||
room.chatRoom.roomName !== localRoom.roomName ||
|
||||
room.chatRoom.createdBy.wxUserId !== localRoom.createdBy.wxUserId ||
|
||||
room.chatRoom.createdAt !== localRoom.createdAt ||
|
||||
room.chatRoom.expirationDate !== localRoom.expirationDate ||
|
||||
room.chatRoom.roomType !== localRoom.roomType
|
||||
);
|
||||
});
|
||||
const roomsToDelete = localRooms.filter(room => !serverRoomMap.has(room.id));
|
||||
|
||||
@@ -23,7 +23,7 @@ export class MessageAsyncService {
|
||||
filter((message: any) => {
|
||||
return !message?.requestId?.startsWith(InstanceId) && message?.requestId
|
||||
})
|
||||
).subscribe(async (message: any) => {
|
||||
).subscribe(async (message) => {
|
||||
|
||||
console.log('message async ', message)
|
||||
|
||||
|
||||
@@ -75,6 +75,7 @@ export class MessageLocalDataSourceService {
|
||||
|
||||
async getLastMessageByRoomId(roomId: string): Promise<Result<undefined|TableMessage, any>> {
|
||||
try {
|
||||
console.log({roomId})
|
||||
const lastMessage = await messageDataSource.message
|
||||
.where('roomId')
|
||||
.equals(roomId)
|
||||
@@ -107,7 +108,7 @@ export class MessageLocalDataSourceService {
|
||||
}
|
||||
|
||||
|
||||
// @ValidateSchema(tableSchema)
|
||||
// @ValidateSchema(tableSchema)
|
||||
async createMessage(data: MessageInputDTO) {
|
||||
|
||||
try {
|
||||
|
||||
@@ -179,6 +179,10 @@ export class RoomLocalDataSourceService {
|
||||
return await roomDataSource.room.toArray()
|
||||
}
|
||||
|
||||
getMemberLive(data: {roomId, wxUserId}) {
|
||||
const $roomIdUserId = data.roomId + data.wxUserId
|
||||
return liveQuery(() => roomDataSource.memberList.get($roomIdUserId)) as any;
|
||||
}
|
||||
|
||||
getItemsLive(): Observable<RoomListOutPutDTO[]> {
|
||||
return liveQuery(() => roomDataSource.room.toArray()) as any;
|
||||
|
||||
+6
-2
@@ -11,8 +11,12 @@ export class UserTypingLiveDataSourceService {
|
||||
private SignalRLiveDataSourceService: SignalRService
|
||||
) { }
|
||||
|
||||
sendTyping(roomId) {
|
||||
return this.SignalRLiveDataSourceService.sendTyping({roomId, UserName:SessionStore.user.FullName})
|
||||
sendTyping(roomId, ) {
|
||||
return this.SignalRLiveDataSourceService.sendTyping({
|
||||
roomId,
|
||||
UserName:SessionStore.user.FullName,
|
||||
userId:SessionStore.user.UserId
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ const MemberSchema = z.object({
|
||||
id: z.string(),
|
||||
user: UserSchema,
|
||||
joinAt: z.string(),
|
||||
isAdmin: z.boolean()
|
||||
});
|
||||
|
||||
export const RoomByIdOutputDTOSchema = z.object({
|
||||
@@ -27,6 +28,5 @@ export const RoomByIdOutputDTOSchema = z.object({
|
||||
}),
|
||||
})
|
||||
|
||||
|
||||
export type RoomByIdMemberItemOutputDTO = z.infer<typeof MemberSchema>
|
||||
export type RoomByIdOutputDTO = z.infer<typeof RoomByIdOutputDTOSchema>
|
||||
export type RoomByIdOutputDTO = z.infer<typeof RoomByIdOutputDTOSchema>
|
||||
@@ -8,12 +8,16 @@ const CreatedBySchema = z.object({
|
||||
});
|
||||
|
||||
const RoomListItemOutPutDTOSchema = z.object({
|
||||
id: z.string(),
|
||||
roomName: z.string(),
|
||||
createdBy: CreatedBySchema,
|
||||
createdAt: z.string(),
|
||||
expirationDate: z.string().nullable(), // api check
|
||||
roomType: z.number()
|
||||
|
||||
chatRoom: z.object({
|
||||
id: z.string(),
|
||||
roomName: z.string(),
|
||||
createdBy: CreatedBySchema,
|
||||
createdAt: z.string(),
|
||||
expirationDate: z.string().nullable(), // api check
|
||||
roomType: z.number()
|
||||
}),
|
||||
joinAt: z.string()
|
||||
})
|
||||
|
||||
|
||||
|
||||
@@ -42,7 +42,8 @@ export class MessageRepositoryService {
|
||||
|
||||
data['requestId'] = InstanceId +'@'+ uuidv4();
|
||||
|
||||
const localActionResult = await this.messageLocalDataSourceService.sendMessage(data)
|
||||
const localActionResult = await this.messageLocalDataSourceService.sendMessage({...data})
|
||||
console.log('create message', data)
|
||||
|
||||
// this.messageLiveDataSourceService.sendMessage({
|
||||
// type: 'sendMessage',
|
||||
@@ -63,17 +64,20 @@ export class MessageRepositoryService {
|
||||
delete sendMessageResult.value.sender
|
||||
}
|
||||
|
||||
let clone: TableMessage = {
|
||||
...sendMessageResult.value,
|
||||
messageId: sendMessageResult.value.id,
|
||||
id : localActionResult.value
|
||||
}
|
||||
// let clone: TableMessage = {
|
||||
// ...sendMessageResult.value,
|
||||
// messageId: sendMessageResult.value.id,
|
||||
// id : localActionResult.value
|
||||
// }
|
||||
|
||||
return this.messageLocalDataSourceService.update({...clone, sending: false})
|
||||
// console.log({clone})
|
||||
console.log('update message')
|
||||
//return this.messageLocalDataSourceService.update({...clone, sending: false})
|
||||
return ok(true)
|
||||
}
|
||||
|
||||
} else {
|
||||
return this.messageLocalDataSourceService.update({sending: false})
|
||||
// return this.messageLocalDataSourceService.update({sending: false})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +86,7 @@ export class MessageRepositoryService {
|
||||
if(result.isOk()) {
|
||||
if(result.value) {
|
||||
|
||||
return await this.messageLiveSignalRDataSourceService.sendReadAt({roomId, memberId: SessionStore.user.UserId, chatMessageId: result.value.messageId})
|
||||
// return await this.messageLiveSignalRDataSourceService.sendReadAt({roomId, memberId: SessionStore.user.UserId, chatMessageId: result.value.messageId})
|
||||
}
|
||||
return ok(true)
|
||||
}
|
||||
@@ -116,6 +120,14 @@ export class MessageRepositoryService {
|
||||
}
|
||||
|
||||
sendTyping(roomId) {
|
||||
return this.messageLiveSignalRDataSourceService.sendTyping({roomId, UserName:SessionStore.user.FullName})
|
||||
return this.messageLiveSignalRDataSourceService.sendTyping({
|
||||
roomId,
|
||||
UserName:SessionStore.user.FullName,
|
||||
userId: SessionStore.user.UserId
|
||||
})
|
||||
}
|
||||
|
||||
getMemberByLive({roomId, userId}) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ export class RoomRepositoryService {
|
||||
// },
|
||||
// }
|
||||
|
||||
this.roomLocalDataSourceService.createRoom(roomData)
|
||||
this.roomLocalDataSourceService.createRoom(roomData.chatRoom)
|
||||
}
|
||||
|
||||
for( const roomData of roomsToUpdate) {
|
||||
@@ -78,7 +78,7 @@ export class RoomRepositoryService {
|
||||
// },
|
||||
// }
|
||||
|
||||
this.roomLocalDataSourceService.updateRoom(roomData)
|
||||
this.roomLocalDataSourceService.updateRoom(roomData.chatRoom)
|
||||
}
|
||||
|
||||
for( const roomData of roomsToDelete) {
|
||||
@@ -105,15 +105,15 @@ export class RoomRepositoryService {
|
||||
|
||||
if(result.isOk()) {
|
||||
const localList = await this.roomLocalDataSourceService.getRoomList()
|
||||
const { roomsToDelete, roomsToInsert, roomsToUpdate } = roomListDetermineChanges([result.value.data], localList)
|
||||
// const { roomsToDelete, roomsToInsert, roomsToUpdate } = roomListDetermineChanges([result.value.data], localList)
|
||||
|
||||
for( const roomData of roomsToUpdate) {
|
||||
if(!roomData.createdBy?.wxUserId) {
|
||||
delete roomData.createdBy;
|
||||
}
|
||||
// for( const roomData of roomsToUpdate) {
|
||||
// if(!roomData.chatRoom.createdBy?.wxUserId) {
|
||||
// delete roomData.chatRoom.createdBy;
|
||||
// }
|
||||
|
||||
this.roomLocalDataSourceService.updateRoom(roomData)
|
||||
}
|
||||
// this.roomLocalDataSourceService.updateRoom(roomData.chatRoom)
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -127,10 +127,13 @@ export class RoomRepositoryService {
|
||||
if(result.isOk()) {
|
||||
|
||||
const localListRoom = await this.roomLocalDataSourceService.getRoomList()
|
||||
const { roomsToDelete, roomsToInsert, roomsToUpdate } = roomListDetermineChanges([result.value.data], localListRoom)
|
||||
const object = {
|
||||
chatRoom: result.value.data
|
||||
}
|
||||
const { roomsToDelete, roomsToInsert, roomsToUpdate } = roomListDetermineChanges([object], localListRoom)
|
||||
|
||||
for( const roomData of roomsToUpdate) {
|
||||
this.roomLocalDataSourceService.updateRoom(roomData)
|
||||
this.roomLocalDataSourceService.updateRoom(roomData.chatRoom)
|
||||
}
|
||||
|
||||
// ============================
|
||||
|
||||
Reference in New Issue
Block a user