示例#1
0
    def _body(self):
        _message = {}
        _message["id"] = self._task.get("uuid")
        _message["fi"] = self._task.get("from_uuid")
        _message["ti"] = self._task.get("to_uuid")
        _message["ft"] = self._task.get("from_type")
        _message["tt"] = self._task.get("to_type")
        _message["mt"] = self._task.get("message_type")
        _message["ms"] = self._task.get("message_subtype")
        _message["ci"] = self._task.get("conversation_uuid")
        _message["ct"] = self._task.get("conversation_type")
        _message["tl"] = self._task.get("title")
        _message["bo"] = self._task.get("body")

        if _message["ct"] == CONVERSATION_TYPE.S2P:
            _message["ti"] = self._task["app_uuid"]
            _message["tt"] = YVOBJECT.AP
            if self._name == APP_POLICY.GROUP:
                #_message["ti"] == self._task["to_uuid"]
                _message["tt"] == YVOBJECT.OG
                
        if isinstance(self._task.get("title"), unicode):
            _message["tl"] = self._task.get("title").encode("utf-8")
        if isinstance(self._task.get("body"), unicode):
            _message["bo"] = self._task.get("body").encode("utf-8")

        _message["ts"] = datetime_to_microsecond_timestamp(self._task["createtime"])
        
        self._task["message_body"] = _message

        _message_body = json.dumps(self._task["message_body"])
        if isinstance(_message_body, unicode):
            _message_body = _message_body.encode("utf-8")
            
        _values = {
            "uuid": self._task["uuid"],
            "task_status": TASK_STATUS.PROCESSED,
            "message_body": _message_body,
        }
        _row = MessagePushTask(**_values)
        _row.async_update(self._redis)
        _row.update_redis_keys(self._redis)
        return
示例#2
0
 def _send_apologize(self, _text):
     _task = {
         "uuid": str(uuid.uuid1()),
         "app_uuid": self._task["app_uuid"],
         "conversation_uuid": self._task["conversation_uuid"],
         "conversation_type": CONVERSATION_TYPE.S2P,
         "message_type": MESSAGE_TYPE.NOTI,
         "message_subtype": MESSAGE_SUBTYPE.TEXT,
         "from_uuid": self._task["to_uuid"],
         "from_type": self._task["to_type"],
         "to_uuid": self._task["to_uuid"],
         "to_type": self._task["to_type"],
         "body": _text,
         "task_status": TASK_STATUS.PENDING,
     }
     _row = MessagePushTask(**_task)
     _row.async_add(self._redis)
     _row.create_redis_keys(self._redis)
     _m = {"task_uuid": _row.uuid}
     self._redis.rpush(REDIS_DISPATCHER_NOTIFICATION_KEY, json.dumps(_m))
     return
示例#3
0
    def _body(self):
        _message = {}
        _message["id"] = self._task.get("uuid")
        _message["fi"] = self._task.get("from_uuid")
        _message["ti"] = self._task.get("to_uuid")
        _message["ft"] = self._task.get("from_type")
        _message["tt"] = self._task.get("to_type")
        _message["mt"] = self._task.get("message_type")
        _message["ms"] = self._task.get("message_subtype")
        _message["ci"] = self._task.get("conversation_uuid")
        _message["ct"] = self._task.get("conversation_type")
        _message["tl"] = self._task.get("title")
        _message["bo"] = self._task.get("body")

        if _message["ct"] == CONVERSATION_TYPE.S2P:
            _message["ti"] = self._task["app_uuid"]
            _message["tt"] = YVOBJECT.AP
            if self._name == APP_POLICY.GROUP:
                #_message["ti"] == self._task["to_uuid"]
                _message["tt"] == YVOBJECT.OG

        if isinstance(self._task.get("title"), unicode):
            _message["tl"] = self._task.get("title").encode("utf-8")
        if isinstance(self._task.get("body"), unicode):
            _message["bo"] = self._task.get("body").encode("utf-8")

        _message["ts"] = datetime_to_microsecond_timestamp(
            self._task["createtime"])

        self._task["message_body"] = _message

        _message_body = json.dumps(self._task["message_body"])
        if isinstance(_message_body, unicode):
            _message_body = _message_body.encode("utf-8")

        _values = {
            "uuid": self._task["uuid"],
            "task_status": TASK_STATUS.PROCESSED,
            "message_body": _message_body,
        }
        _row = MessagePushTask(**_values)
        _row.async_update(self._redis)
        _row.update_redis_keys(self._redis)
        return
示例#4
0
 def _send_apologize(self, _text):
     _task = {
         "uuid": str(uuid.uuid1()),
         "app_uuid": self._task["app_uuid"],
         "conversation_uuid": self._task["conversation_uuid"],
         "conversation_type": CONVERSATION_TYPE.S2P,
         "message_type": MESSAGE_TYPE.NOTI,
         "message_subtype": MESSAGE_SUBTYPE.TEXT,
         "from_uuid": self._task["to_uuid"],
         "from_type": self._task["to_type"],
         "to_uuid": self._task["to_uuid"],
         "to_type": self._task["to_type"],
         "body": _text,
         "task_status": TASK_STATUS.PENDING,
     }
     _row = MessagePushTask(**_task)
     _row.async_add(self._redis)
     _row.create_redis_keys(self._redis)
     _m = {"task_uuid": _row.uuid}
     self._redis.rpush(REDIS_DISPATCHER_NOTIFICATION_KEY, json.dumps(_m))
     return
