aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt47
-rw-r--r--connection.cpp2
-rw-r--r--connection.h12
-rw-r--r--connectiondata.h11
-rw-r--r--events/event.h7
-rw-r--r--events/receiptevent.cpp4
-rw-r--r--events/receiptevent.h6
-rw-r--r--events/roomaliasesevent.cpp1
-rw-r--r--events/roomaliasesevent.h5
-rw-r--r--events/roomcanonicalaliasevent.h5
-rw-r--r--events/roommemberevent.cpp1
-rw-r--r--events/roommemberevent.h5
-rw-r--r--events/roommessageevent.cpp1
-rw-r--r--events/roommessageevent.h11
-rw-r--r--events/roomnameevent.h5
-rw-r--r--events/roomtopicevent.h5
-rw-r--r--events/typingevent.h5
-rw-r--r--events/unknownevent.h5
-rw-r--r--jobs/basejob.h5
-rw-r--r--jobs/checkauthmethods.h13
-rw-r--r--jobs/geteventsjob.cpp96
-rw-r--r--jobs/geteventsjob.h49
-rw-r--r--jobs/joinroomjob.cpp1
-rw-r--r--jobs/joinroomjob.h5
-rw-r--r--jobs/leaveroomjob.h5
-rw-r--r--jobs/mediathumbnailjob.h5
-rw-r--r--jobs/passwordlogin.cpp2
-rw-r--r--jobs/passwordlogin.h5
-rw-r--r--jobs/postmessagejob.h5
-rw-r--r--jobs/postreceiptjob.cpp17
-rw-r--r--jobs/postreceiptjob.h10
-rw-r--r--jobs/roommembersjob.cpp70
-rw-r--r--jobs/roommembersjob.h47
-rw-r--r--jobs/roommessagesjob.cpp1
-rw-r--r--jobs/roommessagesjob.h5
-rw-r--r--jobs/syncjob.cpp4
-rw-r--r--jobs/syncjob.h7
-rw-r--r--joinstate.h5
-rw-r--r--kcoreaddons_export.h41
-rw-r--r--logmessage.cpp60
-rw-r--r--logmessage.h44
-rw-r--r--room.cpp148
-rw-r--r--room.h51
-rw-r--r--state.h5
-rw-r--r--user.h5
45 files changed, 229 insertions, 620 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5449446b..24cdd58d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -19,18 +19,28 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
"MinSizeRel" "RelWithDebInfo")
endif()
-find_package(Qt5Core 5.2.0 REQUIRED) # For JSON (de)serialization
-find_package(Qt5Network 5.2.0 REQUIRED) # For networking
-find_package(Qt5Gui 5.2.0 REQUIRED) # For userpics
+if ( CMAKE_VERSION VERSION_LESS "3.1" )
+ CHECK_CXX_COMPILER_FLAG("-std=c++11" STD_FLAG_SUPPORTED)
+ if ( STD_FLAG_SUPPORTED )
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
+ endif ( STD_FLAG_SUPPORTED )
+else ( CMAKE_VERSION VERSION_LESS "3.1" )
+ set(CMAKE_CXX_STANDARD 11)
+endif ( CMAKE_VERSION VERSION_LESS "3.1" )
+
+find_package(Qt5 5.2.1 REQUIRED Network Gui)
+get_filename_component(Qt5_Prefix "${Qt5_DIR}/../../../.." ABSOLUTE)
message( STATUS )
-message( STATUS "================================================================================" )
-message( STATUS " libqmatrixclient Build Information " )
-message( STATUS "================================================================================" )
-message( STATUS "Building with: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}" )
-message( STATUS "Install Prefix: ${CMAKE_INSTALL_PREFIX}" )
-message( STATUS "Path to Qt Core: ${Qt5Core_DIR}" )
-message( STATUS "================================================================================" )
+message( STATUS "=============================================================================" )
+message( STATUS " libqmatrixclient Build Information" )
+message( STATUS "=============================================================================" )
+if (CMAKE_BUILD_TYPE)
+ message( STATUS "Build type: ${CMAKE_BUILD_TYPE}")
+endif(CMAKE_BUILD_TYPE)
+message( STATUS "Using compiler: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}" )
+message( STATUS "Using Qt ${Qt5_VERSION} at ${Qt5_Prefix}" )
+message( STATUS "=============================================================================" )
message( STATUS )
# Set up source files
@@ -39,7 +49,6 @@ set(libqmatrixclient_SRCS
connection.cpp
room.cpp
user.cpp
- logmessage.cpp
state.cpp
settings.cpp
events/event.cpp
@@ -69,20 +78,4 @@ add_library(qmatrixclient ${libqmatrixclient_SRCS})
set_property(TARGET qmatrixclient PROPERTY VERSION "0.0.0")
set_property(TARGET qmatrixclient PROPERTY SOVERSION 0 )
-if ( CMAKE_VERSION VERSION_LESS "3.1" )
- CHECK_CXX_COMPILER_FLAG("-std=c++11" STD_FLAG_SUPPORTED)
- if ( STD_FLAG_SUPPORTED )
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
- endif ( STD_FLAG_SUPPORTED )
-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)
- target_compile_features(qmatrixclient PRIVATE cxx_nullptr)
- target_compile_features(qmatrixclient PRIVATE cxx_variadic_templates)
-endif ( CMAKE_VERSION VERSION_LESS "3.1" )
-
target_link_libraries(qmatrixclient Qt5::Core Qt5::Network Qt5::Gui)
diff --git a/connection.cpp b/connection.cpp
index e0274fd7..0f115e3a 100644
--- a/connection.cpp
+++ b/connection.cpp
@@ -211,7 +211,7 @@ PostReceiptJob* Connection::postReceipt(Room* room, Event* event)
void Connection::joinRoom(QString roomAlias)
{
JoinRoomJob* job = new JoinRoomJob(d->data, roomAlias);
- connect( job, &SyncJob::success, [=] () {
+ connect( job, &BaseJob::success, [=] () {
if ( Room* r = provideRoom(job->roomId()) )
emit joinedRoom(r);
});
diff --git a/connection.h b/connection.h
index c5dad246..0e25d695 100644
--- a/connection.h
+++ b/connection.h
@@ -16,11 +16,11 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef QMATRIXCLIENT_CONNECTION_H
-#define QMATRIXCLIENT_CONNECTION_H
+#pragma once
#include <QtCore/QObject>
#include <QtCore/QUrl>
+#include <QtCore/QSize>
namespace QMatrixClient
{
@@ -83,13 +83,13 @@ namespace QMatrixClient
void connectionError(QString error);
void resolveError(QString error);
//void jobError(BaseJob* job);
-
+
protected:
/**
* @brief Access the underlying ConnectionData class
*/
ConnectionData* connectionData();
-
+
/**
* @brief Find a (possibly new) Room object for the specified id
* Use this method whenever you need to find a Room object in
@@ -105,7 +105,7 @@ namespace QMatrixClient
* makes it possible for derived classes to have its own User class
*/
virtual User* createUser(QString userId);
-
+
/**
* makes it possible for derived classes to have its own Room class
*/
@@ -116,5 +116,3 @@ namespace QMatrixClient
Private* d;
};
}
-
-#endif // QMATRIXCLIENT_CONNECTION_H
diff --git a/connectiondata.h b/connectiondata.h
index 5c8342d7..89e30e4d 100644
--- a/connectiondata.h
+++ b/connectiondata.h
@@ -16,8 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef QMATRIXCLIENT_CONNECTIONDATA_H
-#define QMATRIXCLIENT_CONNECTIONDATA_H
+#pragma once
#include <QtCore/QUrl>
@@ -30,7 +29,7 @@ namespace QMatrixClient
public:
ConnectionData(QUrl baseUrl);
virtual ~ConnectionData();
-
+
//bool isConnected() const;
QString accessToken() const;
QUrl baseUrl() const;
@@ -42,11 +41,9 @@ namespace QMatrixClient
QString lastEvent() const;
void setLastEvent( QString identifier );
-
+
private:
class Private;
Private* d;
};
-}
-
-#endif // QMATRIXCLIENT_CONNECTIONDATA_H
+}
diff --git a/events/event.h b/events/event.h
index 2e5e5da1..12b0ebd5 100644
--- a/events/event.h
+++ b/events/event.h
@@ -16,10 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef QMATRIXCLIENT_EVENT_H
-#define QMATRIXCLIENT_EVENT_H
-
-#include <algorithm>
+#pragma once
#include <QtCore/QString>
#include <QtCore/QDateTime>
@@ -112,5 +109,3 @@ namespace QMatrixClient
return fallback;
}
}
-
-#endif // QMATRIXCLIENT_EVENT_H
diff --git a/events/receiptevent.cpp b/events/receiptevent.cpp
index 29d78a20..74e89ba2 100644
--- a/events/receiptevent.cpp
+++ b/events/receiptevent.cpp
@@ -35,13 +35,11 @@ Example of a Receipt Event:
#include "receiptevent.h"
-#include <QtCore/QJsonObject>
#include <QtCore/QJsonArray>
#include <QtCore/QDebug>
using namespace QMatrixClient;
-
class ReceiptEvent::Private
{
public:
@@ -83,7 +81,7 @@ ReceiptEvent* ReceiptEvent::fromJson(const QJsonObject& obj)
{
const QJsonObject user = reads[userId].toObject();
const QDateTime time = QDateTime::fromMSecsSinceEpoch( (quint64) user["ts"].toDouble(), Qt::UTC );
- receipts.push_back({ eventId, userId, time });
+ receipts.push_back({ userId, time });
}
e->d->eventToReceipts.insert(eventId, receipts);
}
diff --git a/events/receiptevent.h b/events/receiptevent.h
index cf08fed9..5ca33f75 100644
--- a/events/receiptevent.h
+++ b/events/receiptevent.h
@@ -16,8 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef QMATRIXCLIENT_RECEIPTEVENT_H
-#define QMATRIXCLIENT_RECEIPTEVENT_H
+#pragma once
#include "event.h"
@@ -28,7 +27,6 @@ namespace QMatrixClient
class Receipt
{
public:
- QString eventId;
QString userId;
QDateTime timestamp;
};
@@ -56,5 +54,3 @@ namespace QMatrixClient
Private* d;
};
}
-
-#endif // QMATRIXCLIENT_RECEIPTEVENT_H
diff --git a/events/roomaliasesevent.cpp b/events/roomaliasesevent.cpp
index 15b4c54e..9c64e40c 100644
--- a/events/roomaliasesevent.cpp
+++ b/events/roomaliasesevent.cpp
@@ -34,7 +34,6 @@
#include "roomaliasesevent.h"
-#include <QtCore/QJsonObject>
#include <QtCore/QJsonArray>
#include <QtCore/QDebug>
diff --git a/events/roomaliasesevent.h b/events/roomaliasesevent.h
index 89ea63b8..8f638be2 100644
--- a/events/roomaliasesevent.h
+++ b/events/roomaliasesevent.h
@@ -16,8 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef QMATRIXCLIENT_ROOMALIASESEVENT_H
-#define QMATRIXCLIENT_ROOMALIASESEVENT_H
+#pragma once
#include "event.h"
@@ -40,5 +39,3 @@ namespace QMatrixClient
Private* d;
};
}
-
-#endif // QMATRIXCLIENT_ROOMALIASESEVENT_H \ No newline at end of file
diff --git a/events/roomcanonicalaliasevent.h b/events/roomcanonicalaliasevent.h
index f3ab8e5a..87219be6 100644
--- a/events/roomcanonicalaliasevent.h
+++ b/events/roomcanonicalaliasevent.h
@@ -16,8 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef QMATRIXCLIENT_ROOMCANONICALALIASEVENT_H
-#define QMATRIXCLIENT_ROOMCANONICALALIASEVENT_H
+#pragma once
#include "event.h"
@@ -38,5 +37,3 @@ namespace QMatrixClient
Private* d;
};
}
-
-#endif // QMATRIXCLIENT_ROOMCANONICALALIASEVENT_H \ No newline at end of file
diff --git a/events/roommemberevent.cpp b/events/roommemberevent.cpp
index e58bda8f..93b4bb32 100644
--- a/events/roommemberevent.cpp
+++ b/events/roommemberevent.cpp
@@ -19,7 +19,6 @@
#include "roommemberevent.h"
#include <QtCore/QDebug>
-#include <QtCore/QUrl>
using namespace QMatrixClient;
diff --git a/events/roommemberevent.h b/events/roommemberevent.h
index e47013cb..f37cdc04 100644
--- a/events/roommemberevent.h
+++ b/events/roommemberevent.h
@@ -16,8 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef QMATRIXCLIENT_ROOMMEMBEREVENT_H
-#define QMATRIXCLIENT_ROOMMEMBEREVENT_H
+#pragma once
#include <QtCore/QJsonObject>
#include <QtCore/QUrl>
@@ -46,5 +45,3 @@ namespace QMatrixClient
Private* d;
};
}
-
-#endif // QMATRIXCLIENT_ROOMMEMBEREVENT_H
diff --git a/events/roommessageevent.cpp b/events/roommessageevent.cpp
index 76152102..bb28d682 100644
--- a/events/roommessageevent.cpp
+++ b/events/roommessageevent.cpp
@@ -18,7 +18,6 @@
#include "roommessageevent.h"
-#include <QtCore/QJsonObject>
#include <QtCore/QMimeDatabase>
#include <QtCore/QDebug>
diff --git a/events/roommessageevent.h b/events/roommessageevent.h
index 591b2df9..67789ef7 100644
--- a/events/roommessageevent.h
+++ b/events/roommessageevent.h
@@ -16,8 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef QMATRIXCLIENT_ROOMMESSAGEEVENT_H
-#define QMATRIXCLIENT_ROOMMESSAGEEVENT_H
+#pragma once
#include <QtCore/QUrl>
#include <QtCore/QMimeType>
@@ -42,7 +41,7 @@ namespace QMatrixClient
public:
RoomMessageEvent();
virtual ~RoomMessageEvent();
-
+
QString userId() const;
MessageEventType msgtype() const;
@@ -57,9 +56,9 @@ namespace QMatrixClient
QString body() const;
MessageEventContent::Base* content() const;
-
+
static RoomMessageEvent* fromJson( const QJsonObject& obj );
-
+
private:
class Private;
Private* d;
@@ -145,5 +144,3 @@ namespace QMatrixClient
using AudioContent = ThumbnailedContent<AudioInfo>;
}
}
-
-#endif // QMATRIXCLIENT_ROOMMESSAGEEVENT_H
diff --git a/events/roomnameevent.h b/events/roomnameevent.h
index 436a1dd4..0997ad9c 100644
--- a/events/roomnameevent.h
+++ b/events/roomnameevent.h
@@ -16,8 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef QMATRIXCLIENT_ROOMNAMEEVENT_H
-#define QMATRIXCLIENT_ROOMNAMEEVENT_H
+#pragma once
#include "event.h"
@@ -40,5 +39,3 @@ private:
};
}
-
-#endif // QMATRIXCLIENT_ROOMNAMEEVENT_H
diff --git a/events/roomtopicevent.h b/events/roomtopicevent.h
index f4d87eef..d4347953 100644
--- a/events/roomtopicevent.h
+++ b/events/roomtopicevent.h
@@ -16,8 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef QMATRIXCLIENT_ROOMTOPICEVENT_H
-#define QMATRIXCLIENT_ROOMTOPICEVENT_H
+#pragma once
#include <QtCore/QJsonObject>
@@ -40,5 +39,3 @@ namespace QMatrixClient
Private* d;
};
}
-
-#endif // QMATRIXCLIENT_ROOMTOPICEVENT_H
diff --git a/events/typingevent.h b/events/typingevent.h
index 2625dc66..5a8b045c 100644
--- a/events/typingevent.h
+++ b/events/typingevent.h
@@ -16,8 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef QMATRIXCLIENT_TYPINGEVENT_H
-#define QMATRIXCLIENT_TYPINGEVENT_H
+#pragma once
#include <QtCore/QStringList>
@@ -40,5 +39,3 @@ namespace QMatrixClient
Private* d;
};
}
-
-#endif // QMATRIXCLIENT_TYPINGEVENT_H
diff --git a/events/unknownevent.h b/events/unknownevent.h
index 58493095..51f2c4be 100644
--- a/events/unknownevent.h
+++ b/events/unknownevent.h
@@ -16,8 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef QMATRIXCLIENT_UNKNOWNEVENT_H
-#define QMATRIXCLIENT_UNKNOWNEVENT_H
+#pragma once
#include "event.h"
@@ -39,5 +38,3 @@ namespace QMatrixClient
Private* d;
};
}
-
-#endif // QMATRIXCLIENT_UNKNOWNEVENT_H \ No newline at end of file
diff --git a/jobs/basejob.h b/jobs/basejob.h
index b356eb7e..55267def 100644
--- a/jobs/basejob.h
+++ b/jobs/basejob.h
@@ -16,8 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef QMATRIXCLIENT_BASEJOB_H
-#define QMATRIXCLIENT_BASEJOB_H
+#pragma once
#include <QtCore/QObject>
#include <QtCore/QJsonDocument>
@@ -229,5 +228,3 @@ namespace QMatrixClient
QScopedPointer<Private> d;
};
}
-
-#endif // QMATRIXCLIENT_BASEJOB_H
diff --git a/jobs/checkauthmethods.h b/jobs/checkauthmethods.h
index e6aeba69..f6eb978a 100644
--- a/jobs/checkauthmethods.h
+++ b/jobs/checkauthmethods.h
@@ -16,30 +16,27 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef QMATRIXCLIENT_CHECKAUTHMETHODS_H
-#define QMATRIXCLIENT_CHECKAUTHMETHODS_H
+#pragma once
#include "basejob.h"
namespace QMatrixClient
{
class ConnectionData;
-
+
class CheckAuthMethods : public BaseJob
{
public:
CheckAuthMethods(ConnectionData* connection);
virtual ~CheckAuthMethods();
-
+
QString session();
-
+
protected:
Status parseJson(const QJsonDocument& data) override;
-
+
private:
class Private;
Private* d;
};
}
-
-#endif // QMATRIXCLIENT_CHECKAUTHMETHODS_H
diff --git a/jobs/geteventsjob.cpp b/jobs/geteventsjob.cpp
deleted file mode 100644
index 748a0189..00000000
--- a/jobs/geteventsjob.cpp
+++ /dev/null
@@ -1,96 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2015 Felix Rohrbach <kde@fxrh.de>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include "geteventsjob.h"
-
-#include <QtCore/QJsonDocument>
-#include <QtCore/QJsonObject>
-#include <QtCore/QJsonValue>
-#include <QtCore/QJsonArray>
-#include <QtCore/QDebug>
-
-#include <QtNetwork/QNetworkReply>
-
-#include "../room.h"
-#include "../connectiondata.h"
-#include "../events/event.h"
-
-using namespace QMatrixClient;
-
-class GetEventsJob::Private
-{
- public:
- Private() {}
-
- QList<Event*> events;
- QString from;
-};
-
-GetEventsJob::GetEventsJob(ConnectionData* connection, QString from)
- : BaseJob(connection, JobHttpType::GetJob)
- , d(new Private)
-{
- if( from.isEmpty() )
- from = connection->lastEvent();
- d->from = from;
-}
-
-GetEventsJob::~GetEventsJob()
-{
- delete d;
-}
-
-QList< Event* > GetEventsJob::events()
-{
- return d->events;
-}
-
-QString GetEventsJob::apiPath()
-{
- return "_matrix/client/r0/events";
-}
-
-QUrlQuery GetEventsJob::query()
-{
- QUrlQuery query;
- query.addQueryItem("from", d->from);
- return query;
-}
-
-void GetEventsJob::parseJson(const QJsonDocument& data)
-{
- QJsonObject json = data.object();
- if( !json.contains("chunk") || !json.value("chunk").isArray() )
- {
- fail( BaseJob::UserDefinedError, "Couldn't find chunk" );
- return;
- }
- QJsonArray chunk = json.value("chunk").toArray();
-// qDebug() << chunk;
- for( const QJsonValue& val: chunk )
- {
- QJsonObject eventObj = val.toObject();
- Event* event = Event::fromJson(eventObj);
- if( event )
- {
- d->events.append(event);
- }
- }
- connection()->setLastEvent( json.value("end").toString() );
- emitResult();
-} \ No newline at end of file
diff --git a/jobs/geteventsjob.h b/jobs/geteventsjob.h
deleted file mode 100644
index d2eb75eb..00000000
--- a/jobs/geteventsjob.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2015 Felix Rohrbach <kde@fxrh.de>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef QMATRIXCLIENT_GETEVENTSJOB_H
-#define QMATRIXCLIENT_GETEVENTSJOB_H
-
-#include "basejob.h"
-
-namespace QMatrixClient
-{
- class ConnectionData;
- class Room;
- class Event;
- class GetEventsJob: public BaseJob
- {
- Q_OBJECT
- public:
- GetEventsJob(ConnectionData* connection, QString from=QString());
- virtual ~GetEventsJob();
-
- QList<Event*> events();
-
- protected:
- QString apiPath();
- QUrlQuery query();
- void parseJson(const QJsonDocument& data);
-
- private:
- class Private;
- Private* d;
- };
-}
-
-#endif // QMATRIXCLIENT_GETEVENTSJOB_H \ No newline at end of file
diff --git a/jobs/joinroomjob.cpp b/jobs/joinroomjob.cpp
index d443acd7..073084c4 100644
--- a/jobs/joinroomjob.cpp
+++ b/jobs/joinroomjob.cpp
@@ -18,7 +18,6 @@
#include "joinroomjob.h"
-#include <QtCore/QJsonObject>
#include <QtNetwork/QNetworkReply>
#include "../connectiondata.h"
diff --git a/jobs/joinroomjob.h b/jobs/joinroomjob.h
index c1eebbef..a69843ed 100644
--- a/jobs/joinroomjob.h
+++ b/jobs/joinroomjob.h
@@ -16,8 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef QMATRIXCLIENT_JOINROOMJOB_H
-#define QMATRIXCLIENT_JOINROOMJOB_H
+#pragma once
#include "basejob.h"
@@ -41,5 +40,3 @@ namespace QMatrixClient
Private* d;
};
}
-
-#endif // QMATRIXCLIENT_JOINROOMJOB_H
diff --git a/jobs/leaveroomjob.h b/jobs/leaveroomjob.h
index 492233f6..4a62810f 100644
--- a/jobs/leaveroomjob.h
+++ b/jobs/leaveroomjob.h
@@ -16,8 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef QMATRIXCLIENT_LEAVEROOMJOB_H
-#define QMATRIXCLIENT_LEAVEROOMJOB_H
+#pragma once
#include "basejob.h"
@@ -33,5 +32,3 @@ namespace QMatrixClient
virtual ~LeaveRoomJob();
};
}
-
-#endif // QMATRIXCLIENT_LEAVEROOMJOB_H
diff --git a/jobs/mediathumbnailjob.h b/jobs/mediathumbnailjob.h
index 15bec9a1..cf1e9afb 100644
--- a/jobs/mediathumbnailjob.h
+++ b/jobs/mediathumbnailjob.h
@@ -16,8 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef QMATRIXCLIENT_MEDIATHUMBNAILJOB_H
-#define QMATRIXCLIENT_MEDIATHUMBNAILJOB_H
+#pragma once
#include "basejob.h"
@@ -44,5 +43,3 @@ namespace QMatrixClient
Private* d;
};
}
-
-#endif // QMATRIXCLIENT_MEDIATHUMBNAILJOB_H
diff --git a/jobs/passwordlogin.cpp b/jobs/passwordlogin.cpp
index a7a405aa..c78c15b5 100644
--- a/jobs/passwordlogin.cpp
+++ b/jobs/passwordlogin.cpp
@@ -18,8 +18,6 @@
#include "passwordlogin.h"
-#include <QtCore/QJsonDocument>
-#include <QtCore/QJsonObject>
#include <QtNetwork/QNetworkReply>
#include "../connectiondata.h"
diff --git a/jobs/passwordlogin.h b/jobs/passwordlogin.h
index 156865a3..c1291389 100644
--- a/jobs/passwordlogin.h
+++ b/jobs/passwordlogin.h
@@ -16,8 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef QMATRIXCLIENT_PASSWORDLOGIN_H
-#define QMATRIXCLIENT_PASSWORDLOGIN_H
+#pragma once
#include "basejob.h"
@@ -43,5 +42,3 @@ namespace QMatrixClient
Private* d;
};
}
-
-#endif // QMATRIXCLIENT_PASSWORDLOGIN_H
diff --git a/jobs/postmessagejob.h b/jobs/postmessagejob.h
index 9d52ae8d..2e1989fd 100644
--- a/jobs/postmessagejob.h
+++ b/jobs/postmessagejob.h
@@ -16,8 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef QMATRIXCLIENT_POSTMESSAGEJOB_H
-#define QMATRIXCLIENT_POSTMESSAGEJOB_H
+#pragma once
#include "basejob.h"
@@ -40,5 +39,3 @@ namespace QMatrixClient
Private* d;
};
}
-
-#endif // QMATRIXCLIENT_POSTMESSAGEJOB_H
diff --git a/jobs/postreceiptjob.cpp b/jobs/postreceiptjob.cpp
index d0c82b4f..1eaefc2a 100644
--- a/jobs/postreceiptjob.cpp
+++ b/jobs/postreceiptjob.cpp
@@ -24,23 +24,10 @@
using namespace QMatrixClient;
-class PostReceiptJob::Private
-{
- public:
- Private() {}
-
- QString roomId;
- QString eventId;
-};
-
PostReceiptJob::PostReceiptJob(ConnectionData* connection, QString roomId, QString eventId)
: BaseJob(connection, JobHttpType::PostJob, "PostReceiptJob",
QString("/_matrix/client/r0/rooms/%1/receipt/m.read/%2").arg(roomId, eventId))
- , d(new Private)
-{
-}
+{ }
PostReceiptJob::~PostReceiptJob()
-{
- delete d;
-}
+{ }
diff --git a/jobs/postreceiptjob.h b/jobs/postreceiptjob.h
index 4e047b3a..c0002dc0 100644
--- a/jobs/postreceiptjob.h
+++ b/jobs/postreceiptjob.h
@@ -16,24 +16,16 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef QMATRIXCLIENT_POSTRECEIPTJOB_H
-#define QMATRIXCLIENT_POSTRECEIPTJOB_H
+#pragma once
#include "basejob.h"
namespace QMatrixClient
{
- class Room;
class PostReceiptJob: public BaseJob
{
public:
PostReceiptJob(ConnectionData* connection, QString roomId, QString eventId);
virtual ~PostReceiptJob();
-
- private:
- class Private;
- Private* d;
};
}
-
-#endif // QMATRIXCLIENT_POSTRECEIPTJOB_H
diff --git a/jobs/roommembersjob.cpp b/jobs/roommembersjob.cpp
deleted file mode 100644
index 7fc44c63..00000000
--- a/jobs/roommembersjob.cpp
+++ /dev/null
@@ -1,70 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2015 Felix Rohrbach <kde@fxrh.de>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include "roommembersjob.h"
-
-#include <QtCore/QJsonObject>
-#include <QtCore/QJsonArray>
-#include <QtCore/QDebug>
-
-#include "../room.h"
-#include "../state.h"
-
-using namespace QMatrixClient;
-
-class RoomMembersJob::Private
-{
- public:
- Room* room;
- QList<State*> states;
-};
-
-RoomMembersJob::RoomMembersJob(ConnectionData* data, Room* room)
- : BaseJob(data, JobHttpType::GetJob, "RoomMembersJob")
- , d(new Private)
-{
- d->room = room;
-}
-
-RoomMembersJob::~RoomMembersJob()
-{
- delete d;
-}
-
-QList< State* > RoomMembersJob::states()
-{
- return d->states;
-}
-
-QString RoomMembersJob::apiPath() const
-{
- return QString("_matrix/client/r0/rooms/%1/members").arg(d->room->id());
-}
-
-BaseJob::Status RoomMembersJob::parseJson(const QJsonDocument& data)
-{
- QJsonArray chunk = data.object().value("chunk").toArray();
- for( const QJsonValue& val : chunk )
- {
- State* state = State::fromJson(val.toObject());
- if( state )
- d->states.append(state);
- }
- qDebug() << "States: " << d->states.count();
- return Success;
-}
diff --git a/jobs/roommembersjob.h b/jobs/roommembersjob.h
deleted file mode 100644
index 04803d67..00000000
--- a/jobs/roommembersjob.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2015 Felix Rohrbach <kde@fxrh.de>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef QMATRIXCLIENT_ROOMMEMBERSJOB_H
-#define QMATRIXCLIENT_ROOMMEMBERSJOB_H
-
-#include "basejob.h"
-
-namespace QMatrixClient
-{
- class ConnectionData;
- class Room;
- class State;
- class RoomMembersJob: public BaseJob
- {
- public:
- RoomMembersJob(ConnectionData* data, Room* room);
- virtual ~RoomMembersJob();
-
- QList<State*> states();
-
- protected:
- QString apiPath() const override;
- Status parseJson(const QJsonDocument& data) override;
-
- private:
- class Private;
- Private* d;
- };
-}
-
-#endif // QMATRIXCLIENT_ROOMMEMBERSJOB_H
diff --git a/jobs/roommessagesjob.cpp b/jobs/roommessagesjob.cpp
index d67ffc2a..1e53f601 100644
--- a/jobs/roommessagesjob.cpp
+++ b/jobs/roommessagesjob.cpp
@@ -19,7 +19,6 @@
#include "roommessagesjob.h"
#include "../room.h"
-#include <QtCore/QJsonObject>
#include <QtCore/QJsonArray>
using namespace QMatrixClient;
diff --git a/jobs/roommessagesjob.h b/jobs/roommessagesjob.h
index 227ffac2..348217cc 100644
--- a/jobs/roommessagesjob.h
+++ b/jobs/roommessagesjob.h
@@ -16,8 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef QMATRIXCLIENT_ROOMMESSAGESJOB_H
-#define QMATRIXCLIENT_ROOMMESSAGESJOB_H
+#pragma once
#include "basejob.h"
@@ -47,5 +46,3 @@ namespace QMatrixClient
Private* d;
};
}
-
-#endif // QMATRIXCLIENT_ROOMMESSAGESJOB_H
diff --git a/jobs/syncjob.cpp b/jobs/syncjob.cpp
index 521f829e..554ac0f7 100644
--- a/jobs/syncjob.cpp
+++ b/jobs/syncjob.cpp
@@ -18,13 +18,9 @@
#include "syncjob.h"
-#include <QtCore/QJsonDocument>
-#include <QtCore/QJsonObject>
-#include <QtCore/QJsonValue>
#include <QtCore/QJsonArray>
#include <QtCore/QDebug>
-#include "../room.h"
#include "../connectiondata.h"
using namespace QMatrixClient;
diff --git a/jobs/syncjob.h b/jobs/syncjob.h
index e7b23d16..be1d4776 100644
--- a/jobs/syncjob.h
+++ b/jobs/syncjob.h
@@ -16,8 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef QMATRIXCLIENT_SYNCJOB_H
-#define QMATRIXCLIENT_SYNCJOB_H
+#pragma once
#include "basejob.h"
@@ -102,7 +101,7 @@ namespace QMatrixClient
SyncJob(ConnectionData* connection, QString since = {}, QString filter = {},
int timeout = -1, QString presence = {});
virtual ~SyncJob();
-
+
SyncData& roomData();
QString nextBatch() const;
@@ -114,5 +113,3 @@ namespace QMatrixClient
Private* d;
};
}
-
-#endif // QMATRIXCLIENT_SYNCJOB_H
diff --git a/joinstate.h b/joinstate.h
index e7175b2b..348ca8a6 100644
--- a/joinstate.h
+++ b/joinstate.h
@@ -16,8 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef QMATRIXCLIENT_JOINSTATE_H
-#define QMATRIXCLIENT_JOINSTATE_H
+#pragma once
namespace QMatrixClient
{
@@ -28,5 +27,3 @@ namespace QMatrixClient
Leave
};
}
-
-#endif // QMATRIXCLIENT_JOINSTATE_H \ No newline at end of file
diff --git a/kcoreaddons_export.h b/kcoreaddons_export.h
deleted file mode 100644
index 00c13059..00000000
--- a/kcoreaddons_export.h
+++ /dev/null
@@ -1,41 +0,0 @@
-
-#ifndef KCOREADDONS_EXPORT_H
-#define KCOREADDONS_EXPORT_H
-
-#ifdef KCOREADDONS_STATIC_DEFINE
-# define KCOREADDONS_EXPORT
-# define KCOREADDONS_NO_EXPORT
-#else
-# ifndef KCOREADDONS_EXPORT
-# ifdef KF5CoreAddons_EXPORTS
- /* We are building this library */
-# define KCOREADDONS_EXPORT __attribute__((visibility("default")))
-# else
- /* We are using this library */
-# define KCOREADDONS_EXPORT __attribute__((visibility("default")))
-# endif
-# endif
-
-# ifndef KCOREADDONS_NO_EXPORT
-# define KCOREADDONS_NO_EXPORT __attribute__((visibility("hidden")))
-# endif
-#endif
-
-#ifndef KCOREADDONS_DEPRECATED
-# define KCOREADDONS_DEPRECATED __attribute__ ((__deprecated__))
-#endif
-
-#ifndef KCOREADDONS_DEPRECATED_EXPORT
-# define KCOREADDONS_DEPRECATED_EXPORT KCOREADDONS_EXPORT KCOREADDONS_DEPRECATED
-#endif
-
-#ifndef KCOREADDONS_DEPRECATED_NO_EXPORT
-# define KCOREADDONS_DEPRECATED_NO_EXPORT KCOREADDONS_NO_EXPORT KCOREADDONS_DEPRECATED
-#endif
-
-#define DEFINE_NO_DEPRECATED 0
-#if DEFINE_NO_DEPRECATED
-# define KCOREADDONS_NO_DEPRECATED
-#endif
-
-#endif
diff --git a/logmessage.cpp b/logmessage.cpp
deleted file mode 100644
index 8b385c25..00000000
--- a/logmessage.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2015 Felix Rohrbach <kde@fxrh.de>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include "logmessage.h"
-
-using namespace QMatrixClient;
-
-class LogMessage::Private
-{
- public:
- Private() {}
-
- MessageType type;
- QString message;
- QString author;
-};
-
-LogMessage::LogMessage(LogMessage::MessageType type, QString message, QString author)
- : d(new Private)
-{
- d->type = type;
- d->message = message;
- d->author = author;
-}
-
-LogMessage::~LogMessage()
-{
- delete d;
-}
-
-LogMessage::MessageType LogMessage::type() const
-{
- return d->type;
-}
-
-QString LogMessage::message() const
-{
- return d->message;
-}
-
-QString LogMessage::author() const
-{
- return d->author;
-}
-
diff --git a/logmessage.h b/logmessage.h
deleted file mode 100644
index bb58af65..00000000
--- a/logmessage.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2015 Felix Rohrbach <kde@fxrh.de>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef QMATRIXCLIENT_LOGMESSAGE_H
-#define QMATRIXCLIENT_LOGMESSAGE_H
-
-#include <QtCore/QString>
-
-namespace QMatrixClient
-{
- class LogMessage
- {
- public:
- enum MessageType{ UserMessage, StatusMessage };
-
- LogMessage( MessageType type, QString message, QString author=QString() );
- virtual ~LogMessage();
-
- MessageType type() const;
- QString message() const;
- QString author() const;
-
- private:
- class Private;
- Private* d;
- };
-}
-
-#endif // QMATRIXCLIENT_LOGMESSAGE_H \ No newline at end of file
diff --git a/room.cpp b/room.cpp
index c2a1ce70..2d32c430 100644
--- a/room.cpp
+++ b/room.cpp
@@ -28,7 +28,6 @@
#include "connection.h"
#include "state.h"
#include "user.h"
-#include "events/event.h"
#include "events/roommessageevent.h"
#include "events/roomnameevent.h"
#include "events/roomaliasesevent.h"
@@ -49,7 +48,7 @@ class Room::Private
Private(Connection* c, const QString& id_)
: q(nullptr), connection(c), id(id_), joinState(JoinState::Join)
- , roomMessagesJob(nullptr)
+ , unreadMessages(false), roomMessagesJob(nullptr)
{ }
Room* q;
@@ -68,6 +67,7 @@ class Room::Private
QString displayname;
QString topic;
JoinState joinState;
+ bool unreadMessages;
int highlightCount;
int notificationCount;
members_map_t membersMap;
@@ -90,6 +90,7 @@ class Room::Private
void getPreviousContent();
+ bool isEventNotable(const Event* e) const;
private:
QString calculateDisplayname() const;
QString roomNameFromMemberNames(const QList<User*>& userlist) const;
@@ -167,34 +168,77 @@ void Room::setLastReadEvent(User* user, QString eventId)
{
d->lastReadEvent.insert(user, eventId);
emit lastReadEventChanged(user);
+ if (user == d->connection->user())
+ emit readMarkerPromoted();
}
-bool Room::promoteReadMarker(User* user, QString eventId)
+Room::Timeline::const_iterator Room::promoteReadMarker(User* u, QString eventId)
{
- // Check that the new read event is not before the previously set - only
- // allow the read marker to move down the timeline, not up.
- QString prevLastReadId = lastReadEvent(user);
+ QString prevLastReadId = lastReadEvent(u);
+ int stillUnreadMessagesCount = 0;
+ auto it = d->messageEvents.end();
+ Event* targetEvent = nullptr;
// Older Qt doesn't provide rbegin()/rend() for Qt containers
- for (auto it = messageEvents().end(); it != messageEvents().begin();)
+ while (it != d->messageEvents.begin())
{
--it;
+ // Check that the new read event is not before the previously set - only
+ // allow the read marker to move down the timeline, not up.
if (prevLastReadId == (*it)->id())
- return false;
+ break;
+
+ // Found the message to mark as read; if there are messages from
+ // that user right below this one, automatically promote the marker
+ // to them instead of this one; still return this one to save
+ // markMessagesAsRead() from going through local messages over again.
if (eventId == (*it)->id())
{
- setLastReadEvent(user, eventId);
- return true;
+ setLastReadEvent(u, (targetEvent ? targetEvent : *it)->id());
+ break;
+ }
+
+ // If we are on a message from that user (or a series thereof),
+ // remember it (or the end of the sequence) so that we could use it
+ // in case when the event to promote the marker to is immediately
+ // above the ones from that user.
+ if ((*it)->senderId() == u->id())
+ {
+ if (!targetEvent)
+ targetEvent = *it;
+ }
+ else
+ targetEvent = nullptr;
+
+ // Detect events "notable" for the local user so that we can properly
+ // set unreadMessages
+ if (u == connection()->user())
+ stillUnreadMessagesCount += d->isEventNotable(*it);
+ }
+
+ if( u == connection()->user() )
+ {
+ if (d->unreadMessages && stillUnreadMessagesCount == 0)
+ {
+ d->unreadMessages = false;
+ qDebug() << "Room" << displayName() << ": no more unread messages";
+ emit unreadMessagesChanged(this);
}
+ if (stillUnreadMessagesCount > 0)
+ qDebug() << "Room" << displayName()
+ << ": still" << stillUnreadMessagesCount << "unread message(s)";
}
- return false;
+ return it;
}
-void Room::markMessagesAsRead(Timeline::const_iterator last)
+void Room::markMessagesAsRead(QString uptoEventId)
{
- QString prevLastReadId = lastReadEvent(connection()->user());
- if ( !promoteReadMarker(connection()->user(), (*last)->id()) )
+ if (d->messageEvents.empty())
return;
+ User* localUser = connection()->user();
+ QString prevLastReadId = lastReadEvent(localUser);
+ auto last = promoteReadMarker(localUser, uptoEventId);
+
// We shouldn't send read receipts for messages from the local user - so
// shift back (if necessary) to the nearest message not from the local user
// or the so far last read message, whichever comes first.
@@ -202,7 +246,7 @@ void Room::markMessagesAsRead(Timeline::const_iterator last)
{
if ((*last)->senderId() != connection()->userId())
{
- d->connection->postReceipt(this, (*last));
+ d->connection->postReceipt(this, *last);
break;
}
if (last == messageEvents().begin())
@@ -213,14 +257,24 @@ void Room::markMessagesAsRead(Timeline::const_iterator last)
void Room::markMessagesAsRead()
{
if (!messageEvents().empty())
- markMessagesAsRead(messageEvents().end() - 1);
+ markMessagesAsRead(messageEvents().back()->id());
+}
+
+bool Room::hasUnreadMessages()
+{
+ return d->unreadMessages;
}
-QString Room::lastReadEvent(User* user)
+QString Room::lastReadEvent(User* user) const
{
return d->lastReadEvent.value(user);
}
+QString Room::readMarkerEventId() const
+{
+ return lastReadEvent(d->connection->user());
+}
+
int Room::notificationCount() const
{
return d->notificationCount;
@@ -441,10 +495,50 @@ void Room::addNewMessageEvents(const Events& events)
emit addedMessages();
}
+bool Room::Private::isEventNotable(const Event* e) const
+{
+ return e->senderId() != connection->userId() &&
+ e->type() == EventType::RoomMessage;
+}
+
void Room::doAddNewMessageEvents(const Events& events)
{
d->messageEvents.reserve(d->messageEvents.size() + events.size());
- std::copy(events.begin(), events.end(), std::back_inserter(d->messageEvents));
+
+ Timeline::size_type newUnreadMessages = 0;
+
+ // The first message in the batch defines whose read marker we can
+ // automatically promote any further. Others will need explicit read receipts
+ // from the server (or, for the local user, markMessagesAsRead() invocation)
+ // to promote their read markers over the new message events.
+ User* firstWriter = connection()->user(events.front()->senderId());
+ bool canAutoPromote = d->messageEvents.empty() ||
+ lastReadEvent(firstWriter) == d->messageEvents.back()->id();
+ Event* firstWriterSeriesEnd = canAutoPromote ? events.front() : nullptr;
+
+ for (auto e: events)
+ {
+ d->messageEvents.push_back(e);
+
+ newUnreadMessages += d->isEventNotable(e);
+ if (firstWriterSeriesEnd)
+ {
+ if (e->senderId() != firstWriter->id())
+ firstWriterSeriesEnd = e;
+ else
+ {
+ setLastReadEvent(firstWriter, firstWriterSeriesEnd->id());
+ firstWriterSeriesEnd = nullptr;
+ }
+ }
+ }
+
+ if( !d->unreadMessages && newUnreadMessages > 0)
+ {
+ d->unreadMessages = true;
+ emit unreadMessagesChanged(this);
+ qDebug() << "Room" << displayName() << ": unread messages";
+ }
}
void Room::addHistoricalMessageEvents(const Events& events)
@@ -535,10 +629,8 @@ void Room::processEphemeralEvent(Event* event)
{
const auto receipts = receiptEvent->receiptsForEvent(eventId);
for( const Receipt& r: receipts )
- {
if (auto m = d->member(r.userId))
promoteReadMarker(m, eventId);
- }
}
}
}
@@ -628,3 +720,19 @@ void Room::Private::updateDisplayname()
if (old_name != displayname)
emit q->displaynameChanged(q);
}
+
+MemberSorter Room::memberSorter() const
+{
+ return MemberSorter(this);
+}
+
+bool MemberSorter::operator()(User *u1, User *u2) const
+{
+ auto n1 = room->roomMembername(u1);
+ auto n2 = room->roomMembername(u2);
+ if (n1[0] == '@')
+ n1.remove(0, 1);
+ if (n2[0] == '@')
+ n2.remove(0, 1);
+ return n1 < n2;
+}
diff --git a/room.h b/room.h
index fb3212e9..7cfd4c00 100644
--- a/room.h
+++ b/room.h
@@ -16,8 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef QMATRIXCLIENT_ROOM_H
-#define QMATRIXCLIENT_ROOM_H
+#pragma once
#include <QtCore/QList>
#include <QtCore/QStringList>
@@ -32,10 +31,12 @@ namespace QMatrixClient
class Event;
class Connection;
class User;
+ class MemberSorter;
class Room: public QObject
{
Q_OBJECT
+ Q_PROPERTY(QString readMarkerEventId READ readMarkerEventId WRITE markMessagesAsRead NOTIFY readMarkerPromoted)
public:
using Timeline = Owning<Events>;
@@ -69,27 +70,31 @@ namespace QMatrixClient
Q_INVOKABLE void updateData(SyncRoomData& data );
Q_INVOKABLE void setJoinState( JoinState state );
- Q_INVOKABLE QString lastReadEvent(User* user);
+ Q_INVOKABLE QString lastReadEvent(User* user) const;
+ QString readMarkerEventId() const;
/**
- * @brief Mark the message at the iterator as read
+ * @brief Mark the event with uptoEventId as read
*
- * Marks the message at the iterator as read; also posts a read
- * receipt to the server either for this message or, if it's from
- * the local user, for the nearest non-local message before.
+ * Finds in the timeline and marks as read the event with
+ * the specified id; also posts a read receipt to the server either
+ * for this message or, if it's from the local user, for
+ * the nearest non-local message before.
*/
- Q_INVOKABLE void markMessagesAsRead(Timeline::const_iterator last);
+ Q_INVOKABLE void markMessagesAsRead(QString uptoEventId);
/**
- * @brief Mark the most recent message in the timeline as read
- *
- * This effectively marks everything in the room as read.
+ * @brief Mark the whole room timeline as read
*/
Q_INVOKABLE void markMessagesAsRead();
+ Q_INVOKABLE bool hasUnreadMessages();
+
Q_INVOKABLE int notificationCount() const;
Q_INVOKABLE void resetNotificationCount();
Q_INVOKABLE int highlightCount() const;
Q_INVOKABLE void resetHighlightCount();
+ MemberSorter memberSorter() const;
+
public slots:
void getPreviousContent();
void userRenamed(User* user, QString oldName);
@@ -116,6 +121,8 @@ namespace QMatrixClient
void highlightCountChanged(Room* room);
void notificationCountChanged(Room* room);
void lastReadEventChanged(User* user);
+ void readMarkerPromoted();
+ void unreadMessagesChanged(Room* room);
protected:
Connection* connection() const;
@@ -124,7 +131,7 @@ namespace QMatrixClient
virtual void processStateEvents(const Events& events);
virtual void processEphemeralEvent(Event* event);
- bool promoteReadMarker(User* user, QString eventId);
+ Timeline::const_iterator promoteReadMarker(User* u, QString eventId);
private:
class Private;
@@ -135,6 +142,22 @@ namespace QMatrixClient
void setLastReadEvent(User* user, QString eventId);
};
-}
-#endif // QMATRIXCLIENT_ROOM_H
+ class MemberSorter
+ {
+ public:
+ MemberSorter(const Room* r) : room(r) { }
+
+ bool operator()(User* u1, User* u2) const;
+
+ template <typename ContT>
+ typename ContT::size_type lowerBoundIndex(const ContT& c,
+ typename ContT::value_type v) const
+ {
+ return std::lower_bound(c.begin(), c.end(), v, *this) - c.begin();
+ }
+
+ private:
+ const Room* room;
+ };
+}
diff --git a/state.h b/state.h
index 79566eba..b059ea92 100644
--- a/state.h
+++ b/state.h
@@ -16,8 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef QMATRIXCLIENT_STATE_H
-#define QMATRIXCLIENT_STATE_H
+#pragma once
#include <QtCore/QString>
#include <QtCore/QJsonObject>
@@ -46,5 +45,3 @@ namespace QMatrixClient
Private* d;
};
}
-
-#endif // QMATRIXCLIENT_STATE_H \ No newline at end of file
diff --git a/user.h b/user.h
index c408eb67..95c26bca 100644
--- a/user.h
+++ b/user.h
@@ -16,8 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef QMATRIXCLIENT_USER_H
-#define QMATRIXCLIENT_USER_H
+#pragma once
#include <QtCore/QString>
#include <QtCore/QObject>
@@ -65,5 +64,3 @@ namespace QMatrixClient
Private* d;
};
}
-
-#endif // QMATRIXCLIENT_USER_H