gemercheung 2 years ago
parent
commit
549fd7f8e3

+ 1 - 1
src/room/actions/actions.service.ts

@@ -127,7 +127,7 @@ export class ActionsService {
     if (data) {
     if (data) {
       const roomId = socket.data.user.RoomId || '';
       const roomId = socket.data.user.RoomId || '';
       const userId = data.userId;
       const userId = data.userId;
-      await this.roomService.handleKickAction(roomId, userId);
+      await this.roomService.handleSetRoomAssitant(socket, roomId, userId);
     }
     }
   }
   }
 }
 }

+ 5 - 3
src/room/room.service.ts

@@ -41,6 +41,7 @@ export class RoomService {
       JoinTime: Date.now(),
       JoinTime: Date.now(),
       InTime: Date.now(),
       InTime: Date.now(),
       IsOnline: true,
       IsOnline: true,
+      IsAssistant: false,
     };
     };
     return data;
     return data;
   }
   }
@@ -357,11 +358,12 @@ export class RoomService {
     socket: Socket,
     socket: Socket,
     roomId: string,
     roomId: string,
     userId: string,
     userId: string,
-    status: boolean,
   ): Promise<boolean> {
   ): Promise<boolean> {
     const assistant = await this.userService.getUsersBy(roomId, userId);
     const assistant = await this.userService.getUsersBy(roomId, userId);
-    assistant.IsOnline = status;
-    const updated = await this.userService.updateUsers(assistant);
+    assistant.IsAssistant = !assistant.IsAssistant;
+    const data = assistant;
+    console.log('update-assistant', data);
+    const updated = await this.userService.updateUsers(data);
     if (updated) {
     if (updated) {
       this.handleRoomStatusAction(socket);
       this.handleRoomStatusAction(socket);
     }
     }

+ 1 - 0
src/room/user.d.ts

@@ -12,6 +12,7 @@ interface UserInfoType {
   InTime?: Timestamp;
   InTime?: Timestamp;
   Order?: number;
   Order?: number;
   IsOnline?: boolean;
   IsOnline?: boolean;
+  IsAssistant: boolean;
 }
 }
 
 
 interface UserInfoParams {
 interface UserInfoParams {

+ 6 - 1
src/room/users/users.service.ts

@@ -10,7 +10,7 @@ export class UsersService {
     @InjectRedis() private readonly redis: Redis,
     @InjectRedis() private readonly redis: Redis,
     @Inject(forwardRef(() => RoomService))
     @Inject(forwardRef(() => RoomService))
     private roomService: RoomService,
     private roomService: RoomService,
-  ) {}
+  ) { }
 
 
   async isUserInRooms(RoomId: string, UserId: string): Promise<boolean> {
   async isUserInRooms(RoomId: string, UserId: string): Promise<boolean> {
     const res = await this.redis.hexists(
     const res = await this.redis.hexists(
@@ -61,13 +61,18 @@ export class UsersService {
       useInfo.UserId,
       useInfo.UserId,
     );
     );
     const userObj = JSON.parse(user) as any as UserInfoType;
     const userObj = JSON.parse(user) as any as UserInfoType;
+
     if (userObj.Role === useInfo.Role) {
     if (userObj.Role === useInfo.Role) {
       const updateInfo: UserInfoType = Object.assign({}, userObj, {
       const updateInfo: UserInfoType = Object.assign({}, userObj, {
         JoinTime: useInfo.JoinTime,
         JoinTime: useInfo.JoinTime,
         InTime: useInfo.InTime,
         InTime: useInfo.InTime,
         Avatar: useInfo.Avatar,
         Avatar: useInfo.Avatar,
         Nickname: useInfo.Nickname,
         Nickname: useInfo.Nickname,
+        IsAssistant: useInfo.IsAssistant,
       });
       });
+      if (useInfo.IsAssistant) {
+        updateInfo.Order = 1;
+      }
       await this.redis.hset(
       await this.redis.hset(
         `kankan:socket:rooms:${useInfo.RoomId}`,
         `kankan:socket:rooms:${useInfo.RoomId}`,
         useInfo.UserId,
         useInfo.UserId,