aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2017-11-01 20:59:52 +0300
committerKitsune Ral <Kitsune-Ral@users.sf.net>2017-11-01 20:59:52 +0300
commit2390082f7ca264aabeadc8f62bb71c39ce2b96f0 (patch)
treee8e69bce4eefb434ae244e73dde7e9e1c0df352e
parenta275ef911b3f4d0334df0628324aee0081dd3a65 (diff)
downloadlibquotient-2390082f7ca264aabeadc8f62bb71c39ce2b96f0.tar.gz
libquotient-2390082f7ca264aabeadc8f62bb71c39ce2b96f0.zip
Event::isStateEvent(); fixed StateEvent::_prev always being initialised
Event::isStateEvent() is an easier way to make checking an event kind (instead of enumerating through all types corresponding to state changes). StateEvent::_prev (accessible through prev_content) should only be initialised if there's a previous state in the original JSON.
-rw-r--r--events/event.h29
1 files changed, 21 insertions, 8 deletions
diff --git a/events/event.h b/events/event.h
index 020ef54b..9c915e35 100644
--- a/events/event.h
+++ b/events/event.h
@@ -31,12 +31,18 @@ namespace QMatrixClient
{
Q_GADGET
public:
- enum class Type
+ enum class Type : quint16
{
- RoomMessage, RoomName, RoomAliases, RoomCanonicalAlias,
- RoomMember, RoomTopic, RoomAvatar,
- RoomEncryption, RoomEncryptedMessage,
- Typing, Receipt, Unknown
+ Unknown = 0,
+ Typing, Receipt,
+ RoomEventBase = 0x1000,
+ RoomMessage = RoomEventBase + 1,
+ RoomEncryptedMessage,
+ RoomStateEventBase = 0x1800,
+ RoomName = RoomStateEventBase + 1,
+ RoomAliases, RoomCanonicalAlias, RoomMember, RoomTopic,
+ RoomAvatar, RoomEncryption,
+ Reserved = 0x2000
};
explicit Event(Type type) : _type(type) { }
@@ -44,6 +50,10 @@ namespace QMatrixClient
Event(const Event&) = delete;
Type type() const { return _type; }
+ bool isStateEvent() const
+ {
+ return (quint16(_type) & 0x1800) == 0x1800;
+ }
QByteArray originalJson() const;
QJsonObject originalJsonObject() const;
@@ -152,9 +162,12 @@ namespace QMatrixClient
: RoomEvent(type, obj)
, _content(contentJson(),
std::forward<ContentParamTs>(contentParams)...)
- , _prev(new ContentT(obj["prev_content"].toObject(),
- std::forward<ContentParamTs>(contentParams)...))
- { }
+ {
+ if (obj.contains("prev_content"))
+ _prev.reset(new ContentT(
+ obj["prev_content"].toObject(),
+ std::forward<ContentParamTs>(contentParams)...));
+ }
template <typename... ContentParamTs>
explicit StateEvent(Type type, ContentParamTs&&... contentParams)
: RoomEvent(type)