/** This file is a part of r0nk, atlas_moon, and 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_INFO_HPP #define MATRIX_EVENT_INFO_HPP #include "raii/rjp_string.hpp" #include //strcmp namespace matrix{ //message handling structs //enumerate message type but also give a string representation class msgtype{ private: const char* m_str; const int m_num; public: constexpr msgtype(const char* s, int n): m_str(s), m_num(n){} constexpr msgtype(const msgtype&) = default; ~msgtype(void) = default; constexpr msgtype& operator=(const msgtype&) = default; constexpr bool operator==(const msgtype& m){ return m_num == m.m_num; } constexpr bool operator!=(const msgtype& m){ return m_num != m.m_num; } constexpr const char* str(void)const{ return m_str; } constexpr operator int(void)const{ return m_num; } }; //class enumeration struct msg{ private: enum _types{ _text, _audio, _video, _file, _image, _other }; public: constexpr static msgtype text = msgtype("text", _text); constexpr static msgtype audio = msgtype("audio", _audio); constexpr static msgtype video = msgtype("video", _video); constexpr static msgtype file = msgtype("file", _file); constexpr static msgtype image = msgtype("image", _image); constexpr static msgtype other = msgtype("other", _other); constexpr static const msgtype& from_str(const char* str){ if(!strcmp(str, "m.text")){ return text; }else if(!strcmp(str, "m.audio")){ return audio; }else if(!strcmp(str, "m.video")){ return video; }else if(!strcmp(str, "m.file")){ return file; }else if(!strcmp(str, "m.image")){ return image; }else{ return other; } } }; struct event_info { const raii::rjp_string roomid; const raii::rjp_string sender; const raii::rjp_string eventid; const raii::rjp_string eventtype; const int serverts; const int age; }; struct msg_info : public event_info { const msgtype type = msg::other; const raii::rjp_string body; }; struct membership_info : public event_info { const raii::rjp_string recipient; }; } #endif