aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--connection.cpp6
-rw-r--r--connection.h5
-rw-r--r--connectiondata.cpp10
-rw-r--r--connectiondata.h8
4 files changed, 25 insertions, 4 deletions
diff --git a/connection.cpp b/connection.cpp
index 56628a07..56ceb068 100644
--- a/connection.cpp
+++ b/connection.cpp
@@ -32,7 +32,6 @@
#include "jobs/mediathumbnailjob.h"
#include <QtNetwork/QDnsLookup>
-#include <QtCore/QDebug>
using namespace QMatrixClient;
@@ -316,3 +315,8 @@ Room* Connection::createRoom(const QString& roomId)
{
return new Room(this, roomId);
}
+
+QByteArray Connection::generateTxnId()
+{
+ return d->data->generateTxnId();
+}
diff --git a/connection.h b/connection.h
index f0b097fd..e3f33155 100644
--- a/connection.h
+++ b/connection.h
@@ -91,6 +91,11 @@ namespace QMatrixClient
return job;
}
+ /** Generates a new transaction id. Transaction id's are unique within
+ * a single Connection object
+ */
+ Q_INVOKABLE QByteArray generateTxnId();
+
signals:
void resolved();
void connected();
diff --git a/connectiondata.cpp b/connectiondata.cpp
index 6c7eff8c..cd91ef27 100644
--- a/connectiondata.cpp
+++ b/connectiondata.cpp
@@ -21,6 +21,7 @@
#include "logging.h"
#include <QtNetwork/QNetworkAccessManager>
+#include <cstdlib>
using namespace QMatrixClient;
@@ -35,6 +36,9 @@ struct ConnectionData::Private
QUrl baseUrl;
QString accessToken;
QString lastEvent;
+
+ mutable unsigned int txnCounter = 0;
+ const int id = std::rand(); // We don't really care about pure randomness
};
ConnectionData::ConnectionData(QUrl baseUrl)
@@ -89,3 +93,9 @@ void ConnectionData::setLastEvent(QString identifier)
{
d->lastEvent = identifier;
}
+
+QByteArray ConnectionData::generateTxnId() const
+{
+ return QByteArray::number(d->id) + 'q' +
+ QByteArray::number(++d->txnCounter);
+}
diff --git a/connectiondata.h b/connectiondata.h
index 0eadab80..7b0097d6 100644
--- a/connectiondata.h
+++ b/connectiondata.h
@@ -27,7 +27,7 @@ namespace QMatrixClient
class ConnectionData
{
public:
- ConnectionData(QUrl baseUrl);
+ explicit ConnectionData(QUrl baseUrl);
virtual ~ConnectionData();
QString accessToken() const;
@@ -41,8 +41,10 @@ namespace QMatrixClient
QString lastEvent() const;
void setLastEvent( QString identifier );
+ QByteArray generateTxnId() const;
+
private:
- class Private;
+ struct Private;
Private* d;
};
-}
+} // namespace QMatrixClient