/** 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_SYNCER_HPP #define MATRIX_SYNCER_HPP #include "raii/curler.hpp" #include "raii/rjp_ptr.hpp" #include "raii/rjp_string.hpp" #include "raii/string.hpp" #include "matrix/event_info.hpp" #include "matrix/session_info.hpp" #include "matrix/client_base.hpp" #include //size_t #include //forward #include //function #include //shared_ptr namespace matrix{ class session; class syncer : public internal::client_base { friend class ::matrix::session; private: const std::shared_ptr m_ses; std::function m_message_callback; std::function m_membership_callback; std::function m_raw_callback; raii::rjp_string m_next_batch; //string which tracks where we are in the server history public: syncer(std::shared_ptr&); syncer(const syncer& b) = default; syncer(syncer&& b) = default; ~syncer(void) = default; syncer& operator=(const syncer&) = default; syncer& operator=(syncer&&) = default; template void set_message_callback(Func&& f){ m_message_callback = std::forward(f); } template void set_membership_callback(Func&& f){ m_membership_callback = std::forward(f); } template void set_raw_callback(Func&& f){ m_raw_callback = std::forward(f); } raii::string sync(size_t timeout); private: void _handle_membership_events(RJP_value* rooms); void _handle_other_membership(RJP_value* join); void _handle_invites(RJP_value* invites); void _handle_messages(RJP_value* messages); }; } #endif