/** 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 . */ #include "matrix/events.hpp" #include "matrix/json_targets.hpp" namespace matrix::sync{ //Event base event::event(RJP_value* ev): m_event(ev), m_type(rjp_search_member(ev, json::keys::event::type(), 0).value), m_content(rjp_search_member(ev, json::keys::event::content(), 0).value){} raii::static_string event::type(void)const&{ return raii::static_string(rjp_value_string(m_type), rjp_value_string_length(m_type)); } raii::rjp_string event::type(void)&&{ return raii::rjp_string(std::exchange(m_type, nullptr)); } const RJP_value* event::content(void)const{ return m_content; } RJP_value* event::content(void){ return m_content; } const RJP_value* event::raw(void)const{ return m_event; } RJP_value* event::raw(void){ return m_event; } //Room event room_event::room_event(RJP_value* ev, const raii::string_base& roomid): room_event_base(roomid), event(ev), m_id(rjp_search_member(ev, json::keys::event::eventid(), 0).value), m_sender(rjp_search_member(ev, json::keys::event::sender(), 0).value), m_unsigned(rjp_search_member(ev, json::keys::event::extra(), 0).value), m_redacts(rjp_search_member(ev, json::keys::event::redacts(), 0).value), m_origin_server_ts(rjp_value_integer(rjp_search_member(ev, json::keys::event::origin_server_ts(), 0).value)){} raii::static_string room_event::eventid(void)const&{ return raii::static_string(rjp_value_string(m_id), rjp_value_string_length(m_id)); } raii::rjp_string room_event::eventid(void)&&{ return raii::rjp_string(std::exchange(m_id, nullptr)); } raii::static_string room_event::sender(void)const&{ return raii::static_string(rjp_value_string(m_sender), rjp_value_string_length(m_sender)); } raii::rjp_string room_event::sender(void)&&{ return raii::rjp_string(std::exchange(m_sender, nullptr)); } int room_event::origin_server_ts(void)const{ return m_origin_server_ts; } const RJP_value* room_event::extra(void)const{ return m_unsigned; } RJP_value* room_event::extra(void){ return m_unsigned; } raii::static_string room_event::redacts(void)const&{ if(!m_redacts) return raii::static_string(); return raii::static_string(rjp_value_string(m_redacts), rjp_value_string_length(m_redacts)); } raii::rjp_string room_event::redacts(void)&&{ if(!m_redacts) return raii::rjp_string(); return raii::rjp_string(std::exchange(m_redacts, nullptr)); } //Room state event room_state_event::room_state_event(RJP_value* ev, const raii::string_base& roomid): room_event(ev, roomid), m_state_key(rjp_search_member(ev, json::keys::event::state_key(), 0).value), m_prev_content(rjp_search_member(ev, json::keys::event::prev_content(), 0).value) { if(!m_prev_content && m_unsigned){ m_prev_content = rjp_search_member(m_unsigned, json::keys::event::prev_content(), 0).value; } } raii::static_string room_state_event::state_key(void)const&{ return raii::static_string(rjp_value_string(m_state_key), rjp_value_string_length(m_state_key)); } raii::rjp_string room_state_event::state_key(void)&&{ return raii::rjp_string(std::exchange(m_state_key, nullptr)); } raii::static_string room_state_event::prev_content(void)const&{ return raii::static_string(rjp_value_string(m_prev_content), rjp_value_string_length(m_prev_content)); } raii::rjp_string room_state_event::prev_content(void)&&{ return raii::rjp_string(std::exchange(m_prev_content, nullptr)); } room_ephemeral_event::room_ephemeral_event(RJP_value* ev, const raii::string_base& roomid): room_event_base(roomid), event(ev){} }