Przeglądaj źródła

增加助手权限

gemercheung 2 lat temu
rodzic
commit
bc3d8fadaf

+ 33 - 6
src/room/actions/actions.service.ts

@@ -21,15 +21,32 @@ export class ActionsService {
         this.roomService._userInfo.Role === 'leader'
       );
     };
+    const isAssistant = async () => {
+      const roomId = socket.data.user?.RoomId;
+      const UserId = socket.data.user?.UserId;
+      if (roomId && UserId) {
+        const user = await this.userService.getUsersBy(roomId, UserId);
+        if (user?.IsAssistant) {
+          return Promise.resolve(true);
+        } else {
+          return Promise.resolve(false);
+        }
+      } else {
+        return Promise.resolve(false);
+      }
+    };
     let roomId = socket.data.user?.RoomId;
+    const assistant = await isAssistant();
+
     if (!roomId) {
       roomId = this.roomService._userInfo.RoomId;
       this.roomService.logger.error(
         `当前-socket丟失参数-action::${roomId}`,
         'handleAllAction',
       );
+      return;
     }
-
+    this.roomService.logger.warn(`当前-socket-是否助手::${assistant}`);
     this.roomService.logger.warn(
       `当前--broadcast:${roomId}, data:${JSON.stringify(data)}action:${data.type
       } ,isLeader:${isSocketLeader()}`,
@@ -48,24 +65,34 @@ export class ActionsService {
       case 'users-muted':
         const mutedParams = data as any as MutedStateType;
         mutedParams.roomId = roomId;
-        isSocketLeader() && (await this.handleMutedState(mutedParams));
+
+        if (isSocketLeader() || assistant) {
+          await this.handleMutedState(mutedParams);
+        }
+
         await this.roomService.handleRoomStatusAction(socket);
         break;
       case 'users-words':
         const typingParams = data as any as TypingStateType;
         typingParams.roomId = roomId;
-        isSocketLeader() && (await this.handleTypingState(typingParams));
+
+        if (isSocketLeader() || assistant) {
+          await this.handleTypingState(typingParams);
+        }
         this.roomService.handleRoomStatusAction(socket);
         await this.roomService.handleRoomStatusAction(socket);
         break;
       case 'users-kicked':
         const kickParams = data as any as KickStateType;
-        isSocketLeader() && (await this.handleKickState(socket, kickParams));
+        if (isSocketLeader() || assistant) {
+          await this.handleKickState(socket, kickParams);
+        }
         break;
       case 'set-assistant':
         const assistantParams = data as any as SetAssistantType;
-        isSocketLeader() &&
-          (await this.handleSetAssitant(socket, assistantParams));
+        if (isSocketLeader() || assistant) {
+          await this.handleSetAssitant(socket, assistantParams);
+        }
         break;
       default:
         break;

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

@@ -21,7 +21,7 @@ export class DelayService {
     @Inject(forwardRef(() => RoomService))
     public readonly roomService: RoomService,
     public readonly tempService: TempService,
-  ) { }
+  ) {}
 
   async init(): Promise<void> {
     const redisDB = this.configService.get<string>('REDIS_DB');

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

@@ -17,7 +17,7 @@ export class RoomService {
     private readonly actionsService: ActionsService,
     private readonly delayService: DelayService,
     private readonly tempService: TempService,
-  ) { }
+  ) {}
   public readonly logger = new Logger('user');
   public _sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
   public _userInfo = {} as UserInfoType;
@@ -369,7 +369,6 @@ export class RoomService {
     const assistant = await this.userService.getUsersBy(roomId, userId);
     assistant.IsAssistant = !assistant.IsAssistant;
     const data = assistant;
-    console.log('update-assistant', data);
     const updated = await this.userService.updateUsers(data);
     if (updated) {
       this.handleRoomStatusAction(socket);

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

@@ -10,7 +10,7 @@ export class UsersService {
     @InjectRedis() private readonly redis: Redis,
     @Inject(forwardRef(() => RoomService))
     private roomService: RoomService,
-  ) { }
+  ) {}
 
   async isUserInRooms(RoomId: string, UserId: string): Promise<boolean> {
     const res = await this.redis.hexists(

+ 3 - 2
src/socket/socket.gateway.ts

@@ -34,12 +34,13 @@ console.log('SOCKET_USE_MSPACK', process.env.SOCKET_USE_MSPACK);
       : '',
 })
 export class SocketGateway
-  implements OnGatewayInit, OnGatewayDisconnect, OnGatewayConnection {
+  implements OnGatewayInit, OnGatewayDisconnect, OnGatewayConnection
+{
   constructor(
     @InjectRedis() private readonly redis: Redis,
     private readonly roomService: RoomService,
     private readonly delayService: DelayService,
-  ) { }
+  ) {}
   public readonly logger = new Logger('socketGateway');
   @WebSocketServer() server: Server;
   // public _loginLimit = new Map<string, string>();