diff options
author | Black Hat <bhat@encom.eu.org> | 2020-01-21 11:03:25 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-21 11:03:25 -0800 |
commit | e3a5b3a5e5253fc5ce67574b01e8d25ec14e4d25 (patch) | |
tree | 11286e7a13267624da5e3cbf06794fc0ce9c896d /lib/events/roompowerlevelsevent.h | |
parent | 16d6700950f5f0ebd71481efd5e1a24f04e3c651 (diff) | |
parent | ac48199de174aa8cca52e703a3e65034fcd5db07 (diff) | |
download | libquotient-e3a5b3a5e5253fc5ce67574b01e8d25ec14e4d25.tar.gz libquotient-e3a5b3a5e5253fc5ce67574b01e8d25ec14e4d25.zip |
Merge pull request #371 from quotient-im/bhat-powerlevel
Add m.room.power_levels support
Diffstat (limited to 'lib/events/roompowerlevelsevent.h')
-rw-r--r-- | lib/events/roompowerlevelsevent.h | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/lib/events/roompowerlevelsevent.h b/lib/events/roompowerlevelsevent.h new file mode 100644 index 00000000..f0f7207f --- /dev/null +++ b/lib/events/roompowerlevelsevent.h @@ -0,0 +1,76 @@ +#pragma once + +#include "eventcontent.h" +#include "stateevent.h" + +namespace Quotient { +class PowerLevelsEventContent : public EventContent::Base { +public: + struct Notifications { + int room; + }; + + explicit PowerLevelsEventContent(const QJsonObject& json); + + int invite; + int kick; + int ban; + + int redact; + + QHash<QString, int> events; + int eventsDefault; + int stateDefault; + + QHash<QString, int> users; + int usersDefault; + + Notifications notifications; + +protected: + void fillJson(QJsonObject* o) const override; +}; + +class RoomPowerLevelsEvent : public StateEvent<PowerLevelsEventContent> { + Q_GADGET +public: + DEFINE_EVENT_TYPEID("m.room.power_levels", RoomPowerLevelsEvent) + + explicit RoomPowerLevelsEvent(const QJsonObject& obj) + : StateEvent(typeId(), obj) + {} + + int invite() const { return content().invite; } + int kick() const { return content().kick; } + int ban() const { return content().ban; } + + int redact() const { return content().redact; } + + QHash<QString, int> events() const { return content().events; } + int eventsDefault() const { return content().eventsDefault; } + int stateDefault() const { return content().stateDefault; } + + QHash<QString, int> users() const { return content().users; } + int usersDefault() const { return content().usersDefault; } + + int roomNotification() const { return content().notifications.room; } + + int powerLevelForEvent(const QString& eventId) const; + int powerLevelForState(const QString& eventId) const; + int powerLevelForUser(const QString& userId) const; + +private: +}; + +template <> +class EventFactory<RoomPowerLevelsEvent> { +public: + static event_ptr_tt<RoomPowerLevelsEvent> make(const QJsonObject& json, + const QString&) + { + return makeEvent<RoomPowerLevelsEvent>(json); + } +}; + +REGISTER_EVENT_TYPE(RoomPowerLevelsEvent) +} // namespace Quotient |