20 #ifndef __OPERATOR_EVENT_HH_ 21 #define __OPERATOR_EVENT_HH_ 40 const std::string &getType()
const throw () {
return data.at(
"type").get_ref<
const std::string &>(); }
41 const nlohmann::json &getContent()
const throw () {
return data.at(
"content"); }
42 const nlohmann::json &getRawData()
const throw () {
return data; }
43 const std::string &getRoomID()
const throw () {
return room_id; }
45 typedef std::function<std::unique_ptr<Event>(nlohmann::json data,
const std::string &)> event_builder_t;
46 static std::unique_ptr<Event> newEvent(nlohmann::json data,
const std::string & =
"")
throw (
Error::Error);
47 static void registerEventClass(
const std::string &type, event_builder_t);
49 template<
typename T>
static std::unique_ptr<Event> _new_helper(nlohmann::json data,
const std::string &room_id) {
50 return std::unique_ptr<Event>(
new T(std::move(data), room_id));
53 static const std::string TYPE;
57 const std::string &get_room_name(
const nlohmann::json &data,
const std::string &room_id) {
58 static std::string emptystring;
63 auto it = data.find(
"room_id");
64 if (it == data.end() || !it->is_string())
68 return it->get_ref<
const std::string &>();
78 const std::string &getEventID()
const throw () {
return data.at(
"event_id").get_ref<
const std::string &>(); }
79 const std::string &getSender()
const throw () {
return data.at(
"sender").get_ref<
const std::string &>(); }
80 const nlohmann::json &getUnsigned()
const throw (std::out_of_range) {
return data.at(
"unsigned"); }
83 static std::unique_ptr<Event> newEvent(nlohmann::json data,
const std::string & =
"")
throw (
Error::Error);
84 static void registerEventClass(
const std::string &type, event_builder_t);
93 const std::string &getStateKey()
const throw() {
return data.at(
"state_key").get_ref<
const std::string &>(); }
94 const nlohmann::json &getPrevContent()
const throw (std::out_of_range) {
return data.at(
"prev_content"); }
96 static std::unique_ptr<Event> newEvent(nlohmann::json data,
const std::string & =
"")
throw (
Error::Error);
97 static void registerEventClass(
const std::string &type, event_builder_t);
106 const std::vector<std::string> getAliases()
const throw () {
return aliases; }
108 static const std::string TYPE;
110 std::vector<std::string> aliases;
121 static std::unique_ptr<Event> newEvent(nlohmann::json data,
const std::string & =
"")
throw (
Error::Error);
122 static void registerEventClass(
const std::string &type, event_builder_t);
133 Message(
const std::string &msgtype,
const std::string &body,
const std::string &room_id)
throw ();
135 const std::string &getBody()
const throw () {
return getContent().at(
"body").get_ref<
const std::string &>(); }
136 const std::string &getMessageType()
const throw () {
return getContent().at(
"msgtype").get_ref<
const std::string &>(); }
138 static const std::string TYPE;
140 static void registerMessageClass(
const std::string &type, event_builder_t);
141 static void registerMessageClass(
const std::string &type, event_builder_t, event_builder_t);
142 static std::unique_ptr<Event> newEvent(nlohmann::json data,
const std::string & =
"")
throw (
Error::Error);
150 : T(std::move(d), room_id) {}
153 _HTMLMessage<T>(
const std::string &body,
const std::string &html,
const std::string &room_id)
155 {
"type", Message::Message::TYPE},
156 {
"room_id", room_id},
158 {
"msgtype", T::MSGTYPE},
160 {
"format",
"org.matrix.custom.html"},
161 {
"formatted_body", html}
170 Text(nlohmann::json d,
const std::string &room_id =
"")
throw (
Error::Error)
171 :
Message(std::move(d), room_id) {
172 data[
"content"][
"msgtype"] = MSGTYPE;
176 Text(
const std::string &body,
const std::string &room)
177 :
Message(body, MSGTYPE, room) {}
179 static const std::string MSGTYPE;
193 :
Message(std::move(d), room_id) {
194 data[
"content"][
"msgtype"] = MSGTYPE;
198 Emote(
const std::string &body,
const std::string &room)
199 :
Message(body, MSGTYPE, room) {}
201 static const std::string MSGTYPE;
215 :
Message(std::move(d), room_id) {
216 data[
"content"][
"msgtype"] = MSGTYPE;
220 Notice(
const std::string &body,
const std::string &room)
221 :
Message(body, MSGTYPE, room) {}
223 static const std::string MSGTYPE;
238 Login(
const std::string &user_id,
const std::string &home_server)
throw (
Error::Error)
240 {
"type", Login::TYPE},
242 {
"user_id", user_id},
243 {
"home_server", home_server}
247 const std::string &getUserID()
const throw () {
return getContent().at(
"user_id").get_ref<
const std::string &>(); }
248 const std::string &getHomeServer()
const throw () {
return getContent().at(
"home_server").get_ref<
const std::string &>(); }
250 static const std::string TYPE;
259 {
"type", Logout::TYPE},
260 {
"content", nlohmann::json::object()}
263 static const std::string TYPE;
270 enum membership_t {NONE, INVITE, JOIN, KNOCK, LEAVE, BAN};
273 {
"type", RoomMembership::TYPE},
274 {
"room_id", room_id},
276 {
"membership", membership}
280 membership_t getMembership()
const throw () {
return static_cast<membership_t
>(getContent().at(
"membership").get<
int>()); }
282 static const std::string TYPE;
293 {
"type", Limited::TYPE},
294 {
"room_id", room_id},
295 {
"content", nlohmann::json::object()}
298 static const std::string TYPE;
303 #endif // __OPERATOR_EVENT_HH_ general "message" events (a.k.a. timeline events)
Definition: event.hh:115
event relating to the state of a room.
Definition: event.hh:89
the client has logged in
Definition: event.hh:236
the client has logged out
Definition: event.hh:255
HTML version of a message class.
Definition: event.hh:147
indicates that the sync result has been limited.
Definition: event.hh:289
normal text messages (msgtype m.text)
Definition: event.hh:168
base class for messages (events of type m.room.message)
Definition: event.hh:128
base error class.
Definition: error.hh:37
aliases for a room.
Definition: event.hh:102
event that is associated with a room.
Definition: event.hh:74
the user's membership in a room has changed
Definition: event.hh:268
emote messages (msgtype m.emote)
Definition: event.hh:190
notice messages (msgtype m.notice)
Definition: event.hh:212
base event class.
Definition: event.hh:35