Beispiel #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)})
Beispiel #2
0
def controlGetAllRoom():
    try:
        assert_login()
        rooms = service.getAllRoomsWithCheck(current_user)
        return jsonify({'success': 1, 'rooms': rooms})
    except Exception as e:
        print e
        return jsonify({'success': 0, 'error': str(e)})
Beispiel #3
0
def controlDeletePutContact(otherId):
    try:
        assert_login()
        if not service.removeContact(current_user, otherId):
            raise Exception(u'삭제에 실패했습니다')
        return jsonify({'success': 1})
    except Exception as e:
        print e
        return jsonify({'success': 0, 'error': str(e)})
Beispiel #4
0
def controlPostMessage(contactId):
    try:
        assert_login()
        json = request.get_json()
        content = json['content']
        message = service.create(current_user, contactId, content)
        return jsonify({'success': 1, 'message': message.serialize})
    except Exception as e:
        print e
        return jsonify({'success': 0, 'error': str(e)})
Beispiel #5
0
def controllPostContact():
    try:
        assert_login()
        json = request.get_json()
        phoneNumber = json['phoneNumber']
        name = json['name']
        other = service.createContact(current_user, name, phoneNumber)
        return jsonify({'success': 1, 'otherId': other.id})
    except Exception as e:
        print e
        return jsonify({'success': 0, 'error': str(e)})
Beispiel #6
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)})
Beispiel #7
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)})
Beispiel #8
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)})
Beispiel #9
0
def controlPostExitRoom(roomId):
    try:
        assert_login()

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

        service.exitRoom(current_user, room)
        return jsonify({'success': 1})
    except Exception as e:
        print e
        return jsonify({'success': 0, 'error': str(e)})
Beispiel #10
0
def controlGetContactsAll():
    try:
        args = request.args
        limit = int(args.get('limit', 999999))
        assert_login()
        return jsonify({
            'success':
            1,
            'contacts': [i.serialize for i in current_user.contacts[:limit]]
        })
    except Exception as e:
        print e
        return jsonify({'success': 0, 'error': str(e)})
Beispiel #11
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)})
Beispiel #12
0
def controlGetRoom(roomId):
    try:
        assert_login()

        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')

        service.userCheckRoom(current_user, room)

        return jsonify({
            'success': 1,
            'room': room.serialize,
            'messages': [i.serialize for i in room.messages]
        })
    except Exception as e:
        print e
        return jsonify({'success': 0, 'error': str(e)})