Exemplo n.º 1
0
 def _accept():
     """Accept the request"""
     get_members_query = Query.get_room_members(roomname)
     room_members: str = self.db.read_execute_query(
         get_members_query)[0][0]
     add_member_query = Query.add_member(roomname, username,
                                         room_members)
     self.db.execute_query(add_member_query)
Exemplo n.º 2
0
    def add_member(self, roomname: str, username: str) -> bool:
        """ Add a user to the room
        Args:
            roomname (str): Name of the room to add user to
            username (str): User to add to room
        Returns:
            bool: True if successfully added, False if not added 
        """

        try:
            room_exists = self.room_exists(roomname)

            if room_exists:
                get_members_query = Query.get_room_members(roomname)
                room_members: str = self.db.read_execute_query(
                    get_members_query)[0][0]
                room_members_list = room_members.split()

                if username in room_members_list:
                    self.logger.warning(
                        f"User '{username}' is already a part of room {roomname}"
                    )
                    return False

                else:
                    add_member_query = Query.add_member(
                        roomname, username, room_members)
                    self.db.execute_query(add_member_query)
                    self.logger.info(f"User '{username}' added to {roomname}")
                    return True

            else:
                self.logger.error(f"Room '{roomname}' does not exist")
                return False

        except:
            self.logger.error(f"Failed to add '{username}' to '{roomname}'")
            return False