Commit e100745e authored by Martin Straka's avatar Martin Straka

Update download message list task and task refactoring

parent 6c48e906
...@@ -125,6 +125,7 @@ bool IsdsWrapper::syncSingleAccount(const QVariant &acntModelVariant, ...@@ -125,6 +125,7 @@ bool IsdsWrapper::syncSingleAccount(const QVariant &acntModelVariant,
emit statusBarTextChanged(tr("%1: downloading %2").arg(userName).arg(msgType), true, true); emit statusBarTextChanged(tr("%1: downloading %2").arg(userName).arg(msgType), true, true);
/* Create download message list task and run it */
TaskDownloadMessageList *task; TaskDownloadMessageList *task;
task = new (std::nothrow) TaskDownloadMessageList( task = new (std::nothrow) TaskDownloadMessageList(
m_isdsSession.isdsCtxMap[userName], &m_netLayer, &m_dbWrapper, m_isdsSession.isdsCtxMap[userName], &m_netLayer, &m_dbWrapper,
...@@ -133,7 +134,9 @@ bool IsdsWrapper::syncSingleAccount(const QVariant &acntModelVariant, ...@@ -133,7 +134,9 @@ bool IsdsWrapper::syncSingleAccount(const QVariant &acntModelVariant,
task->setAutoDelete(false); task->setAutoDelete(false);
m_workPool.runSingle(task); m_workPool.runSingle(task);
QList<qint64> msgIds = task->m_msgIds; /* Results from task */
QList<qint64> msgIds = task->m_msgIds;
const QString statusBarText = task->m_statusBarText;
bool success = TaskDownloadMessageList::DL_SUCCESS == task->m_result; bool success = TaskDownloadMessageList::DL_SUCCESS == task->m_result;
delete task; delete task;
...@@ -143,29 +146,10 @@ bool IsdsWrapper::syncSingleAccount(const QVariant &acntModelVariant, ...@@ -143,29 +146,10 @@ bool IsdsWrapper::syncSingleAccount(const QVariant &acntModelVariant,
tr("Failed to download list of %1 messages for user name '%2'.").arg(msgType).arg(userName), tr("Failed to download list of %1 messages for user name '%2'.").arg(msgType).arg(userName),
m_isdsSession.isdsCtxMap[userName].last_isds_msg); m_isdsSession.isdsCtxMap[userName].last_isds_msg);
} else { } else {
emit statusBarTextChanged( emit statusBarTextChanged(statusBarText, false, true);
m_isdsSession.isdsCtxMap[userName].last_isds_msg,
false, true);
}
if (globSet.downloadCompleteMsgs) {
MessageListModel *messageModel =
MessageListModel::fromVariant(msgModelVariant);
if (messageModel == Q_NULLPTR) {
qWarning("%s", "Cannot access message model.");
}
foreach (qint64 msgId, msgIds) {
TaskDownloadMessage *task;
task = new (std::nothrow) TaskDownloadMessage(
m_isdsSession.isdsCtxMap[userName], &m_netLayer,
&m_dbWrapper, msgId, msgDirect, messageModel);
task->setAutoDelete(true);
m_workPool.assignLo(task, WorkerPool::APPEND);
}
} }
/* Update message counters in the accout list */
AccountListModel *accountModel = AccountListModel *accountModel =
AccountListModel::fromVariant(acntModelVariant); AccountListModel::fromVariant(acntModelVariant);
if (accountModel == Q_NULLPTR) { if (accountModel == Q_NULLPTR) {
...@@ -189,6 +173,24 @@ bool IsdsWrapper::syncSingleAccount(const QVariant &acntModelVariant, ...@@ -189,6 +173,24 @@ bool IsdsWrapper::syncSingleAccount(const QVariant &acntModelVariant,
} }
} }
/* Download complete messages (create and insert tasks to worker pool) */
if (globSet.downloadCompleteMsgs) {
MessageListModel *messageModel =
MessageListModel::fromVariant(msgModelVariant);
if (messageModel == Q_NULLPTR) {
qWarning("%s", "Cannot access message model.");
}
foreach (qint64 msgId, msgIds) {
TaskDownloadMessage *task;
task = new (std::nothrow) TaskDownloadMessage(
m_isdsSession.isdsCtxMap[userName], &m_netLayer,
&m_dbWrapper, msgId, msgDirect, messageModel);
task->setAutoDelete(true);
m_workPool.assignLo(task, WorkerPool::APPEND);
}
}
return success; return success;
} }
......
...@@ -78,14 +78,14 @@ enum TaskChangePassword::Result TaskChangePassword::changePassword( ...@@ -78,14 +78,14 @@ enum TaskChangePassword::Result TaskChangePassword::changePassword(
/* Send SOAP request */ /* Send SOAP request */
if (dbOTPType == OTP_NO_OTP) { if (dbOTPType == OTP_NO_OTP) {
if (!netLayer->createChangePwdRequest(ctx, DB_SERVICE, if (!netLayer->createChangePwdRequest(ctx, DB_SERVICE,
XmlLayer::xmlCreateChangeISDSPasswordSoapRequest(oldPwd, newPwd), XmlLayer::xmlCreateChangeISDSPasswordSoapRequest(oldPwd,
xmlDataOut)) { newPwd), xmlDataOut)) {
return DL_ISDS_ERROR; return DL_ISDS_ERROR;
} }
} else { } else {
if (!netLayer->createChangePwdRequest(ctx, OTP_CHNG_PWD_SERVICE, if (!netLayer->createChangePwdRequest(ctx, OTP_CHNG_PWD_SERVICE,
XmlLayer::xmlCreateChangePasswordOTPSoapRequest(dbOTPType, oldPwd, newPwd), XmlLayer::xmlCreateChangePasswordOTPSoapRequest(dbOTPType,
xmlDataOut)) { oldPwd, newPwd), xmlDataOut)) {
return DL_ISDS_ERROR; return DL_ISDS_ERROR;
} }
} }
......
...@@ -93,14 +93,12 @@ enum TaskDownloadDeliveryInfo::Result TaskDownloadDeliveryInfo::downloadDelivery ...@@ -93,14 +93,12 @@ enum TaskDownloadDeliveryInfo::Result TaskDownloadDeliveryInfo::downloadDelivery
return DL_XML_ERROR; return DL_XML_ERROR;
} }
if (eventList.isEmpty()) {
return DL_ERR;
}
/* Store data into db */ /* Store data into db */
if (!dbWrapper->insertMesasgeDeliveryInfoToDb(ctx.username, eventList, if (!eventList.isEmpty()) {
msgId, ctx.last_isds_msg)) { if (!dbWrapper->insertMesasgeDeliveryInfoToDb(ctx.username,
return DL_DB_INS_ERR; eventList, msgId, ctx.last_isds_msg)) {
return DL_DB_INS_ERR;
}
} }
return DL_SUCCESS; return DL_SUCCESS;
......
...@@ -33,6 +33,7 @@ TaskDownloadMessageList::TaskDownloadMessageList(IsdsSession::IsdsContext &ctx, ...@@ -33,6 +33,7 @@ TaskDownloadMessageList::TaskDownloadMessageList(IsdsSession::IsdsContext &ctx,
uint dmStatusFilter, uint dmOffset, uint dmLimit) uint dmStatusFilter, uint dmOffset, uint dmLimit)
: m_result(DL_ERR), : m_result(DL_ERR),
m_msgIds(), m_msgIds(),
m_statusBarText(),
m_ctx(ctx), m_ctx(ctx),
m_netLayer(netLayer), m_netLayer(netLayer),
m_dbWrapper(dbWrapper), m_dbWrapper(dbWrapper),
...@@ -73,7 +74,8 @@ void TaskDownloadMessageList::run(void) ...@@ -73,7 +74,8 @@ void TaskDownloadMessageList::run(void)
logDebugLv1NL("%s", "-----------------------------------------------"); logDebugLv1NL("%s", "-----------------------------------------------");
m_result = downloadMessageList(m_ctx, m_netLayer, m_dbWrapper, m_result = downloadMessageList(m_ctx, m_netLayer, m_dbWrapper,
m_msgDirect, m_dmStatusFilter, m_dmOffset, m_dmLimit, m_msgIds); m_msgDirect, m_dmStatusFilter, m_dmOffset, m_dmLimit, m_msgIds,
m_statusBarText);
/* ### Worker task end. ### */ /* ### Worker task end. ### */
...@@ -84,7 +86,7 @@ void TaskDownloadMessageList::run(void) ...@@ -84,7 +86,7 @@ void TaskDownloadMessageList::run(void)
enum TaskDownloadMessageList::Result TaskDownloadMessageList::downloadMessageList( enum TaskDownloadMessageList::Result TaskDownloadMessageList::downloadMessageList(
IsdsSession::IsdsContext &ctx, NetLayer *netLayer, DbWrapper *dbWrapper, IsdsSession::IsdsContext &ctx, NetLayer *netLayer, DbWrapper *dbWrapper,
enum Messages::MessageType msgDirect, uint dmStatusFilter, enum Messages::MessageType msgDirect, uint dmStatusFilter,
uint dmOffset, uint dmLimit, QList<qint64> &msgIds) uint dmOffset, uint dmLimit, QList<qint64> &msgIds, QString &statusBarText)
{ {
if (ctx.username.isEmpty()) { if (ctx.username.isEmpty()) {
Q_ASSERT(0); Q_ASSERT(0);
...@@ -116,9 +118,12 @@ enum TaskDownloadMessageList::Result TaskDownloadMessageList::downloadMessageLis ...@@ -116,9 +118,12 @@ enum TaskDownloadMessageList::Result TaskDownloadMessageList::downloadMessageLis
return DL_DB_INS_ERR; return DL_DB_INS_ERR;
} }
/* Store info text about new messages (for showing in status bar) */
statusBarText = ctx.last_isds_msg;
/* /*
* For sent message where message status was changed * For sent message where message status was changed
* we must update delivery info as well. * we should update delivery info as well.
*/ */
if (Messages::TYPE_SENT == msgDirect) { if (Messages::TYPE_SENT == msgDirect) {
...@@ -126,32 +131,31 @@ enum TaskDownloadMessageList::Result TaskDownloadMessageList::downloadMessageLis ...@@ -126,32 +131,31 @@ enum TaskDownloadMessageList::Result TaskDownloadMessageList::downloadMessageLis
QList<Messages::Event> eventList; QList<Messages::Event> eventList;
/* Send SOAP request */ /*
if (!netLayer->sendSoapRequest(ctx, MESSAGE_SERVICE, * Following functions don't have to check return values
XmlLayer::xmlCreateSignedDeliveryInfoSoapRequest(msgId), * because they are complementary actions for message
xmlDataOut)) { * list download (delivery info is not important).
return DL_ISDS_ERROR; */
}
/* Parse SOAP response */ /* Send delivery info SOAP request */
if (!XmlLayer::parseGetMsgDeliveryInfoResponse(xmlDataOut, eventList, netLayer->sendSoapRequest(ctx, MESSAGE_SERVICE,
ctx.last_isds_msg)) { XmlLayer::xmlCreateSignedDeliveryInfoSoapRequest(msgId),
return DL_XML_ERROR; xmlDataOut);
}
if (eventList.isEmpty()) { /* Parse delivery info SOAP response */
return DL_ERR; XmlLayer::parseGetMsgDeliveryInfoResponse(xmlDataOut,
} eventList, ctx.last_isds_msg);
/* Store data into db */ /* Store delivery info into db */
if (!dbWrapper->insertMesasgeDeliveryInfoToDb(ctx.username, eventList, if (!eventList.isEmpty()) {
msgId, ctx.last_isds_msg)) { dbWrapper->insertMesasgeDeliveryInfoToDb(
return DL_DB_INS_ERR; ctx.username, eventList, msgId,
ctx.last_isds_msg);
} }
} }
} }
/* Return message ID list for complete message download */ /* Return message ID list for additional download of complete messages */
foreach (const Messages::Message &msg, messages) { foreach (const Messages::Message &msg, messages) {
msgIds.append(msg.dmID); msgIds.append(msg.dmID);
} }
......
...@@ -80,16 +80,21 @@ public: ...@@ -80,16 +80,21 @@ public:
* @param[in] dmStatusFilter Dowanlod message status filter. * @param[in] dmStatusFilter Dowanlod message status filter.
* @param[in] dmOffset Message download offset. * @param[in] dmOffset Message download offset.
* @param[in] dmLimit Message list length limit. * @param[in] dmLimit Message list length limit.
* @param[out] msgIds Message ID list (for download of complete messages).
* @param[out] statusBarText Text about new messages for status bar.
* @return Error state. * @return Error state.
*/ */
static static
enum Result downloadMessageList(IsdsSession::IsdsContext &ctx, enum Result downloadMessageList(IsdsSession::IsdsContext &ctx,
NetLayer *netLayer, DbWrapper *dbWrapper, NetLayer *netLayer, DbWrapper *dbWrapper,
enum Messages::MessageType msgDirect, uint dmStatusFilter, enum Messages::MessageType msgDirect, uint dmStatusFilter,
uint dmOffset, uint dmLimit, QList<qint64> &msgIds); uint dmOffset, uint dmLimit, QList<qint64> &msgIds,
QString &statusBarText);
enum Result m_result; /*!< Return state. */ enum Result m_result; /*!< Return state. */
QList<qint64> m_msgIds; /*!< Return message ID list. */ QList<qint64> m_msgIds; /*!< Return message ID list. */
QString m_statusBarText; /*!< Return text about new messages for status bar. */
private: private:
/*! /*!
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment