matrix_thing/src/matrix/syncer.cpp
2019-07-17 15:08:20 -07:00

46 lines
1.4 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/syncer.hpp"
#include "raii/static_string.hpp"
#include "raii/rjp_ptr.hpp"
#include "raii/util.hpp"
namespace matrix{
syncer::syncer(std::shared_ptr<internal::session_info>& ses):
client_base(),
m_ses(ses){}
raii::string syncer::sync(size_t timeout){
raii::string reply = _get_curl(m_ses->urls.sync(m_ses->homeserver, m_ses->access_token, m_next_batch, raii::itostr(timeout)));
if(!reply)
return {};
raii::rjp_ptr root(rjp_parse(reply));
if(!root)
return reply;
RJP_search_res res = rjp_search_member(root.get(), "next_batch", 0);
if(!res.value)
return reply;
m_next_batch = res.value;
return reply;
}
}