aboutsummaryrefslogtreecommitdiff
path: root/lib/events/stateevent.h
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2019-07-06 20:13:38 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2019-07-06 20:13:38 +0900
commit025e5ab7d90ce8cf474567457301de32d5a3e34a (patch)
treea56ab34bff688275a9deabd920539bebc247cc8e /lib/events/stateevent.h
parentcbb4f219d5c79f81706019c0679222d5ccee4a4c (diff)
downloadlibquotient-025e5ab7d90ce8cf474567457301de32d5a3e34a.tar.gz
libquotient-025e5ab7d90ce8cf474567457301de32d5a3e34a.zip
Be stricter on usage of stateKey
A few places in the library dealt with state events without any notion of state_key inside events, including StateEvent[Base] and relevant functions in Room. A number of workarounds have been made; e.g., Room::setMemberState() accepted userId as a separate parameter, ignoring the state key inside the RoomMemberEvent already passed to it, and Room::setLocalAliases() had a bug in the initial version where the function still tried to pass aliases in an event with an empty state key. This commit fixes this shortcoming: StateEventBase now gets stateKey as one more parameter, Room::Private::getCurrentState() respects stateKey and returns properly constructed stub events, and Room::setMemberState() gives way to a more generic Room::setState() that works uniformly with whatever state event you pass to it.
Diffstat (limited to 'lib/events/stateevent.h')
-rw-r--r--lib/events/stateevent.h10
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/events/stateevent.h b/lib/events/stateevent.h
index 5dadac7f..692f2685 100644
--- a/lib/events/stateevent.h
+++ b/lib/events/stateevent.h
@@ -37,7 +37,12 @@ namespace QMatrixClient {
public:
using factory_t = EventFactory<StateEventBase>;
- using RoomEvent::RoomEvent;
+ StateEventBase(Type type, const QJsonObject& json)
+ : RoomEvent(type, json)
+ { }
+ StateEventBase(Type type, event_mtype_t matrixType,
+ const QString& stateKey = {},
+ const QJsonObject& contentJson = {});
~StateEventBase() override = default;
bool isStateEvent() const override { return true; }
@@ -94,8 +99,9 @@ namespace QMatrixClient {
}
template <typename... ContentParamTs>
explicit StateEvent(Type type, event_mtype_t matrixType,
+ const QString& stateKey = {},
ContentParamTs&&... contentParams)
- : StateEventBase(type, matrixType)
+ : StateEventBase(type, matrixType, stateKey)
, _content(std::forward<ContentParamTs>(contentParams)...)
{
editJson().insert(ContentKey, _content.toJson());