matrix_thing/src/matrix/events.cpp

110 lines
4.2 KiB
C++

/**
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 <http://www.gnu.org/licenses/>.
*/
#include "matrix/events.hpp"
namespace matrix::sync{
//Event base
raii::static_string event::type(void)const&{
RJP_search_res res = rjp_search_member(m_event, "type", 0);
return raii::static_string(rjp_value_string(res.value), rjp_value_string_length(res.value));
}
raii::rjp_string event::type(void)&&{
RJP_search_res res = rjp_search_member(m_event, "type", 0);
return raii::rjp_string(res.value);
}
const RJP_value* event::content(void)const{
RJP_search_res res = rjp_search_member(m_event, "content", 0);
return res.value;
}
RJP_value* event::content(void){
RJP_search_res res = rjp_search_member(m_event, "content", 0);
return res.value;
}
//Room event
raii::static_string room_event::eventid(void)const&{
RJP_search_res res = rjp_search_member(m_event, "event_id", 0);
return raii::static_string(rjp_value_string(res.value), rjp_value_string_length(res.value));
}
raii::rjp_string room_event::eventid(void)&&{
RJP_search_res res = rjp_search_member(m_event, "event_id", 0);
return raii::rjp_string(res.value);
}
raii::static_string room_event::sender(void)const&{
RJP_search_res res = rjp_search_member(m_event, "sender", 0);
return raii::static_string(rjp_value_string(res.value), rjp_value_string_length(res.value));
}
raii::rjp_string room_event::sender(void)&&{
RJP_search_res res = rjp_search_member(m_event, "sender", 0);
return raii::rjp_string(res.value);
}
int room_event::origin_server_ts(void)const{
RJP_search_res res = rjp_search_member(m_event, "origin_server_ts", 0);
return rjp_value_integer(res.value);
}
const RJP_value* room_event::extra(void)const{
RJP_search_res res = rjp_search_member(m_event, "unsigned", 0);
return res.value;
}
RJP_value* room_event::extra(void){
RJP_search_res res = rjp_search_member(m_event, "unsigned", 0);
return res.value;
}
raii::static_string room_event::redacts(void)const&{
RJP_search_res res = rjp_search_member(m_event, "redacts", 0);
return raii::static_string(rjp_value_string(res.value), rjp_value_string_length(res.value));
}
raii::rjp_string room_event::redacts(void)&&{
RJP_search_res res = rjp_search_member(m_event, "redacts", 0);
return raii::rjp_string(res.value);
}
//Room state event
raii::static_string room_state_event::state_key(void)const&{
RJP_search_res res = rjp_search_member(m_event, "state_key", 0);
return raii::static_string(rjp_value_string(res.value), rjp_value_string_length(res.value));
}
raii::rjp_string room_state_event::state_key(void)&&{
RJP_search_res res = rjp_search_member(m_event, "state_key", 0);
return raii::rjp_string(res.value);
}
raii::static_string room_state_event::prev_content(void)const&{
RJP_search_res res = rjp_search_member(m_event, "prev_content", 0);
if(res.value)
return raii::static_string(rjp_value_string(res.value), rjp_value_string_length(res.value));
res = rjp_search_member(m_event, "unsigned", 0);
if(!res.value)
return raii::static_string{};
res = rjp_search_member(res.value, "prev_content", 0);
return raii::static_string(rjp_value_string(res.value), rjp_value_string_length(res.value));
}
raii::rjp_string room_state_event::prev_content(void)&&{
RJP_search_res res = rjp_search_member(m_event, "prev_content", 0);
if(res.value)
return raii::rjp_string(res.value);
res = rjp_search_member(m_event, "unsigned", 0);
if(!res.value)
return raii::static_string{};
res = rjp_search_member(res.value, "prev_content", 0);
return raii::rjp_string(res.value);
}
}