Пример #1
0
def join(sid, data):
    user = data["user"]
    room_id = data["room_id"]
    sio.enter_room(sid, room_id)

    if not RoomService.exist_by_id(room_id):
        sio.emit("not_found_error", "room")
        sio.leave_room(sid, room_id)
        return

    if not UserService.exist_by_id(user["id"]):
        sio.emit("not_found_error", "user")
        sio.leave_room(sid, room_id)

    if ParticipantService.is_creator(room_id, user["id"]):
        participant = ParticipantService.by_room_id(room_id)
        data = {"participants": participant, "messages": []}
        sio.emit("user_connected", data, room=room_id)
        return

    if ParticipantService.exists_by_user_id_room_id(user["id"], room_id):
        sio.emit("conflict_error", "participant")
        sio.leave_room(sid, room_id)
        return

    ParticipantService.add(room_id, user["id"])

    participants = ParticipantService.by_room_id(room_id)
    messages = MessageService.by_room_id(room_id)

    data = {"participants": participants, "messages": messages}
    sio.emit("user_connected", data, room=room_id)
    return
Пример #2
0
def delete_user(user_id):

    if not UserService.exist_by_id(user_id):
        raise NotFoundException(pointer="user", message="not found")

    user = UserService.remove_by_id(user_id)
    return user.to_dict()
Пример #3
0
def create_room():
    body = body_validator(CreateRoomSchema)

    room_name = body["name"]
    creator = body["creator"]

    if not UserService.exist_by_id(creator):
        raise NotFoundException(pointer="user", message="not found")

    if RoomService.exist_by_id(room_name):
        raise ConflictException(pointer="room", message="exists")

    room = RoomService.add(room_name, creator)
    ParticipantService.add(room.id, creator, is_creator=True)

    return room.to_dict()