Commit 3567abd9 authored by Weblate's avatar Weblate

Merge remote-tracking branch 'origin/master'

parents ef730d0a 0cb665d6
......@@ -225,7 +225,7 @@ void Kaidan::setChatPartner(QString chatPartner)
void Kaidan::sendMessage(QString jid, QString message)
{
messageController->sendMessage(&jid, &message);
rosterController->updateLastExchangedOfJid(&jid);
rosterController->handleNewMessageSent(&jid, &message);
}
QString Kaidan::getResourcePath(QString name_)
......
......@@ -239,6 +239,10 @@ void RosterController::handleMessageReceived(Swift::Message::ref message)
if (optionalMessageBody) {
QString msgAuthor = QString::fromStdString(message->getFrom()
.toBare().toString());
QString message = QString::fromStdString(optionalMessageBody.get());
// update the last message for this contact
rosterModel->setLastMessageForJid(&msgAuthor, &message);
updateLastExchangedOfJid(&msgAuthor);
......@@ -248,6 +252,14 @@ void RosterController::handleMessageReceived(Swift::Message::ref message)
}
}
void RosterController::handleNewMessageSent(QString *jid, QString *message)
{
// update the last message for this contact
rosterModel->setLastMessageForJid(jid, message);
// update the last exchanged date
updateLastExchangedOfJid(jid);
}
void RosterController::updateLastExchangedOfJid(QString *jid_)
{
QString dateTime = QDateTime::currentDateTime().toString(Qt::ISODate);
......
......@@ -44,6 +44,7 @@ public:
void requestRosterFromClient();
RosterModel* getRosterModel();
void setChatPartner(QString *chatPartner);
void handleNewMessageSent(QString*, QString*);
void updateLastExchangedOfJid(QString *jid_);
void newUnreadMessageForJid(const QString jid_);
void resetUnreadMessagesForJid(QString *jid_);
......
......@@ -193,3 +193,20 @@ void RosterModel::setUnreadMessageCountOfJid(const QString* jid_, const int coun
submit();
}
void RosterModel::setLastMessageForJid(QString *jid, QString *message)
{
QSqlQuery query;
query.prepare(QString("UPDATE Roster SET lastMessage = %1 WHERE jid = '%2'")
.arg(*message, *jid));
if (!query.exec()) {
qDebug("Failed to query database: %s", qPrintable(query.lastError().text()));
qDebug() << query.lastQuery();
}
if (!select()) {
qDebug() << "Error on select in RosterModel::setUnreadMessageCountOfJid";
}
submit();
}
......@@ -43,6 +43,7 @@ public:
void setLastExchangedOfJid(QString*, QString*);
int getUnreadMessageCountOfJid(const QString* jid_);
void setUnreadMessageCountOfJid(const QString* jid_, const int unreadMessageCount);
void setLastMessageForJid(QString*, QString*);
};
#endif // ROSTERMODEL_H
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