/** This file is a part of rexy's matrix client Copyright (C) 2019-2020 rexy712 This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ #ifndef MATRIX_EVENT_HPP #define MATRIX_EVENT_HPP #include "raii/rjp_ptr.hpp" #include #include "raii/rjp_string.hpp" namespace matrix::sync{ /* Base class for events returned by a sync */ class event { protected: RJP_value* m_event; RJP_value* m_type; RJP_value* m_content; public: event(void) = default; explicit event(RJP_value* ev); event(const event&) = delete; //TODO event(event&&)noexcept; ~event(void) = default; event& operator=(const event&); rexy::static_string type(void)const&; raii::rjp_string type(void)&&; const RJP_value* content(void)const; RJP_value* content(void); const RJP_value* raw(void)const; RJP_value* raw(void); }; /* Base class for events associated with a room returned by a sync */ class room_event_base { protected: rexy::static_string m_roomid; public: room_event_base(void) = default; room_event_base(const room_event_base&) = delete; constexpr room_event_base(room_event_base&&) = default; room_event_base& operator=(const room_event_base&) = default; constexpr room_event_base(const rexy::string_base& roomid): m_roomid(roomid.get(), roomid.length()){} constexpr const rexy::static_string& roomid(void)const{ return m_roomid; } }; /* Class to represent a single event associated with a specific room. */ class room_event : public room_event_base, public event { protected: RJP_value* m_id; RJP_value* m_sender; RJP_value* m_unsigned; RJP_value* m_redacts; int m_origin_server_ts; public: room_event(void) = default; room_event(RJP_value* ev, const rexy::string_base& roomid); room_event(const room_event&) = delete; //TODO room_event(room_event&&)noexcept; room_event& operator=(const room_event&) = delete; room_event& operator=(room_event&&); rexy::static_string eventid(void)const&; raii::rjp_string eventid(void)&&; rexy::static_string sender(void)const&; raii::rjp_string sender(void)&&; int origin_server_ts(void)const; const RJP_value* extra(void)const; RJP_value* extra(void); //only for m.room.redacts events rexy::static_string redacts(void)const&; raii::rjp_string redacts(void)&&; }; /* Class to represent a single state event associated with a specific room */ class room_state_event : public room_event { protected: RJP_value* m_state_key; RJP_value* m_prev_content; public: room_state_event(void) = default; room_state_event(RJP_value* ev, const rexy::string_base& roomid); room_state_event(const room_state_event&) = delete; //TODO room_state_event(room_state_event&&); room_state_event& operator=(const room_state_event&) = delete; room_state_event& operator=(room_state_event&&); rexy::static_string state_key(void)const&; raii::rjp_string state_key(void)&&; rexy::static_string prev_content(void)const&; raii::rjp_string prev_content(void)&&; }; /* Class to represent a single ephemeral event associated with a specific room */ class room_ephemeral_event : public room_event_base, public event { public: room_ephemeral_event(RJP_value* ev, const rexy::string_base& roomid); room_ephemeral_event(const room_ephemeral_event&) = delete; //TODO room_ephemeral_event(room_ephemeral_event&&) = default; }; //Specialized event for room messages class room_message_event : public room_event { protected: RJP_value* m_body; RJP_value* m_type; public: room_message_event(RJP_value* ev, const rexy::string_base& roomid); room_message_event(const room_message_event&) = delete; room_message_event(room_message_event&&); room_message_event(room_event&&)noexcept; rexy::static_string body(void)const&; raii::rjp_string body(void)&&; rexy::static_string msgtype(void)const&; raii::rjp_string msgtype(void)&&; }; } namespace matrix{ namespace detail{ template struct uninstantiated_false{ static constexpr bool value = false; }; } template::value> To event_cast(From&&){ static_assert(detail::uninstantiated_false::value); } template<> matrix::sync::room_message_event event_cast(matrix::sync::room_state_event&& from); } #endif