Esempio n. 1
0
def accept_friend():
    if not request.data:
        return INVALID_PARAM()
    
    req = json.loads(request.data)
    request_id = req.get('request_id')
    friend_uid = req.get('uid')
    if not request_id or not friend_uid:
        return INVALID_PARAM()
    
    friend_req = Friend.get_friend_request(g._db, request_id)
    if not friend_req:
        return INVALID_PARAM()

    if friend_req['uid'] != friend_uid or \
       friend_req['friend_uid'] != request.uid:
        return INVALID_PARAM()
    
    #添加双向的好友关系
    Friend.add_friend_relation(g._db, friend_req['uid'], friend_req['friend_uid'])
    
    sys_msg = {"friend":{"type":"accept", "uid":request.uid}}
    gobelieve.send_system_message(friend_req['uid'], json.dumps(sys_msg))
    
    return make_response(200, {"success":True})
Esempio n. 2
0
def delete_friend(friend_uid):
    uid = request.uid
    Friend.delete_friend_relation(g._db, uid, friend_uid)

    sys_msg = {"friend":{"type":"delete", "uid":uid}}
    gobelieve.send_system_message(friend_uid, json.dumps(sys_msg))
    
    return make_response(200, {"success":True})    
Esempio n. 3
0
def request_friend():
    uid = request.uid
    if not request.data:
        return INVALID_PARAM()
    
    req = json.loads(request.data)
    friend_uid = req.get('friend_uid')
    
    req_id = Friend.add_friend_request(g._db, uid, friend_uid)

    sys_msg = {"friend":{"request_id":req_id, "uid":uid, "type":"request"}}
    gobelieve.send_system_message(friend_uid, json.dumps(sys_msg))
    
    resp = {"request_id":req_id}
    return make_response(200, resp)
Esempio n. 4
0
def post_call():
    if not request.data:
        return INVALID_PARAM()
    
    req = json.loads(request.data)
    channel_id = req.get('channel_id', None)
    peer_uid = req.get('peer_uid', None)
    if not channel_id or not peer_uid:
        return INVALID_PARAM()

    
    uid = int(request.uid)
    now = int(time.time())

    c = {
        "channel_id":channel_id,
        "caller":uid,
        "callee":peer_uid,
        "timestamp":now
    }
    p = "你的朋友请求与你通话"
    obj = {
        "voip":c,
        "push":p,
        "sound":"apns.caf"
    }
    content = json.dumps(obj)

    r = gobelieve.send_system_message(peer_uid, content)
    logging.debug("send system message:%s", r)

    return make_response(200, {"success":True})
Esempio n. 5
0
def post_conferences():
    if not request.data:
        return INVALID_PARAM()
    
    req = json.loads(request.data)
    channel_id = req.get('channel_id', None)
    partipants = req.get('partipants', None)
    if not channel_id or not partipants:
        return INVALID_PARAM()
    
    uid = int(request.uid)
    now = int(time.time())

    c = {
        "channel_id":channel_id,
        "initiator":uid,
        "partipants":partipants,
        "timestamp":now
    }

    p = "你的朋友邀请你加入群视频通话"
    obj = {
        "conference":c,
        "push":p,
        "sound":"apns.caf"
    }
    content = json.dumps(obj)
    for pid in partipants:
        if pid == uid:
            continue
        r = gobelieve.send_system_message(pid, content)
        logging.debug("send system message:%s", r)

    return make_response(200, {"success":True})