mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
change room name for direct room
This commit is contained in:
@@ -1,4 +1,63 @@
|
||||
import { SessionStore } from "src/app/store/session.service";
|
||||
import { z } from "zod"
|
||||
|
||||
export enum RoomType {
|
||||
Group = 1,
|
||||
Direct = 2
|
||||
}
|
||||
|
||||
const UserSchema = z.object({
|
||||
wxUserId: z.number(),
|
||||
wxFullName: z.string(),
|
||||
wxeMail: z.string(),
|
||||
userPhoto: z.string().nullable(),
|
||||
});
|
||||
|
||||
const MemberSchema = z.object({
|
||||
id: z.string(),
|
||||
user: UserSchema,
|
||||
joinAt: z.string(),
|
||||
isAdmin: z.boolean()
|
||||
});
|
||||
|
||||
export const RoomEntitySchema = z.object({
|
||||
id: z.string(),
|
||||
roomName: z.string(),
|
||||
createdBy: z.object({
|
||||
wxUserId: z.number(),
|
||||
wxFullName: z.string(),
|
||||
wxeMail: z.string().email(),
|
||||
userPhoto: z.string().nullable().optional()// api check
|
||||
}),
|
||||
createdAt: z.any(),
|
||||
expirationDate: z.any().nullable(),
|
||||
roomType: z.nativeEnum(RoomType),
|
||||
members: z.array(MemberSchema).optional()
|
||||
})
|
||||
|
||||
export type IRoomEntity = z.infer<typeof RoomEntitySchema>
|
||||
|
||||
export class RoomEntity implements IRoomEntity{
|
||||
|
||||
id: typeof RoomEntitySchema._input.id
|
||||
roomName: typeof RoomEntitySchema._input.roomName
|
||||
createdBy: typeof RoomEntitySchema._input.createdBy
|
||||
createdAt: typeof RoomEntitySchema._input.createdAt
|
||||
expirationDate: typeof RoomEntitySchema._input.expirationDate
|
||||
roomType: typeof RoomEntitySchema._input.roomType
|
||||
members: typeof RoomEntitySchema._input.members
|
||||
|
||||
constructor(data: IRoomEntity) {
|
||||
Object.assign(this, data)
|
||||
if(data.roomType == RoomType.Direct) {
|
||||
this.setName()
|
||||
}
|
||||
}
|
||||
|
||||
setName() {
|
||||
const userChatName = this.members?.find((e) => e.user.wxUserId != SessionStore.user.UserId)
|
||||
if(userChatName) {
|
||||
this.roomName = userChatName.user.wxFullName
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user