mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
fix direct room
This commit is contained in:
@@ -3,6 +3,7 @@ import { BaseEntity } from "src/app/utils/entity";
|
||||
import { z } from "zod"
|
||||
import { MessageEntitySchema } from "./message";
|
||||
import { IDBoolean } from "src/app/infra/database/dexie/type";
|
||||
import { Logger } from "src/app/services/logger/main/service";
|
||||
|
||||
export enum RoomType {
|
||||
Group = 1,
|
||||
@@ -53,7 +54,7 @@ export class RoomEntity extends BaseEntity<RoomEntity>(RoomEntitySchema) implem
|
||||
createdAt: typeof RoomEntitySchema._input.createdAt
|
||||
expirationDate: typeof RoomEntitySchema._input.expirationDate
|
||||
roomType: typeof RoomEntitySchema._input.roomType
|
||||
members: typeof RoomEntitySchema._input.members
|
||||
members: typeof RoomEntitySchema._input.members = []
|
||||
messages: typeof RoomEntitySchema._input.messages
|
||||
receiverId: typeof RoomEntitySchema._input.receiverId
|
||||
|
||||
@@ -64,20 +65,30 @@ export class RoomEntity extends BaseEntity<RoomEntity>(RoomEntitySchema) implem
|
||||
if(data.roomType == RoomType.Direct) {
|
||||
this.setName()
|
||||
|
||||
if(!this.$id) {
|
||||
this.$id = this.getReceiverId()
|
||||
if(this.members.length == 2) {
|
||||
if(!this.$id ) {
|
||||
this.$id = this.getReceiverId()
|
||||
}
|
||||
|
||||
if(!this.receiverId ) {
|
||||
this.setReceiver()
|
||||
}
|
||||
}
|
||||
|
||||
if(!this.receiverId && this.members.length == 2) {
|
||||
this.setReceiver()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// direct room only
|
||||
getReceiverId() {
|
||||
const receiver = this.members?.find((e) => e.user.wxUserId != SessionStore.user.UserId)
|
||||
return receiver.user.wxUserId.toString()
|
||||
if(receiver) {
|
||||
return receiver.user.wxUserId.toString()
|
||||
} else {
|
||||
Logger.error('cant get receiver Id from Room.getReceiverId '+ this.id, this)
|
||||
return undefined
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// direct room only
|
||||
@@ -87,7 +98,13 @@ export class RoomEntity extends BaseEntity<RoomEntity>(RoomEntitySchema) implem
|
||||
|
||||
// direct room only
|
||||
setReceiver() {
|
||||
this.receiverId = parseInt(this.getReceiverId())
|
||||
const receiverId = this.getReceiverId()
|
||||
if(receiverId) {
|
||||
this.receiverId = parseInt(receiverId)
|
||||
} else {
|
||||
Logger.error('cant set receiver Id from Room.setReceiver', this)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// direct room only
|
||||
|
||||
Reference in New Issue
Block a user