Commit aab132b1 authored by Karel Slaný's avatar Karel Slaný
Browse files

Selectively margin sent or received messages as sent or received.

parent 1e51026d
......@@ -155,9 +155,9 @@ Component {
anchors.fill: parent
onClicked: {
if (index == 0) {
messages.markMessagesAsLocallyRead(gUserName, true)
messages.markMessagesAsLocallyRead(gUserName, gMsgType, true)
} else if (index == 1) {
messages.markMessagesAsLocallyRead(gUserName, false)
messages.markMessagesAsLocallyRead(gUserName, gMsgType, false)
}
pageView.pop(StackView.Immediate)
}
......
......@@ -56,6 +56,29 @@ void Messages::clearMessagesModel(void)
globMessagesModel.clearAll();
}
/*!
* @brief Translate message type enumeration type into database representation.
*/
static
enum MessageDb::MessageType enumToDbRepr(enum Messages::MessageType msgType)
{
switch (msgType) {
case Messages::TYPE_RECEIVED:
return MessageDb::TYPE_RECEIVED;
break;
case Messages::TYPE_SENT:
return MessageDb::TYPE_SENT;
break;
default:
/*
* Any other translates to sent, but forces the application to
* crash in debugging mode.
*/
Q_ASSERT(0);
return MessageDb::TYPE_SENT;
break;
}
}
/* ========================================================================= */
/*
......@@ -77,8 +100,7 @@ void Messages::fillMessageList(const QString &userName,
globMessagesModel.clearAll();
/* Translate into database enum type. */
msgDb->getMessageListDataFromDb((msgType == TYPE_RECEIVED) ?
MessageDb::TYPE_RECEIVED : MessageDb::TYPE_SENT);
msgDb->getMessageListDataFromDb(enumToDbRepr(msgType));
}
......@@ -128,7 +150,8 @@ void Messages::markMessageAsLocallyRead(const QString &userName, qint64 msgId,
/*
* Slot: Set all messages in database as locally read/unread.
*/
void Messages::markMessagesAsLocallyRead(const QString &userName, bool isRead)
void Messages::markMessagesAsLocallyRead(const QString &userName,
enum MessageType msgType, bool isRead)
/* ========================================================================= */
{
qDebug("%s()", __func__);
......@@ -140,7 +163,8 @@ void Messages::markMessagesAsLocallyRead(const QString &userName, bool isRead)
qDebug() << "ERROR: Message database cannot open!";
return;
}
msgDb->markMessagesLocallyRead(isRead);
msgDb->markMessagesLocallyRead(enumToDbRepr(msgType), isRead);
/* The current model should correspond with supplied type. */
globMessagesModel.overrideReadAll(isRead);
}
......
......@@ -70,7 +70,7 @@ public:
* @brief Set all messages in database as locally read/unread.
*/
Q_INVOKABLE void markMessagesAsLocallyRead(const QString &userName,
bool isRead);
enum MessageType msgType, bool isRead);
/*!
* @brief Clear message model.
......
......@@ -631,19 +631,21 @@ bool MessageDb::markMessageLocallyRead(qint64 msgId, bool read)
/*
* Slot: Set all messages in database as localy read.
*/
bool MessageDb::markMessagesLocallyRead(bool read)
bool MessageDb::markMessagesLocallyRead(enum MessageType messageType, bool read)
/* ========================================================================= */
{
QSqlQuery query(m_db);
QString queryStr =
"UPDATE messages SET _dmReadLocally = :_dmReadLocally";
"UPDATE messages SET _dmReadLocally = :_dmReadLocally "
"WHERE _dmMessageType = :_dmMessageType";
if (!query.prepare(queryStr)) {
qDebug() << "Cannot prepare SQL query:" <<
query.lastError().text().toUtf8().constData();
return false;
}
query.bindValue(":_dmReadLocally", read);
query.bindValue(":_dmMessageType", messageType);
if (!query.exec()) {
qDebug() << "Cannot execute SQL query:" <<
......
......@@ -147,10 +147,11 @@ public:
/*!
* @brief Set all messages in database as localy read.
*
* @param[in] messageType Received or sent.
* @param[in] read. True = locally read; False = unread.
* @return True on success.
*/
bool markMessagesLocallyRead(bool read);
bool markMessagesLocallyRead(enum MessageType messageType, bool read);
/*!
* @brief Set flag if message attachment is present.
......
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