Commit 23b90ea4 authored by Martin Straka's avatar Martin Straka

Renamed some methods and code refactoring in message db

parent 0f9ce7e9
......@@ -102,8 +102,8 @@ void Accounts::updateNewMessageCounter(const QVariant &acntModelVariant,
}
accountModel->updateCounters(userName,
msgDb->getCntOfNewMsgs(MessageDb::TYPE_RECEIVED), -1,
msgDb->getCntOfNewMsgs(MessageDb::TYPE_SENT), -1);
msgDb->getCntOfNewMessages(MessageDb::TYPE_RECEIVED), -1,
msgDb->getCntOfNewMessages(MessageDb::TYPE_SENT), -1);
}
QString Accounts::fillAccountInfo(const QString &userName)
......@@ -393,9 +393,9 @@ void Accounts::loadModelCounters(AccountListModel *accountModel)
}
accountModel->updateCounters(userName,
msgDb->getCntOfNewMsgs(MessageDb::TYPE_RECEIVED),
msgDb->getCntOfNewMessages(MessageDb::TYPE_RECEIVED),
msgDb->getMessageCount(MessageDb::TYPE_RECEIVED),
msgDb->getCntOfNewMsgs(MessageDb::TYPE_SENT),
msgDb->getCntOfNewMessages(MessageDb::TYPE_SENT),
msgDb->getMessageCount(MessageDb::TYPE_SENT));
}
}
......@@ -133,7 +133,7 @@ void Messages::fillMessageList(const QVariant &msgModelVariant,
messageModel->clearAll();
/* Translate into database enum type. */
msgDb->getMessageListDataFromDb(messageModel, userName,
msgDb->setMessageListModelFromDb(messageModel, userName,
enumToDbRepr(msgType));
}
......@@ -185,7 +185,7 @@ MsgEnvelope *Messages::getMsgEnvelopeDataAndSetRecipient(
return Q_NULLPTR;
}
MsgEnvelope msg = msgDb->getMessageEnvelopeData(msgId);
MsgEnvelope msg = msgDb->getMessageEnvelopeFromDb(msgId);
// Add recipient to model
DataboxListModel *dbModel =
......@@ -352,13 +352,13 @@ void Messages::deleteMessageFromDbs(const QVariant &acntModelVariant,
}
if (fDb->deleteFilesFromDb(msgId)) {
if (msgDb->deleteMsgFromDb(msgId)) {
if (msgDb->deleteMessageFromDb(msgId)) {
/* Remove row from model, don't regenerate data. */
if (accountModel != Q_NULLPTR) {
accountModel->updateCounters(userName,
msgDb->getCntOfNewMsgs(MessageDb::TYPE_RECEIVED),
msgDb->getCntOfNewMessages(MessageDb::TYPE_RECEIVED),
msgDb->getMessageCount(MessageDb::TYPE_RECEIVED),
msgDb->getCntOfNewMsgs(MessageDb::TYPE_SENT),
msgDb->getCntOfNewMessages(MessageDb::TYPE_SENT),
msgDb->getMessageCount(MessageDb::TYPE_SENT));
}
if (messageModel != Q_NULLPTR) {
......@@ -438,7 +438,7 @@ void Messages::deleteExpiredMessagesFromDbs(int days)
userName.toUtf8().constData());
return;
}
msgIDList = msgDb->getExpireMsgListFromDb(days);
msgIDList = msgDb->getExpireMessageListFromDb(days);
if (msgIDList.isEmpty()) {
continue;
......@@ -457,7 +457,7 @@ void Messages::deleteExpiredMessagesFromDbs(int days)
msgDb->beginTransaction();
foreach (qint64 msgId, msgIDList) {
if (fDb->deleteFilesFromDb(msgId)) {
msgDb->deleteMsgFromDb(msgId);
msgDb->deleteMessageFromDb(msgId);
}
}
fDb->commitTransaction();
......@@ -722,11 +722,11 @@ int Messages::searchMsg(const QVariant &msgModelVariant, const QString &phrase,
}
if (msgTypes & TYPE_RECEIVED) {
msgs += msgDb->searchAndAppendMsgs(messageModel,
msgs += msgDb->searchMessagesAndSetModel(messageModel,
userName, phrase, MessageDb::TYPE_RECEIVED);
}
if (msgTypes & TYPE_SENT) {
msgs += msgDb->searchAndAppendMsgs(messageModel,
msgs += msgDb->searchMessagesAndSetModel(messageModel,
userName, phrase, MessageDb::TYPE_SENT);
}
}
......
......@@ -299,7 +299,7 @@ bool DbWrapper::updateAuthorInfo(const QString &userName,
data += ", " + authorName;
}
return msgDb->updateAuthotInfo(msgId, data);
return msgDb->updateMessageAuthorInfoInDb(msgId, data);
}
bool DbWrapper::insertMesasgeDeliveryInfoToDb(const QString &userName,
......
......@@ -67,7 +67,7 @@ bool MessageDb::reopenDb(const QString &newFileName)
return SQLiteDb::reopenDb(newFileName, SQLiteDb::CREATE_MISSING);
}
bool MessageDb::deleteMsgFromDb(qint64 msgId)
bool MessageDb::deleteMessageFromDb(qint64 msgId)
{
QSqlQuery query(m_db);
......@@ -156,7 +156,7 @@ QSet<qint64> MessageDb::getAllMessageIDsFromDB(void)
return msgIDList;
}
QList<qint64> MessageDb::getExpireMsgListFromDb(int days)
QList<qint64> MessageDb::getExpireMessageListFromDb(int days)
{
QSqlQuery query(m_db);
QList<qint64> msgIDList;
......@@ -211,7 +211,7 @@ short MessageDb::getMessageStatusFromDb(qint64 msgId, bool &hasFiles) const
return ret;
}
void MessageDb::getMessageListDataFromDb(MessageListModel *msgModel,
void MessageDb::setMessageListModelFromDb(MessageListModel *msgModel,
const QString &userName, enum MessageType messageType)
{
if (msgModel == Q_NULLPTR) {
......@@ -237,7 +237,7 @@ void MessageDb::getMessageListDataFromDb(MessageListModel *msgModel,
}
}
int MessageDb::getCntOfNewMsgs(enum MessageType messageType)
int MessageDb::getCntOfNewMessages(enum MessageType messageType)
{
QSqlQuery query(m_db);
......@@ -278,7 +278,7 @@ int MessageDb::getMessageCount(enum MessageType messageType)
return 0;
}
MsgEnvelope MessageDb::getMessageEnvelopeData(qint64 dmId)
MsgEnvelope MessageDb::getMessageEnvelopeFromDb(qint64 dmId)
{
QSqlQuery query(m_db);
QString queryStr;
......@@ -754,7 +754,7 @@ bool MessageDb::openDb(const QString &fileName, bool storeToDisk)
return SQLiteDb::openDb(fileName, flags);
}
int MessageDb::searchAndAppendMsgs(MessageListModel *msgModel,
int MessageDb::searchMessagesAndSetModel(MessageListModel *msgModel,
const QString &userName, const QString &phrase,
enum MessageType messageType)
{
......@@ -844,7 +844,7 @@ bool MessageDb::setAttachmentsDownloaded(bool downloaded)
return true;
}
bool MessageDb::updateAuthotInfo(qint64 msgId, const QString &data)
bool MessageDb::updateMessageAuthorInfoInDb(qint64 msgId, const QString &data)
{
QSqlQuery query(m_db);
......
......@@ -76,7 +76,7 @@ public:
* @param[in] msgId Message ID.
* @return True on success.
*/
bool deleteMsgFromDb(qint64 msgId);
bool deleteMessageFromDb(qint64 msgId);
/*!
* @brief Get list of databoxes from db.
......@@ -92,7 +92,7 @@ public:
* @param[in] messageType Message type.
* @return count.
*/
int getCntOfNewMsgs(enum MessageType messageType);
int getCntOfNewMessages(enum MessageType messageType);
/*!
* @brief Get message database size in bytes.
......@@ -114,7 +114,7 @@ public:
* @param[in] days Message age in days.
* @return List of expired message IDs.
*/
QList<qint64> getExpireMsgListFromDb(int days);
QList<qint64> getExpireMessageListFromDb(int days);
/*!
* @brief Get count of received/sent messages.
......@@ -130,16 +130,16 @@ public:
* @param[in] dmId Message identifier.
* @return Message envelope data structure.
*/
MsgEnvelope getMessageEnvelopeData(qint64 dmId);
MsgEnvelope getMessageEnvelopeFromDb(qint64 dmId);
/*!
* @brief Get list of messages from db - for QML.
* @brief Set message list model from db for QML.
*
* @param[in,out] msgModel Model to append data to.
* @param[in] userName Account user name.
* @param[in] messageType Received or sent.
*/
void getMessageListDataFromDb(MessageListModel *msgModel,
void setMessageListModelFromDb(MessageListModel *msgModel,
const QString &userName, enum MessageType messageType);
/*!
......@@ -224,7 +224,7 @@ public:
* @param[in] messageType Type of the sought messages.
* @return Number of results.
*/
int searchAndAppendMsgs(MessageListModel *msgModel,
int searchMessagesAndSetModel(MessageListModel *msgModel,
const QString &userName, const QString &phrase,
enum MessageType messageType);
......@@ -252,7 +252,7 @@ public:
* @param[in] data Author data.
* @return True on success.
*/
bool updateAuthotInfo(qint64 msgId, const QString &data);
bool updateMessageAuthorInfoInDb(qint64 msgId, const QString &data);
/*!
* @brief Update message envelope in messages table.
......
......@@ -195,13 +195,13 @@ enum TaskDownloadMessageList::Result TaskDownloadMessageList::downloadMessageLis
if (msgDb != Q_NULLPTR) {
if (msgDirect == Messages::TYPE_RECEIVED) {
accountModel->updateCounters(ctx.username,
msgDb->getCntOfNewMsgs(MessageDb::TYPE_RECEIVED),
msgDb->getCntOfNewMessages(MessageDb::TYPE_RECEIVED),
msgDb->getMessageCount(MessageDb::TYPE_RECEIVED),
-1, -1);
} else {
accountModel->updateCounters(ctx.username,
-1, -1,
msgDb->getCntOfNewMsgs(MessageDb::TYPE_SENT),
msgDb->getCntOfNewMessages(MessageDb::TYPE_SENT),
msgDb->getMessageCount(MessageDb::TYPE_SENT));
}
}
......
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