aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt4
-rw-r--r--events/event.h18
-rw-r--r--events/roomaliasesevent.cpp2
-rw-r--r--jobs/basejob.cpp4
-rw-r--r--room.cpp21
5 files changed, 31 insertions, 18 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index bb5a47cb..32792435 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -100,6 +100,10 @@ if ( CMAKE_VERSION VERSION_LESS "3.1" )
else ( CMAKE_VERSION VERSION_LESS "3.1" )
target_compile_features(qmatrixclient PRIVATE cxx_range_for)
target_compile_features(qmatrixclient PRIVATE cxx_override)
+ target_compile_features(qmatrixclient PRIVATE cxx_strong_enums)
+ target_compile_features(qmatrixclient PRIVATE cxx_lambdas)
+ target_compile_features(qmatrixclient PRIVATE cxx_auto_type)
+ target_compile_features(qmatrixclient PRIVATE cxx_generalized_initializers)
endif ( CMAKE_VERSION VERSION_LESS "3.1" )
target_link_libraries(qmatrixclient Qt5::Core Qt5::Network Qt5::Gui)
diff --git a/events/event.h b/events/event.h
index b25b1378..6a8d0e89 100644
--- a/events/event.h
+++ b/events/event.h
@@ -19,6 +19,8 @@
#ifndef QMATRIXCLIENT_EVENT_H
#define QMATRIXCLIENT_EVENT_H
+#include <algorithm>
+
#include <QtCore/QString>
#include <QtCore/QDateTime>
#include <QtCore/QJsonObject>
@@ -53,6 +55,22 @@ namespace QMatrixClient
class Private;
Private* d;
};
+
+ /**
+ * Finds a place in the timeline where a new event/message could be inserted.
+ * @return an iterator to an item with the earliest timestamp after
+ * the one of 'item'; or timeline.end(), if all events are earlier
+ */
+ template <class ItemT, template <typename> class ContT>
+ typename ContT<ItemT *>::iterator
+ findInsertionPos(ContT<ItemT *> & timeline, const ItemT *item)
+ {
+ return std::lower_bound (timeline.begin(), timeline.end(), item,
+ [](const ItemT * a, const ItemT * b) {
+ return a->timestamp() < b->timestamp();
+ }
+ );
+ }
}
#endif // QMATRIXCLIENT_EVENT_H
diff --git a/events/roomaliasesevent.cpp b/events/roomaliasesevent.cpp
index 6bbe0aff..54fb5682 100644
--- a/events/roomaliasesevent.cpp
+++ b/events/roomaliasesevent.cpp
@@ -64,7 +64,7 @@ QStringList RoomAliasesEvent::aliases() const
RoomAliasesEvent* RoomAliasesEvent::fromJson(const QJsonObject& obj)
{
- qDebug() << "!!!!";
+ qDebug() << "RoomAliasesEvent::fromJson";
RoomAliasesEvent* e = new RoomAliasesEvent();
e->parseJson(obj);
const QJsonObject contents = obj.value("content").toObject();
diff --git a/jobs/basejob.cpp b/jobs/basejob.cpp
index b7e1b718..bf4ade89 100644
--- a/jobs/basejob.cpp
+++ b/jobs/basejob.cpp
@@ -81,7 +81,7 @@ void BaseJob::start()
QNetworkRequest req = QNetworkRequest(url);
req.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
- req.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);\
+ req.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
req.setMaximumRedirectsAllowed(10);
#endif
QJsonDocument data = QJsonDocument(this->data());
@@ -124,7 +124,7 @@ void BaseJob::gotReply()
{
if( d->reply->error() != QNetworkReply::NoError )
{
- qDebug() << "NetworkError!!!";
+ qDebug() << "NetworkError!!!" << d->reply->error();
fail( NetworkError, d->reply->errorString() );
return;
}
diff --git a/room.cpp b/room.cpp
index 07128844..c5b674ae 100644
--- a/room.cpp
+++ b/room.cpp
@@ -71,14 +71,14 @@ Room::Room(Connection* connection, QString id)
d->connection = connection;
d->joinState = JoinState::Join;
d->gettingNewContent = false;
- qDebug() << "New Room: " << id;
+ qDebug() << "New Room:" << id;
//connection->getMembers(this); // I don't think we need this anymore in r0.0.1
}
Room::~Room()
{
- qDebug() << "deconstructing room " << this;
+ qDebug() << "deconstructing room" << this;
delete d;
}
@@ -284,15 +284,7 @@ Connection* Room::connection()
void Room::processMessageEvent(Event* event)
{
- for( int i=0; i<d->messageEvents.count(); i++ )
- {
- if( event->timestamp() < d->messageEvents.at(i)->timestamp() )
- {
- d->messageEvents.insert(i, event);
- return;
- }
- }
- d->messageEvents.append(event);
+ d->messageEvents.insert(findInsertionPos(d->messageEvents, event), event);
}
void Room::processStateEvent(Event* event)
@@ -302,7 +294,7 @@ void Room::processStateEvent(Event* event)
if (RoomNameEvent* nameEvent = static_cast<RoomNameEvent*>(event))
{
d->name = nameEvent->name();
- qDebug() << "room name: " << d->name;
+ qDebug() << "room name:" << d->name;
emit namesChanged(this);
} else
{
@@ -314,14 +306,14 @@ void Room::processStateEvent(Event* event)
{
RoomAliasesEvent* aliasesEvent = static_cast<RoomAliasesEvent*>(event);
d->aliases = aliasesEvent->aliases();
- qDebug() << "room aliases: " << d->aliases;
+ qDebug() << "room aliases:" << d->aliases;
emit namesChanged(this);
}
if( event->type() == EventType::RoomCanonicalAlias )
{
RoomCanonicalAliasEvent* aliasEvent = static_cast<RoomCanonicalAliasEvent*>(event);
d->canonicalAlias = aliasEvent->alias();
- qDebug() << "room canonical alias: " << d->canonicalAlias;
+ qDebug() << "room canonical alias:" << d->canonicalAlias;
emit namesChanged(this);
}
if( event->type() == EventType::RoomTopic )
@@ -334,7 +326,6 @@ void Room::processStateEvent(Event* event)
{
RoomMemberEvent* memberEvent = static_cast<RoomMemberEvent*>(event);
User* u = d->connection->user(memberEvent->userId());
- if( !u ) qDebug() << "addState: invalid user!" << u << memberEvent->userId();
u->processEvent(event);
if( memberEvent->membership() == MembershipType::Join and !d->users.contains(u) )
{