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,
emit statusBarTextChanged(tr("%1: downloading %2").arg(userName).arg(msgType), true, true);
/* Create download message list task and run it */
TaskDownloadMessageList *task;
task = new (std::nothrow) TaskDownloadMessageList(
m_isdsSession.isdsCtxMap[userName], &m_netLayer, &m_dbWrapper,
......@@ -133,7 +134,9 @@ bool IsdsWrapper::syncSingleAccount(const QVariant &acntModelVariant,
task->setAutoDelete(false);
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;
delete task;
......@@ -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),
m_isdsSession.isdsCtxMap[userName].last_isds_msg);
} else {
emit statusBarTextChanged(
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);
}
emit statusBarTextChanged(statusBarText, false, true);
}
/* Update message counters in the accout list */
AccountListModel *accountModel =
AccountListModel::fromVariant(acntModelVariant);
if (accountModel == Q_NULLPTR) {
......@@ -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;
}
......
......@@ -78,14 +78,14 @@ enum TaskChangePassword::Result TaskChangePassword::changePassword(
/* Send SOAP request */
if (dbOTPType == OTP_NO_OTP) {
if (!netLayer->createChangePwdRequest(ctx, DB_SERVICE,
XmlLayer::xmlCreateChangeISDSPasswordSoapRequest(oldPwd, newPwd),
xmlDataOut)) {
XmlLayer::xmlCreateChangeISDSPasswordSoapRequest(oldPwd,
newPwd), xmlDataOut)) {
return DL_ISDS_ERROR;
}
} else {
if (!netLayer->createChangePwdRequest(ctx, OTP_CHNG_PWD_SERVICE,
XmlLayer::xmlCreateChangePasswordOTPSoapRequest(dbOTPType, oldPwd, newPwd),
xmlDataOut)) {
XmlLayer::xmlCreateChangePasswordOTPSoapRequest(dbOTPType,
oldPwd, newPwd), xmlDataOut)) {
return DL_ISDS_ERROR;
}
}
......
......@@ -93,14 +93,12 @@ enum TaskDownloadDeliveryInfo::Result TaskDownloadDeliveryInfo::downloadDelivery
return DL_XML_ERROR;
}
if (eventList.isEmpty()) {
return DL_ERR;
}
/* Store data into db */
if (!dbWrapper->insertMesasgeDeliveryInfoToDb(ctx.username, eventList,
msgId, ctx.last_isds_msg)) {
return DL_DB_INS_ERR;
if (!eventList.isEmpty()) {
if (!dbWrapper->insertMesasgeDeliveryInfoToDb(ctx.username,
eventList, msgId, ctx.last_isds_msg)) {
return DL_DB_INS_ERR;
}
}
return DL_SUCCESS;
......
......@@ -33,6 +33,7 @@ TaskDownloadMessageList::TaskDownloadMessageList(IsdsSession::IsdsContext &ctx,
uint dmStatusFilter, uint dmOffset, uint dmLimit)
: m_result(DL_ERR),
m_msgIds(),
m_statusBarText(),
m_ctx(ctx),
m_netLayer(netLayer),
m_dbWrapper(dbWrapper),
......@@ -73,7 +74,8 @@ void TaskDownloadMessageList::run(void)
logDebugLv1NL("%s", "-----------------------------------------------");
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. ### */
......@@ -84,7 +86,7 @@ void TaskDownloadMessageList::run(void)
enum TaskDownloadMessageList::Result TaskDownloadMessageList::downloadMessageList(
IsdsSession::IsdsContext &ctx, NetLayer *netLayer, DbWrapper *dbWrapper,
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()) {
Q_ASSERT(0);
......@@ -116,9 +118,12 @@ enum TaskDownloadMessageList::Result TaskDownloadMessageList::downloadMessageLis
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
* we must update delivery info as well.
* we should update delivery info as well.
*/
if (Messages::TYPE_SENT == msgDirect) {
......@@ -126,32 +131,31 @@ enum TaskDownloadMessageList::Result TaskDownloadMessageList::downloadMessageLis
QList<Messages::Event> eventList;
/* Send SOAP request */
if (!netLayer->sendSoapRequest(ctx, MESSAGE_SERVICE,
XmlLayer::xmlCreateSignedDeliveryInfoSoapRequest(msgId),
xmlDataOut)) {
return DL_ISDS_ERROR;
}
/*
* Following functions don't have to check return values
* because they are complementary actions for message
* list download (delivery info is not important).
*/
/* Parse SOAP response */
if (!XmlLayer::parseGetMsgDeliveryInfoResponse(xmlDataOut, eventList,
ctx.last_isds_msg)) {
return DL_XML_ERROR;
}
/* Send delivery info SOAP request */
netLayer->sendSoapRequest(ctx, MESSAGE_SERVICE,
XmlLayer::xmlCreateSignedDeliveryInfoSoapRequest(msgId),
xmlDataOut);
if (eventList.isEmpty()) {
return DL_ERR;
}
/* Parse delivery info SOAP response */
XmlLayer::parseGetMsgDeliveryInfoResponse(xmlDataOut,
eventList, ctx.last_isds_msg);
/* Store data into db */
if (!dbWrapper->insertMesasgeDeliveryInfoToDb(ctx.username, eventList,
msgId, ctx.last_isds_msg)) {
return DL_DB_INS_ERR;
/* Store delivery info into db */
if (!eventList.isEmpty()) {
dbWrapper->insertMesasgeDeliveryInfoToDb(
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) {
msgIds.append(msg.dmID);
}
......
......@@ -80,16 +80,21 @@ public:
* @param[in] dmStatusFilter Dowanlod message status filter.
* @param[in] dmOffset Message download offset.
* @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.
*/
static
enum Result downloadMessageList(IsdsSession::IsdsContext &ctx,
NetLayer *netLayer, DbWrapper *dbWrapper,
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. */
QList<qint64> m_msgIds; /*!< Return message ID list. */
QString m_statusBarText; /*!< Return text about new messages for status bar. */
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