def delFriend(): uid = int(request.form.get("uid", "0")) del_uid = int(request.form.get("del_uid", "0")) service.delFriend(uid, del_uid) sendMsg( [uid], { 'type': 'init', 'data': { 'people': service.getFriendsInfo(uid), 'pub_keys': service.getPubKeys(), 'time': time.strftime('%H:%M:%S', time.localtime()), 'people_num': len(service.WS_POOL) } }) sendMsg( [del_uid], { 'type': 'init', 'data': { 'people': service.getFriendsInfo(del_uid), 'pub_keys': service.getPubKeys(), 'time': time.strftime('%H:%M:%S', time.localtime()), 'people_num': len(service.WS_POOL) } }) rst = make_response(jsonify({"done": 1})) rst.headers['Access-Control-Allow-Origin'] = '*' return rst, 200
def findUser(): uid = int(request.form.get("uid", "0")) s_uid = int(request.form.get("search_uid", "0")) s_name = request.form.get("search_name", "") if s_uid == 0 and s_name == '': print('err: param err: invalid uid and username') return resp.ReplyFail(resp.PARAM_ERR_CODE, resp.ParamErr) user_infos = {} if s_name != '': infos = mongo.getUserInfoByFuzzyName(name=s_name) if infos is None: print("info: user is not exist code:{} username:{}".format( resp.NOT_EXISTED_ERR_CODE, resp.NotExistedErr, s_name)) # 解决跨域问题 rst = make_response(jsonify({"not_exist": 0})) rst.headers['Access-Control-Allow-Origin'] = '*' return rst, 200 # return resp.ReplyFail(resp.NOT_EXISTED_ERR_CODE, resp.NotExistedErr) for info in infos: print(info) user_infos[info["_id"]] = { "name": info["name"], "avatar": info["avatar"] } elif s_uid != 0: info = mongo.getUserInfoByUId(uid=s_uid) if info is None: print("info: user is not exist code:{} uid:{}".format( resp.NOT_EXISTED_ERR_CODE, resp.NotExistedErr, s_uid)) rst = make_response(jsonify({"not_exist": 0})) rst.headers['Access-Control-Allow-Origin'] = '*' return rst, 200 # return resp.ReplyFail(resp.NOT_EXISTED_ERR_CODE, resp.NotExistedErr) user_infos[info["_id"]] = { "name": info["name"], "avatar": info["avatar"] } users = {} for id, info in user_infos.items(): label = mongo.getLabelInUserRelationTmp(uid, int(id)) if label is not None: info['is_friend'] = True info['label'] = label info['online'] = True if service.WS_POOL.get( id, None) is not None else False else: # TODO info['is_friend'] = False users[id] = info print("info search: uid{} result:{}".format(uid, { "type": "search", "data": users })) sendMsg([int(uid)], {"type": "search", "data": users}) rst = make_response(jsonify({"exist": 1})) rst.headers['Access-Control-Allow-Origin'] = '*' return rst, 200
def agreeAddFr(): uid = int(request.form.get('uid', '0')) fid = int(request.form.get('fid', '0')) label = request.form.get('label', "Default") ok = request.form.get('is_agree', 'no') is_agree = True if ok == "yes" else False flag = service.updateRelation(uid, fid, label, is_agree) if not flag: rst = make_response() rst.headers['Access-Control-Allow-Origin'] = '*' return rst, 403 info = mongo.getUserInfoByUId(uid) ret = sendMsg([fid], { "data": { "uid": uid, "agree": ok, "name": info['name'] }, "type": "agree" }) if ret is None: rst = make_response() rst.headers['Access-Control-Allow-Origin'] = '*' return rst, 403 print("info: uid:{} f_uid:{} friend relation:{} ".format( uid, fid, is_agree)) rst = make_response() rst.headers['Access-Control-Allow-Origin'] = '*' return rst, 200