Ejemplo n.º 1
0
    def _push_to_pc(self, _user_uuid, _device_uuid):
        _pcsocket = self._pcsocket_data(_device_uuid)
        if _pcsocket == None:
            logging.error("no pcsocket data for: %s" % _device_uuid)
            return

        _device = self._devices_hash.get(_device_uuid)

        # if _device == None:
        #     logging.error("no device hash for: %s" % _device_uuid)
        #     return

        _from_user = {}
        _from_type = self._task.get("from_type")

        _fields = ["uuid", "user_icon", "user_email", "user_fullname", "updatetime"]

        if _from_type == YVOBJECT.DU:
            for _i in _fields:
                _from_user[_i] = self._task["_user"].get(_i)
            _from_user["updatetime"] = datetime_to_timestamp(_from_user["updatetime"])

        if _from_type == YVOBJECT.OG:
            _from_user = self._task["_group"]

        if _from_type == YVOBJECT.AP:
            _from_user = self._task["_app"]

        _body = self._task.get("message_body")
        _body["pid"] = _device.get("push_uuid")
        _body["from_user"] = _from_user
        _push = {"pcsocket": _pcsocket, "body": _body}
        _key = REDIS_PUSH_NOTIFICATION_KEY + ".host." + _pcsocket["host"] + ".port." + _pcsocket["port"]
        self._redis.rpush(_key, json.dumps(_push))
        return
    def _get(self, _app_uuid, _group_uuid):
        _redis = self.application.redis
        _key = OrgGroup.__tablename__ + ".app_uuid." + _app_uuid
        _is = _redis.sismember(_key, _group_uuid)
        if _is != True:
            self.setErrorCode(API_ERR.NO_ORG_GROUP)
            return

        _r = self.getReturnData()
        _r["list"] = []
        
        _key = OrgGroupUserData.__tablename__ + ".group_uuid." + _group_uuid
        _users = _redis.smembers(_key)
        if _users == None or len(_users) == 0:
            return
        
        _users = self._get_users(_users)
        for _user in _users:
            _updatetime = string_to_datetime(_user["updatetime"], "extra")
            _user["updatetime"] = datetime_to_timestamp(_updatetime)

        _sorted = sorted(_users, key=itemgetter("updatetime"), reverse=True)

        _shrinked_users = []
        for _user in _sorted:
            _shrinked_users.append(single_user(_redis, _user))

        _r["list"] = _shrinked_users
        return
def _single(_redis, _user):
    _is_mobile_online = False
    _is_browser_online = False
    _device_uuid = _user.get("mobile_device_uuid")
    if _device_uuid != None:
        _is_mobile_online = _online(_redis, _device_uuid)
    _device_uuid = _user.get("browser_device_uuid")
    if _device_uuid != None:
        _is_browser_online = _online(_redis, _device_uuid)
    _d = {}
    _d["is_browser_online"] = _is_browser_online
    _d["is_mobile_online"] = _is_mobile_online
    _d["group"] = _group(_redis, _user.get("uuid"))

    _fields = [
        "uuid",
        "user_icon",
        "user_email",
        "user_fullname",
        "user_signature",
        "updatetime",
    ]
    for _i in _fields:
        _d[_i] = _user.get(_i)
    if isinstance(_d["updatetime"], str):
        _updatetime = string_to_datetime(_d["updatetime"])
        _d["updatetime"] = datetime_to_timestamp(_updatetime)
    return _d
Ejemplo n.º 4
0
    def _push_to_socket(self, _user_uuid, _device_uuid):
        _device = self._devices_hash.get(_device_uuid)

        # if _device == None:
        #     logging.error("no device hash for: %s" % _device_uuid)
        #     return

        _from_user = {}
        _from_type = self._task.get("from_type")

        _fields = [
            "uuid",
            "user_icon",
            "user_email",
            "user_fullname",
            "updatetime",
        ]

        if _from_type == YVOBJECT.DU:
            for _i in _fields:
                _from_user[_i] = self._task["_user"].get(_i)
            _from_user["updatetime"] = datetime_to_timestamp(
                _from_user["updatetime"])

        if _from_type == YVOBJECT.AP:
            _from_user = self._task["_app"]

        _body = self._task.get("message_body")
        _body["pid"] = _device.get("push_uuid")
        _body["from_user"] = _from_user
        _push = {"pcsocket": {"device_uuid": _device_uuid}, "body": _body}
        _key = REDIS_PUSH_NOTIFICATION_KEY
        self._redis.rpush(_key, json.dumps(_push))
        return
Ejemplo n.º 5
0
    def _push_to_pc(self, _user_uuid, _device_uuid):
        _pcsocket = self._pcsocket_data(_device_uuid)
        if _pcsocket == None:
            logging.error("no pcsocket data for: %s" % _device_uuid)
            return
        
        _device = self._devices_hash.get(_device_uuid)

        # if _device == None:
        #     logging.error("no device hash for: %s" % _device_uuid)
        #     return
        
        _from_user = {}
        _from_type = self._task.get("from_type")
        
        _fields = [
            "uuid",
            "user_icon",
            "user_email",
            "user_fullname",
            "updatetime",
        ]
        
        if _from_type == YVOBJECT.DU:
            for _i in _fields:
                _from_user[_i] = self._task["_user"].get(_i)
            _from_user["updatetime"] = datetime_to_timestamp(_from_user["updatetime"])
            
        if _from_type == YVOBJECT.OG:
            _from_user = self._task["_group"]
            
        if _from_type == YVOBJECT.AP:
            _from_user = self._task["_app"]

        _body = self._task.get("message_body")
        _body["pid"] = _device.get("push_uuid")
        _body["from_user"] = _from_user
        _push = {
            "pcsocket": _pcsocket,
            "body": _body
        }
        async_signal_pcsocket_push(_push)
        return