Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

MessageController: Use timestamp from received messages instead of current time

parent 0e2f3199
......@@ -46,7 +46,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
find_package(Qt5 ${QT_MIN_VERSION} REQUIRED NO_MODULE COMPONENTS Core Qml Quick Sql)
find_package(KF5Kirigami2 REQUIRED)
find_package(Swiften REQUIRED)
find_package(Boost ${BOOST_MIN_VERSION} REQUIRED COMPONENTS signals)
find_package(Boost ${BOOST_MIN_VERSION} REQUIRED COMPONENTS signals date_time)
include(GNUInstallDirs)
......@@ -99,6 +99,7 @@ target_link_libraries(${PROJECT_NAME}
Qt5::Qml
Qt5::Quick
Boost::signals
Boost::date_time
${SWIFTEN_LIBRARY}
)
......
......@@ -28,6 +28,8 @@
#include <QSqlQuery>
// Boost
#include <boost/bind.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/optional.hpp>
#include <boost/smart_ptr/make_shared.hpp>
// Swiften
#include <Swiften/Swiften.h>
......@@ -99,9 +101,19 @@ void MessageController::handleMessageReceived(Swift::Message::ref message_)
const QString author = QString(message_->getFrom().toBare().toString().c_str());
const QString author_resource = QString(message_->getFrom().getResource().c_str());
const QString recipient_resource = QString::fromStdString(client->getJID().getResource());
const QString timestamp = QDateTime::currentDateTime().toString(Qt::ISODate); // TODO: use timestamp from message
QString timestamp = QDateTime::currentDateTime().toString(Qt::ISODate); // fallback timestamp
const QString message = QString(message_->getBody()->c_str());
// get the timestamp from the message, if exists
boost::optional<boost::posix_time::ptime> timestampOpt = message_->getTimestamp();
if (timestampOpt)
{
timestamp = QString::fromStdString(
boost::posix_time::to_iso_extended_string(*timestampOpt)
);
}
messageModel->addMessage(&author, &author_resource, ownJid,
&recipient_resource, &timestamp, &message);
......
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