Exemple #1
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
 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
Exemple #3
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
Exemple #4
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()
        _row.create_redis_keys(self._redis)

        _row = ConversationInfo(uuid=self._conversation_uuid,
                                status=CONVERSATION_STATUS.OPEN,
                                latest_task=self._uuid)
        _row.async_update()
        _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()
            _row.update_redis_keys(self._redis)

        # for message routing algorithm
        self._user_latest_send_message_time()
        return
Exemple #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