Commit 330ca8ee authored by Linus Jahn's avatar Linus Jahn
Browse files

MessageHandler: Minor code refactoring

parent 97766d13
...@@ -110,8 +110,7 @@ void MessageHandler::handleMessage(const QXmppMessage &msg) ...@@ -110,8 +110,7 @@ void MessageHandler::handleMessage(const QXmppMessage &msg)
bodyWords.prepend(msg.outOfBandUrl()); bodyWords.prepend(msg.outOfBandUrl());
#endif #endif
for (const QString &word : bodyWords) { for (const QString &word : bodyWords) {
bool isLink = word.startsWith("https://") || word.startsWith("http://"); if (!word.startsWith("https://") || !word.startsWith("http://"))
if (!isLink)
continue; continue;
// check message type by file name in link // check message type by file name in link
...@@ -136,10 +135,9 @@ void MessageHandler::handleMessage(const QXmppMessage &msg) ...@@ -136,10 +135,9 @@ void MessageHandler::handleMessage(const QXmppMessage &msg)
} }
// get possible delay (timestamp) // get possible delay (timestamp)
QDateTime stamp = msg.stamp(); entry.timestamp = (msg.stamp().isNull() || !msg.stamp().isValid())
if (!stamp.isValid() || stamp.isNull()) ? QDateTime::currentDateTimeUtc().toString(Qt::ISODate)
stamp = QDateTime::currentDateTime(); : msg.stamp().toUTC().toString(Qt::ISODate);
entry.timestamp = stamp.toUTC().toString(Qt::ISODate);
// save the message to the database // save the message to the database
#if QXMPP_VERSION >= QT_VERSION_CHECK(1, 0, 0) #if QXMPP_VERSION >= QT_VERSION_CHECK(1, 0, 0)
...@@ -197,8 +195,7 @@ void MessageHandler::sendMessage(QString toJid, QString body) ...@@ -197,8 +195,7 @@ void MessageHandler::sendMessage(QString toJid, QString body)
m.setId(msg.id); m.setId(msg.id);
m.setReceiptRequested(true); m.setReceiptRequested(true);
bool success = client->sendPacket(m); if (client->sendPacket(m))
if (success)
emit model->setMessageAsSentRequested(msg.id); emit model->setMessageAsSentRequested(msg.id);
// TODO: handle error // TODO: handle error
} }
...@@ -236,8 +233,7 @@ void MessageHandler::correctMessage(QString toJid, QString msgId, QString body) ...@@ -236,8 +233,7 @@ void MessageHandler::correctMessage(QString toJid, QString msgId, QString body)
m.setReplaceId(msgId); m.setReplaceId(msgId);
#endif #endif
bool success = client->sendPacket(m); if (client->sendPacket(m))
if (success)
emit model->setMessageAsSentRequested(msg.id); emit model->setMessageAsSentRequested(msg.id);
// TODO: handle error // TODO: handle error
} }
......
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