示例#5
0
 def _send_apologize(self, _text):
     _task = {
         "uuid": str(uuid.uuid1()),
         "app_uuid": self._task["app_uuid"],
         "conversation_uuid": self._task["conversation_uuid"],
         "conversation_type": CONVERSATION_TYPE.S2P,
         "message_type": MESSAGE_TYPE.NOTI,
         "message_subtype": MESSAGE_SUBTYPE.TEXT,
         "from_uuid": self._task["to_uuid"],
         "from_type": self._task["to_type"],
         "to_uuid": self._task["to_uuid"],
         "to_type": self._task["to_type"],
         "body": _text,
         "task_status": TASK_STATUS.PENDING,
     }
     _row = MessagePushTask(**_task)
     _row.async_add()
     _row.create_redis_keys(self._redis)
     #self._send_to_queue(_row.uuid)
     _m = {"task_uuid": _row.uuid}
     async_signal_dis_message(_m)
     return
    def _Task(self):
        super(ForwardMessageHandler, self)._Task()
        _request = json.loads(self.request.body)

        logging.info("ForwardMessage with %s." % (str(_request)))

        self.task_id = 0
        if "from_uuid" not in _request \
           or "to_type" not in _request \
           or "to_uuid" not in _request \
           or "task_uuid" not in _request:
            logging.error("send message failed for input.")
            self.setErrorCode(API_ERR.NO_PARA)
            return

        _old = redis_hash_to_dict(self.application.redis, MessagePushTask, _request["task_uuid"])
        if _old is None:
            logging.error("Error for no task uuid=%s." % (_request["task_uuid"]))
            self.setErrorCode(API_ERR.NO_TASK)
            return

        _from_uuid = _request.get("from_uuid")
        _conversation_uuid = _request.get("to_uuid")
        _uuid = str(uuid.uuid1())
        _now_datetime = datetime.datetime.now()
        _now = _now_datetime.strftime("%Y-%m-%d %H:%M:%S %f")

        _task = {
            "uuid": _uuid,
            "conversation_uuid": _conversation_uuid,
            "app_uuid": self.app_uuid,
            "message_type": _old.message_type,
            "message_subtype": _old.message_subtype,
            "from_uuid": _from_uuid,
            "from_type": YVOBJECT.DU,
            "from_device_uuid": _request["device_uuid"],
            "to_uuid": _conversation_uuid,
            "to_type": _request["to_type"],
            "body": _old.body,
            "task_status": TASK_STATUS.PENDING,
        }

        _row = MessagePushTask(**_task)
        _row.async_add(self.application.redis)
        _row.create_redis_keys(self.application.redis)

        _row = ConversationInfo(uuid=_conversation_uuid, lastest_task=_uuid)
        _row.async_update(self.application.redis)
        _row.update_redis_keys(self.application.redis)
        
        _m = {"task_uuid": _uuid}
        self.application.redis.rpush(REDIS_DISPATCHER_NOTIFICATION_KEY, json.dumps(_m))
        
        #link file
        if _old.message_subtype == MESSAGE_SUBTYPE.FILE:
            self._check_link_file(_old, _from_uuid)
        
        _rdata = self.getReturnData()
        _rdata["ts"] = int(time.mktime(_now_datetime.timetuple()))
        _rdata["ts"] = round(_rdata["ts"])
        _rdata["task"] = _uuid
        return
示例#7
0
    def save(self):
        _task = {
            "uuid": self._uuid,
            "app_uuid": self._app_uuid,
            "conversation_uuid": self._conversation_uuid,
            "conversation_type": self._conversation_type,
            "message_type": self._message_type,
            "message_subtype": self._message_subtype,
            "from_uuid": self._from_uuid,
            "from_type": self._from_type,
            "from_device_uuid": self._from_device_uuid,
            "to_uuid": self._to_uuid,
            "to_type": self._to_type,
            "body": self._message_body,
            "task_status": TASK_STATUS.PENDING,
        }
        _row = MessagePushTask(**_task)
        _row.async_add(self._redis)
        _row.create_redis_keys(self._redis)

        _row = ConversationInfo(uuid=self._conversation_uuid, status=CONVERSATION_STATUS.OPEN, latest_task=self._uuid)
        _row.async_update(self._redis)
        _row.update_redis_keys(self._redis)

        _m = {"task_uuid": self._uuid}
        self._redis.rpush(REDIS_DISPATCHER_NOTIFICATION_KEY, json.dumps(_m))

        _key = ConversationUserData.__tablename__ + ".conversation_uuid." + self._conversation_uuid + ".datas"
        _datas = self._redis.smembers(_key)
        for _data_uuid in _datas:
            _row = ConversationUserData(uuid=_data_uuid, conversation_status=CONVERSATION_STATUS.OPEN)
            _row.async_update(self._redis)
            _row.update_redis_keys(self._redis)
        
        # for message routing algorithm
        self._user_latest_send_message_time()
        return