Commit 09ec147c authored by Martin Straka's avatar Martin Straka

Fixed wrong complete messages downloading during sync

parent 162801be
......@@ -119,7 +119,8 @@ QString DbWrapper::createAccountInfoStringForQml(
bool DbWrapper::insertMessageListToDb(const QString &userName,
enum MessageDb::MessageType messageType,
const QList<Messages::Message> &messages,
QList<qint64> &messageChangedStatusList, QString &txt)
QList<qint64> &messageChangedStatusList, QString &txt,
QList<qint64> &listOfNewMsgIds)
/* ========================================================================= */
{
MessageDb *msgDb = globMessageDbsPtr->accessMessageDb(
......@@ -130,8 +131,11 @@ bool DbWrapper::insertMessageListToDb(const QString &userName,
return false;
}
bool isSentMessage = (messageType == MessageDb::TYPE_SENT);
int newMsgs = 0;
int msgs = messages.count();
msgDb->beginTransaction();
for (int i = 0; i < msgs; ++i) {
bool hasFiles;
......@@ -143,13 +147,18 @@ bool DbWrapper::insertMessageListToDb(const QString &userName,
if (!msgDb->insertMessageEnvelopeIntoDb(messages.at(i))) {
txt = tr("Message %1 envelope insertion failed!").
arg(messages.at(i).dmID);
} else {
// new message envelope has saved into db so
// append message id to list for downloading of
// complete message.
listOfNewMsgIds.append(messages.at(i).dmID);
}
} else {
if (!msgDb->updateMessageEnvelopeInDb(messages.at(i))) {
txt = tr("Message %1 envelope update failed!").
arg(messages.at(i).dmID);
}
if (messageType == MessageDb::TYPE_SENT) {
if (isSentMessage) {
if (msgStatus != messages.at(i).dmMessageStatus && hasFiles) {
messageChangedStatusList.append(messages.at(i).dmID);
}
......@@ -158,7 +167,7 @@ bool DbWrapper::insertMessageListToDb(const QString &userName,
}
msgDb->commitTransaction();
if (messageType == MessageDb::TYPE_RECEIVED) {
if (!isSentMessage) {
if (newMsgs > 0) {
txt = tr("%1: new messages: %2")
.arg(userName).arg(QString::number(newMsgs));
......
......@@ -118,13 +118,16 @@ public:
* @param[in] messages - list of message envelopes.
* @param[out] messageChangedStatusList -
* list of message ids where message status has changed.
* @param[out] txt - error description if something fails.
* @param[out] txt Error description if something fails.
* @param[out] listOfNewMsgIds List of new message Ids for complete
* message downloading.
* @return true if success.
*/
bool insertMessageListToDb(const QString &userName,
enum MessageDb::MessageType messageType,
const QList<Messages::Message> &messages,
QList<qint64> &messageChangedStatusList, QString &txt);
QList<qint64> &messageChangedStatusList, QString &txt,
QList<qint64> &listOfNewMsgIds);
/*!
* @brief Insert complete message to db.
......
......@@ -111,6 +111,7 @@ enum TaskDownloadMessageList::Result TaskDownloadMessageList::downloadMessageLis
QByteArray xmlDataOut;
QList<Messages::Message> messages;
QList<qint64> listOfNewMsgIds;
/* Send SOAP request */
if (!netLayer->sendSoapRequest(ctx, MESSAGE_SERVICE,
......@@ -130,7 +131,8 @@ enum TaskDownloadMessageList::Result TaskDownloadMessageList::downloadMessageLis
QList<qint64> messageChangedStatusList;
if (!dbWrapper->insertMessageListToDb(ctx.username,
(Messages::TYPE_RECEIVED == msgDirect) ? MessageDb::TYPE_RECEIVED : MessageDb::TYPE_SENT,
messages, messageChangedStatusList, ctx.last_isds_msg)) {
messages, messageChangedStatusList, ctx.last_isds_msg,
listOfNewMsgIds)) {
return DL_DB_INS_ERR;
}
......@@ -193,16 +195,16 @@ enum TaskDownloadMessageList::Result TaskDownloadMessageList::downloadMessageLis
}
}
/* Download complete messages (create and insert tasks to worker pool) */
/* Download new complete messages if this setting is enabled.
* (create and insert download compete message tasks to worker pool) */
if (downloadCompleteMsgs) {
if (messageModel == Q_NULLPTR) {
qWarning("%s", "Cannot access message model.");
}
foreach (const Messages::Message &msg, messages) {
foreach (qint64 msgId, listOfNewMsgIds) {
TaskDownloadMessage *task;
task = new (std::nothrow) TaskDownloadMessage(ctx,
netLayer, dbWrapper, msg.dmID, msgDirect,
messageModel);
netLayer, dbWrapper, msgId, msgDirect, messageModel);
task->setAutoDelete(true);
workPool->assignLo(task, WorkerPool::APPEND);
}
......
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