/** This file is a part of rexy's matrix client Copyright (C) 2019 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 "raii/string_base.hpp" #include "raii/rjp_string.hpp" namespace matrix::sync{ /* Base class for events returned by a sync */ class event { protected: RJP_value* m_type; RJP_value* m_content; public: explicit event(RJP_value* ev); constexpr event(const event&) = default; ~event(void) = default; constexpr event& operator=(const event&) = default; raii::static_string type(void)const&; raii::rjp_string type(void)&&; const RJP_value* content(void)const; RJP_value* content(void); }; /* Base class for events associated with a room returned by a sync */ class room_event_base { protected: const raii::static_string m_roomid; public: constexpr room_event_base(const raii::string_base& roomid): m_roomid(roomid.get(), roomid.length()){} constexpr const raii::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(RJP_value* ev, const raii::string_base& roomid); raii::static_string eventid(void)const&; raii::rjp_string eventid(void)&&; raii::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 raii::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(RJP_value* ev, const raii::string_base& roomid); raii::static_string state_key(void)const&; raii::rjp_string state_key(void)&&; raii::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 raii::string_base& roomid); }; } #endif