def create_group(): appid = request.appid obj = request.get_json(force=True, silent=True, cache=False) if obj is None: logging.debug("json decode err:%s", e) raise ResponseMeta(400, "json decode error") master = obj["master"] name = obj["name"] is_super = obj["super"] if "super" in obj else False members = obj["members"] if hasattr(request, 'uid') and request.uid != master: raise ResponseMeta(400, "master must be self") gid = 0 if config.EXTERNAL_GROUP_ID: gid = obj['group_id'] if 'group_id' in obj else 0 #支持members参数为对象数组 #[{uid:"", name:"", avatar:"可选"}, ...] memberIDs = [m['uid'] if type(m) == dict else m for m in members] if gid > 0: gid = Group.create_group_ext(g._db, gid, appid, master, name, is_super, memberIDs) else: gid = Group.create_group(g._db, appid, master, name, is_super, memberIDs) s = 1 if is_super else 0 content = { "group_id":gid, "app_id":appid, "super":s, "name":Group.GROUP_EVENT_CREATE } publish_message(g.rds, content) for mem in memberIDs: content = { "group_id":gid, "member_id":mem, "name":Group.GROUP_EVENT_MEMBER_ADD } publish_message(g.rds, content) v = { "group_id":gid, "master":master, "name":name, "members":members, "timestamp":int(time.time()) } op = {"create":v} send_group_notification(appid, gid, op, members) resp = {"data":{"group_id":gid}} return make_response(200, resp)
def create_group(): appid = request.appid obj = json.loads(request.data) master = obj["master"] name = obj["name"] is_super = obj["super"] if obj.has_key("super") else False members = obj["members"] if hasattr(request, 'uid') and request.uid != master: raise ResponseMeta(400, "master must be self") gid = 0 if config.EXTERNAL_GROUP_ID: gid = obj['group_id'] if obj.has_key('group_id') else 0 #支持members参数为对象数组 #[{uid:"", name:"", avatar:"可选"}, ...] memberIDs = map(lambda m: m['uid'] if type(m) == dict else m, members) if gid > 0: gid = Group.create_group_ext(g._db, gid, appid, master, name, is_super, memberIDs) else: gid = Group.create_group(g._db, appid, master, name, is_super, memberIDs) s = 1 if is_super else 0 content = "%d,%d,%d" % (gid, appid, s) publish_message(g.rds, "group_create", content) for mem in memberIDs: content = "%d,%d" % (gid, mem) publish_message(g.rds, "group_member_add", content) v = { "group_id": gid, "master": master, "name": name, "members": members, "timestamp": int(time.time()) } op = {"create": v} send_group_notification(appid, gid, op, members) resp = {"data": {"group_id": gid}} return make_response(200, resp)
def create_group(): appid = request.appid obj = json.loads(request.data) master = obj["master"] name = obj["name"] is_super = obj["super"] if obj.has_key("super") else False members = obj["members"] if hasattr(request, 'uid') and request.uid != master: raise ResponseMeta(400, "master must be self") gid = 0 if config.EXTERNAL_GROUP_ID: gid = obj['group_id'] if obj.has_key('group_id') else 0 #支持members参数为对象数组 #[{uid:"", name:"", avatar:"可选"}, ...] memberIDs = map(lambda m:m['uid'] if type(m) == dict else m, members) if gid > 0: gid = Group.create_group_ext(g._db, gid, appid, master, name, is_super, memberIDs) else: gid = Group.create_group(g._db, appid, master, name, is_super, memberIDs) s = 1 if is_super else 0 content = "%d,%d,%d"%(gid, appid, s) publish_message(g.rds, "group_create", content) for mem in memberIDs: content = "%d,%d"%(gid, mem) publish_message(g.rds, "group_member_add", content) v = { "group_id":gid, "master":master, "name":name, "members":members, "timestamp":int(time.time()) } op = {"create":v} send_group_notification(appid, gid, op, members) resp = {"data":{"group_id":gid}} return make_response(200, resp)