Ejemplo n.º 1
0
def controlPostRoomInvite(roomId):
    try:
        assert_login()

        json = request.get_json()
        userIds = json['users']

        room = service.get(roomId)
        if not room:
            raise Exception(u'Room not found')

        if current_user not in room.users:
            raise Exception(u'Not authorized')

        users = []
        for userId in userIds:
            user = userService.get(userId)
            if user and (user in current_user.contacts):
                users.append(user)

        service.inviteMany(room, users)
        return jsonify({'success': 1})
    except Exception as e:
        print e
        return jsonify({'success': 0, 'error': str(e)})
Ejemplo n.º 2
0
def controlGetMessages(contactId):
    try:
        assert_login()
        messages = service.find_all(current_user, contactId)
        other = userService.get(contactId)
        if not other:
            raise Exception(u'존재하지 않는 유저입니다')
        return jsonify({'success': 1, 'messages': [i.serialize for i in messages], \
            'user': other.serialize})
    except Exception as e:
        print e
        return jsonify({'success': 0, 'error': str(e)})
Ejemplo n.º 3
0
def controlGetOneToOneRoom(contactId):
    try:
        assert_login()
        contact_user = userService.get(contactId)
        if not contact_user:
            raise Exception(u'Contact user not found')

        room = service.getOneToOneRoom(current_user, contact_user)
        return jsonify({'success': 1, 'room': room.serialize})
    except Exception as e:
        print e
        return jsonify({'success': 0, 'error': str(e)})
Ejemplo n.º 4
0
def controlGetContact(contactId):
    try:
        assert_login()
        contact = service.get(contactId)
        if not contact:
            raise u'잘못된 사용자 번호입니다'
        if contact not in current_user.contacts and current_user.id != contactId:
            raise u'접근이 불가합니다'
        return jsonify({'success': 1, 'contact': contact.serialize})
    except Exception as e:
        print e
        return jsonify({'success': 0, 'error': str(e)})
Ejemplo n.º 5
0
def make_one_to_one_room_name(token, contactId):
    current_user = userService.findByToken(token)
    if not current_user:
        raise Exception(u'User not found')
    contact_user = userService.get(contactId)
    if not contact_user:
        raise Exception(u'Contact not found')

    firstId = current_user.id
    secondId = contact_user.id

    if firstId > secondId:
        firstId, secondId = secondId, firstId

    return current_user, contact_user, '{}:{}'.format(firstId, secondId)
Ejemplo n.º 6
0
def controlPostRoom():
    try:
        assert_login()

        json = request.get_json()
        name = json['name']
        userIds = json['users']
        users = []

        for userId in userIds:
            user = userService.get(userId)
            if not user:
                raise Exception(u'User not found')
            users.append(user)

        room = service.create(name, current_user, users)
        return jsonify({'success': 1, 'room': room.serialize})
    except Exception as e:
        print e
        return jsonify({'success': 0, 'error': str(e)})