Ejemplo n.º 1
0
def add_group_member(gid):
    appid = request.appid
    obj = json.loads(request.data)
    inviter = None
    if type(obj) is dict:
        if 'members' in obj:
            members = obj['members']
            inviter = obj.get('inviter')
        else:
            members = [obj]
    else:
        members = obj

    if len(members) == 0:
        return ""
    
    group = Group.get_group(g._db, gid)
    if not group:
        raise ResponseMeta(400, "group non exists")
    
    # 支持members参数为对象数组
    memberIDs = map(lambda m:m['uid'] if type(m) == dict else m, members)
    
    g._db.begin()
    for member_id in memberIDs:
        try:
            Group.add_group_member(g._db, gid, member_id)
            # 可能是重新加入群
            User.reset_group_synckey(g.rds, appid, member_id, gid)
        except umysql.SQLError, e:
            #1062 duplicate member
            if e[0] != 1062:
                raise
Ejemplo n.º 2
0
def add_group_member(gid):
    appid = request.appid
    obj = json.loads(request.data)
    inviter = None
    if type(obj) is dict:
        if 'members' in obj:
            members = obj['members']
            inviter = obj.get('inviter')
        else:
            members = [obj]
    else:
        members = obj

    if len(members) == 0:
        return ""

    group = Group.get_group(g._db, gid)
    if not group:
        raise ResponseMeta(400, "group non exists")

    # 支持members参数为对象数组
    memberIDs = map(lambda m: m['uid'] if type(m) == dict else m, members)

    g._db.begin()
    for member_id in memberIDs:
        try:
            Group.add_group_member(g._db, gid, member_id)
            User.reset_group_synckey(g.rds, appid, member_id, gid)
        except pymysql.err.IntegrityError, e:
            # 可能是重新加入群
            # 1062 duplicate member
            if e[0] != 1062:
                raise
Ejemplo n.º 3
0
def add_group_member(gid):
    appid = request.appid
    obj = json.loads(request.data)
    if type(obj) is dict:
        members = [obj["uid"]]
    else:
        members = obj

    if len(members) == 0:
        return ""

    #支持members参数为对象数组
    memberIDs = [m['uid'] if type(m) == dict else m for m in members]

    g._db.begin()
    for member_id in memberIDs:
        try:
            Group.add_group_member(g._db, gid, member_id)
            User.reset_group_synckey(g.rds, appid, member_id, gid)
        except pymysql.err.IntegrityError as e:
            # 可能是重新加入群
            #1062 duplicate member
            if e.args[0] != 1062:
                raise

    g._db.commit()

    for m in members:
        member_id = m['uid'] if type(m) == dict else m
        v = {
            "group_id": gid,
            "member_id": member_id,
            "timestamp": int(time.time())
        }
        if type(m) == dict and m.get('name'):
            v['name'] = m['name']
        if type(m) == dict and m.get('avatar'):
            v['avatar'] = m['avatar']

        op = {"add_member": v}
        send_group_notification(appid, gid, op, [member_id])

        content = {
            "group_id": gid,
            "member_id": member_id,
            "name": Group.GROUP_EVENT_MEMBER_ADD
        }
        publish_message(g.rds, content)

    resp = {"success": True}
    return make_response(200, resp)
Ejemplo n.º 4
0
def add_group_member(gid):
    appid = request.appid
    obj = json.loads(request.data)
    if type(obj) is dict:
        members = [obj["uid"]]
    else:
        members = obj

    if len(members) == 0:
        return ""

    g._imdb.begin()
    for member_id in members:
        try:
            Group.add_group_member(g._imdb, gid, member_id)
        except umysql.SQLError, e:
            #1062 duplicate member
            if e[0] != 1062:
                raise
Ejemplo n.º 5
0
def add_group_member(gid):
    appid = request.appid
    obj = json.loads(request.data)
    if type(obj) is dict:
        members = [obj["uid"]]
    else:
        members = obj

    if len(members) == 0:
        return ""

    #支持members参数为对象数组
    memberIDs = map(lambda m:m['uid'] if type(m) == dict else m, members)
    
    g._db.begin()
    for member_id in memberIDs:
        try:
            Group.add_group_member(g._db, gid, member_id)
        except umysql.SQLError, e:
            #1062 duplicate member
            if e[0] != 1062:
                raise
Ejemplo n.º 6
0
def add_group_member(gid):
    appid = request.appid
    obj = json.loads(request.data)
    if type(obj) is dict:
        members = [obj["uid"]]
    else:
        members = obj

    if len(members) == 0:
        return ""

    #支持members参数为对象数组
    memberIDs = map(lambda m:m['uid'] if type(m) == dict else m, members)
    
    g._db.begin()
    for member_id in memberIDs:
        try:
            Group.add_group_member(g._db, gid, member_id)
            #可能是重新加入群
            User.reset_group_synckey(g.rds, appid, member_id, gid)
        except umysql.SQLError, e:
            #1062 duplicate member
            if e[0] != 1062:
                raise
Ejemplo n.º 7
0
def add_group_member(gid):
    appid = request.appid
    obj = json.loads(request.data)
    if type(obj) is dict:
        members = [obj["uid"]]
    else:
        members = obj

    if len(members) == 0:
        return ""

    #支持members参数为对象数组
    memberIDs = map(lambda m:m['uid'] if type(m) == dict else m, members)
    
    g._db.begin()
    for member_id in memberIDs:
        try:
            Group.add_group_member(g._db, gid, member_id)
            User.reset_group_synckey(g.rds, appid, member_id, gid)
        except pymysql.err.IntegrityError, e:
            # 可能是重新加入群
            #1062 duplicate member
            if e[0] != 1062:
                raise
Ejemplo n.º 8
0
def add_group_member(gid):
    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")
    inviter = None
    if type(obj) is dict:
        if 'members' in obj:
            members = obj['members']
            inviter = obj.get('inviter')
        else:
            members = [obj]
    else:
        members = obj

    if len(members) == 0:
        return ""
    
    group = Group.get_group(g._db, gid)
    if not group:
        raise ResponseMeta(400, "group non exists")
    
    # 支持members参数为对象数组
    memberIDs = [m['uid'] if type(m) == dict else m for m in members]
    
    g._db.begin()
    for member_id in memberIDs:
        try:
            Group.add_group_member(g._db, gid, member_id)
            User.reset_group_synckey(g.rds, appid, member_id, gid)
        except pymysql.err.IntegrityError as e:
            # 可能是重新加入群
            #1062 duplicate member
            if e.args[0] != 1062:
                raise

    g._db.commit()

    for m in members:
        member_id = m['uid'] if type(m) == dict else m
        v = {
            "group_id":gid,
            "group_name":group['name'],
            "member_id":member_id,
            "timestamp":int(time.time())
        }
        if type(m) == dict and m.get('name'):
            v['name'] = m['name']
        if type(m) == dict and m.get('avatar'):
            v['avatar'] = m['avatar']
        if inviter:
            v['inviter'] = inviter

        op = {"add_member":v}
        send_group_notification(appid, gid, op, [member_id])

        content = {
            "group_id":gid,
            "member_id":member_id,
            "name":Group.GROUP_EVENT_MEMBER_ADD
        }
        publish_message(g.rds, content)

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