Commit a3c362fb authored by Karel Slaný's avatar Karel Slaný

Removed globAccountsModelPtr from messages.cpp.

parent 4bff0108
......@@ -167,7 +167,7 @@ Component {
} else if (index == 2) {
messages.markMessageAsLocallyRead(messageModel, userName, msgId, false)
} else if (index == 3) {
messages.deleteMessageFromDbs(messageModel, userName, msgId)
messages.deleteMessageFromDbs(accountListModel, messageModel, userName, msgId)
}
pageView.pop(StackView.Immediate)
}
......
......@@ -165,8 +165,8 @@ void Messages::markMessagesAsLocallyRead(const QVariant &msgModelVariant,
messageModel->overrideReadAll(isRead);
}
void Messages::deleteMessageFromDbs(const QVariant &msgModelVariant,
const QString &userName, qint64 msgId)
void Messages::deleteMessageFromDbs(const QVariant &acntModelVariant,
const QVariant &msgModelVariant, const QString &userName, qint64 msgId)
{
qDebug("%s()", __func__);
......@@ -203,6 +203,12 @@ void Messages::deleteMessageFromDbs(const QVariant &msgModelVariant,
return;
}
AccountListModel *accountModel =
AccountListModel::fromVariant(acntModelVariant);
if (accountModel == Q_NULLPTR) {
qWarning("%s", "Cannot access account model.");
}
MessageListModel *messageModel =
MessageListModel::fromVariant(msgModelVariant);
if (messageModel == Q_NULLPTR) {
......@@ -212,14 +218,16 @@ void Messages::deleteMessageFromDbs(const QVariant &msgModelVariant,
if (fDb->deleteFilesFromDb(msgId)) {
if (msgDb->deleteMsgFromDb(msgId)) {
/* Remove row from model, don't regenerate data. */
if (accountModel != Q_NULLPTR) {
accountModel->updateCounters(userName,
msgDb->getCntOfNewMsgs(MessageDb::TYPE_RECEIVED),
msgDb->getMessageCount(MessageDb::TYPE_RECEIVED),
msgDb->getCntOfNewMsgs(MessageDb::TYPE_SENT),
msgDb->getMessageCount(MessageDb::TYPE_SENT));
}
if (messageModel != Q_NULLPTR) {
messageModel->removeMessage(msgId);
}
globAccountsModelPtr->updateCounters(userName,
msgDb->getCntOfNewMsgs(MessageDb::TYPE_RECEIVED),
msgDb->getMessageCount(MessageDb::TYPE_RECEIVED),
msgDb->getCntOfNewMsgs(MessageDb::TYPE_SENT),
msgDb->getMessageCount(MessageDb::TYPE_SENT));
}
}
}
......
......@@ -91,10 +91,16 @@ public:
/*!
* @brief Delete selected message from databases.
*
* @param[in] acntModelVariant Variant holding account model.
* @param[in] msgModelVariant Variant holding message model.
* @param[in] userName User name identifying the account.
* @param[in] msgId Identifier of the message to be deleted.
*/
Q_INVOKABLE static
void deleteMessageFromDbs(const QVariant &msgModelVariant,
const QString &userName, qint64 msgId);
void deleteMessageFromDbs(const QVariant &acntModelVariant,
const QVariant &msgModelVariant, const QString &userName,
qint64 msgId);
/*!
* @brief Move or create new databases to new location.
......
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