Ejemplo n.º 1
0
def xg_push(appid, appname, token, content, extra):
    XGPush.push(appid, appname, token, content, extra)
Ejemplo n.º 2
0
def handle_im_message(msg):
    obj = json.loads(msg)
    if not obj.has_key("appid") or not obj.has_key("sender") or \
       (not obj.has_key("receiver") and not obj.has_key("receivers")):
        logging.warning("invalid push msg:%s", msg)
        return

    logging.debug("push msg:%s", msg)

    appid = obj["appid"]
    sender = obj["sender"]

    receivers = []
    if obj.has_key("receiver"):
        receivers = [obj["receiver"]]
    elif obj.has_key("receivers"):
        receivers = obj["receivers"]

    group_id = obj["group_id"] if obj.has_key("group_id") else 0

    sender_name = User.get_user_name(rds, appid, sender)
    content = push_content(sender_name, obj["content"])

    extra = {}
    extra["sender"] = sender

    if group_id:
        extra["group_id"] = group_id

    appname = config.APPNAME

    apns_users = []
    jp_users = []
    xg_users = []
    hw_users = []
    gcm_users = []
    mi_users = []

    for receiver in receivers:
        u = User.get_user(rds, appid, receiver)
        if u is None:
            logging.info("uid:%d nonexist", receiver)
            continue

        if group_id:
            quiet = User.get_user_notification_setting(rds, appid, receiver,
                                                       group_id)
            if quiet:
                logging.info("uid:%d group id:%d is in quiet mode", receiver,
                             group_id)
                continue

        #找出最近绑定的token
        ts = max(u.apns_timestamp, u.xg_timestamp, u.ng_timestamp,
                 u.mi_timestamp, u.hw_timestamp, u.gcm_timestamp,
                 u.jp_timestamp)

        if u.apns_device_token and u.apns_timestamp == ts:
            apns_users.append(u)
        elif u.xg_device_token and u.xg_timestamp == ts:
            xg_users.append(u)
        elif u.mi_device_token and u.mi_timestamp == ts:
            mi_users.append(u)
        elif u.hw_device_token and u.hw_timestamp == ts:
            hw_users.append(u)
        elif u.gcm_device_token and u.gcm_timestamp == ts:
            gcm_users.append(u)
        elif u.jp_device_token and u.jp_timestamp == ts:
            jp_users.append(u)
        else:
            logging.info("uid:%d has't device token", receiver)
            continue

    for u in xg_users:
        XGPush.push(appid, token, content, extra)

    for u in hw_users:
        HuaWeiPush.push(appid, appname, u.hw_device_token, content)

    for u in gcm_users:
        GCMPush.push(appid, appname, u.gcm_device_token, content)

    for u in mi_users:
        MiPush.push(appid, appname, u.mi_device_token, content)

    for u in apns_users:
        ios_push(appid, u.apns_device_token, content, u.unread + 1, extra)
        User.set_user_unread(rds, appid, receiver, u.unread + 1)

    tokens = []
    for u in jp_users:
        tokens.append(u.jp_device_token)
    if tokens:
        JGPush.push(appid, appname, tokens, content)
Ejemplo n.º 3
0
def handle_im_message(msg):
    obj = json.loads(msg)
    if not obj.has_key("appid") or not obj.has_key("sender") or \
       (not obj.has_key("receiver") and not obj.has_key("receivers")):
        logging.warning("invalid push msg:%s", msg)
        return

    logging.debug("push msg:%s", msg)

    appid = obj["appid"]
    sender = obj["sender"]

    receivers = []
    if obj.has_key("receiver"):
        receivers = [obj["receiver"]]
    elif obj.has_key("receivers"):
        receivers = obj["receivers"]
        
    group_id = obj["group_id"] if obj.has_key("group_id") else 0

    sender_name = User.get_user_name(rds, appid, sender)
    content = push_content(sender_name, obj["content"])

    extra = {}
    extra["sender"] = sender
    
    if group_id:
        extra["group_id"] = group_id

    appname = config.APPNAME

    apns_users = []
    jp_users = []
    xg_users = []
    hw_users = []
    gcm_users = []
    mi_users = []

    for receiver in receivers:
        u = User.get_user(rds, appid, receiver)
        if u is None:
            logging.info("uid:%d nonexist", receiver)
            continue
         
        if group_id:
            quiet = User.get_user_notification_setting(rds, appid, receiver, group_id)
            if quiet:
                logging.info("uid:%d group id:%d is in quiet mode", receiver, group_id)
                continue

        #找出最近绑定的token
        ts = max(u.apns_timestamp, u.xg_timestamp, u.ng_timestamp, 
                 u.mi_timestamp, u.hw_timestamp, u.gcm_timestamp, u.jp_timestamp)

        if u.apns_device_token and u.apns_timestamp == ts:
            apns_users.append(u)
        elif u.xg_device_token and u.xg_timestamp == ts:
            xg_users.append(u)
        elif u.mi_device_token and u.mi_timestamp == ts:
            mi_users.append(u)
        elif u.hw_device_token and u.hw_timestamp == ts:
            hw_users.append(u)
        elif u.gcm_device_token and u.gcm_timestamp == ts:
            gcm_users.append(u)
        elif u.jp_device_token and u.jp_timestamp == ts:
            jp_users.append(u)
        else:
            logging.info("uid:%d has't device token", receiver)
            continue

    for u in xg_users:
        XGPush.push(appid, token, content, extra)

    for u in hw_users:
        HuaWeiPush.push(appid, appname, u.hw_device_token, content)

    for u in gcm_users:
        GCMPush.push(appid, appname, u.gcm_device_token, content)

    for u in mi_users:
        MiPush.push(appid, appname, u.mi_device_token, content)
    
    for u in apns_users:
        ios_push(appid, u.apns_device_token, content, u.unread + 1, extra)
        User.set_user_unread(rds, appid, receiver, u.unread+1)

    tokens = []
    for u in jp_users:
        tokens.append(u.jp_device_token)
    if tokens:
        JGPush.push(appid, appname, tokens, content)
Ejemplo n.º 4
0
def xg_push(appid, token, content, extra):
    XGPush.push(appid, token, content, extra)