aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/events/roomevent.cpp10
-rw-r--r--lib/events/roomevent.h3
-rw-r--r--lib/room.cpp42
-rw-r--r--lib/room.h26
-rw-r--r--lib/user.cpp2
5 files changed, 53 insertions, 30 deletions
diff --git a/lib/events/roomevent.cpp b/lib/events/roomevent.cpp
index 62c2a76d..f1e563ff 100644
--- a/lib/events/roomevent.cpp
+++ b/lib/events/roomevent.cpp
@@ -81,6 +81,16 @@ QString RoomEvent::stateKey() const
return fullJson()[StateKeyKeyL].toString();
}
+void RoomEvent::setRoomId(const QString& roomId)
+{
+ editJson().insert(QStringLiteral("room_id"), roomId);
+}
+
+void RoomEvent::setSender(const QString& senderId)
+{
+ editJson().insert(QStringLiteral("sender"), senderId);
+}
+
void RoomEvent::setTransactionId(const QString& txnId)
{
auto unsignedData = fullJson()[UnsignedKeyL].toObject();
diff --git a/lib/events/roomevent.h b/lib/events/roomevent.h
index ce96174e..e26a7135 100644
--- a/lib/events/roomevent.h
+++ b/lib/events/roomevent.h
@@ -60,6 +60,9 @@ namespace QMatrixClient
QString transactionId() const;
QString stateKey() const;
+ void setRoomId(const QString& roomId);
+ void setSender(const QString& senderId);
+
/**
* Sets the transaction id for locally created events. This should be
* done before the event is exposed to any code using the respective
diff --git a/lib/room.cpp b/lib/room.cpp
index dea21082..cb368d9e 100644
--- a/lib/room.cpp
+++ b/lib/room.cpp
@@ -290,15 +290,15 @@ class Room::Private
SetRoomStateWithKeyJob* requestSetState(const StateEventBase& event)
{
- if (q->successorId().isEmpty())
- {
- // TODO: Queue up state events sending (see #133).
- return connection->callApi<SetRoomStateWithKeyJob>(
- id, event.matrixType(),
- event.stateKey(), event.contentJson());
- }
- qCWarning(MAIN) << q << "has been upgraded, state won't be set";
- return nullptr;
+// if (event.roomId().isEmpty())
+// event.setRoomId(id);
+// if (event.senderId().isEmpty())
+// event.setSender(connection->userId());
+ // TODO: Queue up state events sending (see #133).
+ // TODO: Maybe addAsPending() as well, despite having no txnId
+ return connection->callApi<SetRoomStateWithKeyJob>(
+ id, event.matrixType(),
+ event.stateKey(), event.contentJson());
}
template <typename EvT, typename... ArgTs>
@@ -1416,6 +1416,10 @@ RoomEvent* Room::Private::addAsPending(RoomEventPtr&& event)
{
if (event->transactionId().isEmpty())
event->setTransactionId(connection->generateTxnId());
+ if (event->roomId().isEmpty())
+ event->setRoomId(id);
+ if (event->senderId().isEmpty())
+ event->setSender(connection->userId());
auto* pEvent = rawPtr(event);
emit q->pendingEventAboutToAdd(pEvent);
unsyncedEvents.emplace_back(move(event));
@@ -1425,6 +1429,11 @@ RoomEvent* Room::Private::addAsPending(RoomEventPtr&& event)
QString Room::Private::sendEvent(RoomEventPtr&& event)
{
+ if (q->usesEncryption())
+ {
+ qCCritical(MAIN) << "Room" << q->objectName()
+ << "enforces encryption; sending encrypted messages is not supported yet";
+ }
if (q->successorId().isEmpty())
return doSendEvent(addAsPending(std::move(event)));
@@ -1630,11 +1639,6 @@ QString Room::postFile(const QString& plainText, const QUrl& localPath,
QString Room::postEvent(RoomEvent* event)
{
- if (usesEncryption())
- {
- qCCritical(MAIN) << "Room" << displayName()
- << "enforces encryption; sending encrypted messages is not supported yet";
- }
return d->sendEvent(RoomEventPtr(event));
}
@@ -1715,33 +1719,33 @@ void Room::inviteCall(const QString& callId, const int lifetime,
const QString& sdp)
{
Q_ASSERT(supportsCalls());
- postEvent(new CallInviteEvent(callId, lifetime, sdp));
+ d->sendEvent<CallInviteEvent>(callId, lifetime, sdp);
}
void Room::sendCallCandidates(const QString& callId,
const QJsonArray& candidates)
{
Q_ASSERT(supportsCalls());
- postEvent(new CallCandidatesEvent(callId, candidates));
+ d->sendEvent<CallCandidatesEvent>(callId, candidates);
}
void Room::answerCall(const QString& callId, const int lifetime,
const QString& sdp)
{
Q_ASSERT(supportsCalls());
- postEvent(new CallAnswerEvent(callId, lifetime, sdp));
+ d->sendEvent<CallAnswerEvent>(callId, lifetime, sdp);
}
void Room::answerCall(const QString& callId, const QString& sdp)
{
Q_ASSERT(supportsCalls());
- postEvent(new CallAnswerEvent(callId, sdp));
+ d->sendEvent<CallAnswerEvent>(callId, sdp);
}
void Room::hangupCall(const QString& callId)
{
Q_ASSERT(supportsCalls());
- postEvent(new CallHangupEvent(callId));
+ d->sendEvent<CallHangupEvent>(callId);
}
void Room::getPreviousContent(int limit)
diff --git a/lib/room.h b/lib/room.h
index 3abf262d..c79ca1e0 100644
--- a/lib/room.h
+++ b/lib/room.h
@@ -18,6 +18,7 @@
#pragma once
+#include "connection.h"
#include "csapi/message_pagination.h"
#include "events/roommessageevent.h"
#include "events/accountdataevents.h"
@@ -36,7 +37,6 @@ namespace QMatrixClient
class Avatar;
class SyncRoomData;
class RoomMemberEvent;
- class Connection;
class User;
class MemberSorter;
class LeaveRoomJob;
@@ -406,17 +406,14 @@ namespace QMatrixClient
MemberSorter memberSorter() const;
- Q_INVOKABLE void inviteCall(const QString& callId,
- const int lifetime, const QString& sdp);
- Q_INVOKABLE void sendCallCandidates(const QString& callId,
- const QJsonArray& candidates);
- Q_INVOKABLE void answerCall(const QString& callId, const int lifetime,
- const QString& sdp);
- Q_INVOKABLE void answerCall(const QString& callId,
- const QString& sdp);
- Q_INVOKABLE void hangupCall(const QString& callId);
Q_INVOKABLE bool supportsCalls() const;
+ template <typename EvT, typename... ArgTs>
+ auto setState(ArgTs&&... args) const
+ {
+ return setState(EvT(std::forward<ArgTs>(args)...));
+ }
+
public slots:
/** Check whether the room should be upgraded */
void checkVersion();
@@ -481,6 +478,15 @@ namespace QMatrixClient
/// Switch the room's version (aka upgrade)
void switchVersion(QString newVersion);
+ void inviteCall(const QString& callId,
+ const int lifetime, const QString& sdp);
+ void sendCallCandidates(const QString& callId,
+ const QJsonArray& candidates);
+ void answerCall(const QString& callId, const int lifetime,
+ const QString& sdp);
+ void answerCall(const QString& callId, const QString& sdp);
+ void hangupCall(const QString& callId);
+
signals:
/// Initial set of state events has been loaded
/**
diff --git a/lib/user.cpp b/lib/user.cpp
index 8bdcbe97..7ca97b1a 100644
--- a/lib/user.cpp
+++ b/lib/user.cpp
@@ -292,7 +292,7 @@ void User::rename(const QString& newName, const Room* r)
const auto actualNewName = sanitized(newName);
MemberEventContent evtC;
evtC.displayName = actualNewName;
- connect(r->setState(RoomMemberEvent(id(), move(evtC))),
+ connect(r->setState<RoomMemberEvent>(id(), move(evtC)),
&BaseJob::success, this, [=] { updateName(actualNewName, r); });
}