aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--connection.cpp1
-rw-r--r--events/roommemberevent.cpp8
-rw-r--r--jobs/sendeventjob.cpp2
-rw-r--r--jobs/sendeventjob.h4
-rw-r--r--jobs/setroomstatejob.h8
-rw-r--r--room.cpp27
-rw-r--r--room.h15
7 files changed, 29 insertions, 36 deletions
diff --git a/connection.cpp b/connection.cpp
index e20f843f..c7492868 100644
--- a/connection.cpp
+++ b/connection.cpp
@@ -26,7 +26,6 @@
#include "jobs/sendeventjob.h"
#include "jobs/postreceiptjob.h"
#include "jobs/joinroomjob.h"
-#include "jobs/leaveroomjob.h"
#include "jobs/roommessagesjob.h"
#include "jobs/syncjob.h"
#include "jobs/mediathumbnailjob.h"
diff --git a/events/roommemberevent.cpp b/events/roommemberevent.cpp
index 5973acc7..19f116d2 100644
--- a/events/roommemberevent.cpp
+++ b/events/roommemberevent.cpp
@@ -22,6 +22,9 @@
using namespace QMatrixClient;
+static const auto membershipStrings =
+ { "invite", "join", "knock", "leave", "ban" };
+
RoomMemberEvent::RoomMemberEvent(const QJsonObject& obj)
: RoomEvent(Type::RoomMember, obj), _userId(obj["state_key"].toString())
{
@@ -29,11 +32,10 @@ RoomMemberEvent::RoomMemberEvent(const QJsonObject& obj)
_displayName = contentObj["displayname"].toString();
_avatarUrl = contentObj["avatar_url"].toString();
QString membershipString = contentObj["membership"].toString();
- const auto supportedStrings = { "invite", "join", "knock", "leave", "ban" };
- for (auto it = supportedStrings.begin(); it != supportedStrings.end(); ++it)
+ for (auto it = membershipStrings.begin(); it != membershipStrings.end(); ++it)
if (membershipString == *it)
{
- _membership = MembershipType(it - supportedStrings.begin());
+ _membership = MembershipType(it - membershipStrings.begin());
return;
}
qCWarning(EVENTS) << "Unknown MembershipType: " << membershipString;
diff --git a/jobs/sendeventjob.cpp b/jobs/sendeventjob.cpp
index 7e33e089..f5190d4b 100644
--- a/jobs/sendeventjob.cpp
+++ b/jobs/sendeventjob.cpp
@@ -24,7 +24,7 @@ using namespace QMatrixClient;
SendEventJob::SendEventJob(const QString& roomId, const QString& type,
const QString& plainText)
- : SendEventJob(roomId, new RoomMessageEvent(plainText, type))
+ : SendEventJob(roomId, RoomMessageEvent(plainText, type))
{ }
void SendEventJob::beforeStart(const ConnectionData* connData)
diff --git a/jobs/sendeventjob.h b/jobs/sendeventjob.h
index 7b10b3d4..3a11eb6a 100644
--- a/jobs/sendeventjob.h
+++ b/jobs/sendeventjob.h
@@ -29,12 +29,12 @@ namespace QMatrixClient
public:
/** Constructs a job that sends an arbitrary room event */
template <typename EvT>
- SendEventJob(const QString& roomId, const EvT* event)
+ SendEventJob(const QString& roomId, const EvT& event)
: BaseJob(HttpVerb::Put, QStringLiteral("SendEventJob"),
QStringLiteral("_matrix/client/r0/rooms/%1/send/%2/")
.arg(roomId, EvT::TypeId), // See also beforeStart()
Query(),
- Data(event->toJson()))
+ Data(event.toJson()))
{ }
/**
diff --git a/jobs/setroomstatejob.h b/jobs/setroomstatejob.h
index ddc271b9..b7e6d4a1 100644
--- a/jobs/setroomstatejob.h
+++ b/jobs/setroomstatejob.h
@@ -33,24 +33,24 @@ namespace QMatrixClient
*/
template <typename EvT>
SetRoomStateJob(const QString& roomId, const QString& stateKey,
- const EvT* event)
+ const EvT& event)
: BaseJob(HttpVerb::Put, "SetRoomStateJob",
QStringLiteral("_matrix/client/r0/rooms/%1/state/%2/%3")
.arg(roomId, EvT::TypeId, stateKey),
Query(),
- Data(event->toJson()))
+ Data(event.toJson()))
{ }
/**
* Constructs a job that sets a state using an arbitrary room event
* without a state key.
*/
template <typename EvT>
- SetRoomStateJob(const QString& roomId, const EvT* event)
+ SetRoomStateJob(const QString& roomId, const EvT& event)
: BaseJob(HttpVerb::Put, "SetRoomStateJob",
QStringLiteral("_matrix/client/r0/rooms/%1/state/%2")
.arg(roomId, EvT::TypeId),
Query(),
- Data(event->toJson()))
+ Data(event.toJson()))
{ }
QString eventId() const { return _eventId; }
diff --git a/room.cpp b/room.cpp
index 79168d85..53d8fef1 100644
--- a/room.cpp
+++ b/room.cpp
@@ -445,7 +445,8 @@ void Room::Private::addMember(User *u)
if (!hasMember(u))
{
insertMemberIntoMap(u);
- connect(u, &User::nameChanged, q, &Room::userRenamed);
+ connect(u, &User::nameChanged, q,
+ [=] (User* u, const QString& newName) { renameMember(u, newName); });
emit q->userAdded(u);
}
}
@@ -490,11 +491,6 @@ void Room::Private::removeMember(User* u)
}
}
-void Room::userRenamed(User* user, QString oldName)
-{
- d->renameMember(user, std::move(oldName));
-}
-
QString Room::roomMembername(User *u) const
{
// See the CS spec, section 11.2.2.3
@@ -581,16 +577,15 @@ void Room::updateData(SyncRoomData&& data)
void Room::postMessage(const QString& type, const QString& plainText)
{
- connection()->callApi<SendEventJob>(id(), type, plainText);
+ postMessage(RoomMessageEvent { plainText, type });
}
void Room::postMessage(const QString& plainText, MessageEventType type)
{
- RoomMessageEvent rme(plainText, type);
- postMessage(&rme);
+ postMessage(RoomMessageEvent { plainText, type });
}
-void Room::postMessage(RoomMessageEvent* event)
+void Room::postMessage(const RoomMessageEvent& event)
{
connection()->callApi<SendEventJob>(id(), event);
}
@@ -598,7 +593,7 @@ void Room::postMessage(RoomMessageEvent* event)
void Room::setTopic(const QString& newTopic)
{
RoomTopicEvent evt(newTopic);
- connection()->callApi<SetRoomStateJob>(id(), &evt);
+ connection()->callApi<SetRoomStateJob>(id(), evt);
}
void Room::getPreviousContent(int limit)
@@ -623,27 +618,27 @@ void Room::Private::getPreviousContent(int limit)
}
}
-void Room::inviteToRoom(const QString& memberId) const
+void Room::inviteToRoom(const QString& memberId)
{
connection()->callApi<InviteUserJob>(id(), memberId);
}
-void Room::leaveRoom() const
+void Room::leaveRoom()
{
connection()->callApi<LeaveRoomJob>(id());
}
-void Room::kickMember(const QString& memberId, const QString& reason) const
+void Room::kickMember(const QString& memberId, const QString& reason)
{
connection()->callApi<KickJob>(id(), memberId, reason);
}
-void Room::ban(const QString& userId, const QString& reason) const
+void Room::ban(const QString& userId, const QString& reason)
{
connection()->callApi<BanJob>(id(), userId, reason);
}
-void Room::unban(const QString& userId) const
+void Room::unban(const QString& userId)
{
connection()->callApi<UnbanJob>(id(), userId);
}
diff --git a/room.h b/room.h
index d62d160f..00d4c333 100644
--- a/room.h
+++ b/room.h
@@ -150,21 +150,18 @@ namespace QMatrixClient
public slots:
void postMessage(const QString& plainText,
MessageEventType type = MessageEventType::Text);
- void postMessage(RoomMessageEvent* event);
+ void postMessage(const RoomMessageEvent& event);
/** @deprecated */
void postMessage(const QString& type, const QString& plainText);
void setTopic(const QString& newTopic);
void getPreviousContent(int limit = 10);
- void inviteToRoom(const QString& memberId) const;
- void leaveRoom() const;
- void kickMember(const QString& memberId,
- const QString& reason = {}) const;
- void ban(const QString& userId, const QString& reason = {}) const;
- void unban(const QString& userId) const;
-
- void userRenamed(User* user, QString oldName);
+ void inviteToRoom(const QString& memberId);
+ void leaveRoom();
+ void kickMember(const QString& memberId, const QString& reason = {});
+ void ban(const QString& userId, const QString& reason = {});
+ void unban(const QString& userId);
/** Mark all messages in the room as read */
void markAllMessagesAsRead();