162 lines
5.8 KiB
C++
162 lines
5.8 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/>.
|
|
*/
|
|
|
|
#ifndef MATRIX_CLIENT_HPP
|
|
#define MATRIX_CLIENT_HPP
|
|
|
|
#include "raii/string.hpp"
|
|
#include "raii/rjp_string.hpp"
|
|
#include "raii/filerd.hpp"
|
|
#include "matrix/session_info.hpp"
|
|
#include "matrix/upload_info.hpp"
|
|
#include "matrix/connection.hpp"
|
|
#include "matrix/roomcxn.hpp"
|
|
#include <vector> //vector
|
|
#include <memory> //shared_ptr
|
|
#include <cstdlib> //size_t
|
|
|
|
namespace matrix{
|
|
//Class to interact with the homeserver of the logged in user.
|
|
//Shares state with the spawning session.
|
|
class client : public connection
|
|
{
|
|
public:
|
|
client(const std::shared_ptr<internal::session_info>&);
|
|
|
|
//Copy and move ctor
|
|
client(const client& b) = default;
|
|
client(client&& b) = default;
|
|
//Dtor
|
|
~client(void) = default;
|
|
|
|
//Copy and move assignment
|
|
client& operator=(const client&) = default;
|
|
client& operator=(client&&) = default;
|
|
|
|
/*
|
|
* NOT thread safe.
|
|
* Returns: the current access token.
|
|
*/
|
|
const raii::rjp_string& access_token(void)const;
|
|
/*
|
|
* NOT thread safe
|
|
* Returns: the logged in user's userid.
|
|
*/
|
|
const raii::rjp_string& userid(void)const;
|
|
/*
|
|
* NOT thread safe
|
|
* Returns: the current useragent.
|
|
*/
|
|
const raii::string& useragent(void)const;
|
|
|
|
|
|
/*
|
|
* Sets the display name on the homeserver.
|
|
* Note name must be safe to be placed in a json string.
|
|
* Returns: true if the operation was successful.
|
|
*/
|
|
bool set_display_name(const raii::string_base&);
|
|
/*
|
|
* Sets the url of the user's profile picture on the homeserver.
|
|
* Note url must be safe to be placed in a json string.
|
|
* Returns: true if the operation was successful.
|
|
*/
|
|
bool set_profile_picture(const raii::string_base&);
|
|
|
|
|
|
/*
|
|
* Gets the display name of the logged in user from the homeserver.
|
|
* Returns: the display name on success, an empty string on failure.
|
|
*/
|
|
raii::rjp_string get_display_name(void)const;
|
|
/*
|
|
* Gets the profile picture url of the logged in user from the homeserver.
|
|
* Returns: the profile picture url on success, an empty string on failure.
|
|
*/
|
|
raii::rjp_string get_profile_picture(void)const;
|
|
/*
|
|
* Lookup a room id given a room alias.
|
|
* Returns: the room id of the associated room on success, empty string on failure.
|
|
*/
|
|
raii::rjp_string room_alias_to_id(const raii::string_base& alias)const;
|
|
|
|
/*
|
|
* Get a list of rooms the logged in user is a member of.
|
|
* Returns: a vector of room id strings.
|
|
*/
|
|
std::vector<raii::rjp_string> list_rooms(void)const;
|
|
|
|
/*
|
|
* Create a new room on the logged in user's homeserver. Assign an alias to the room.
|
|
* Returns: the room id of the newly created room on success, an empty string on failure.
|
|
*/
|
|
raii::rjp_string create_room(const raii::string_base& name, const raii::string_base& alias)const;
|
|
|
|
/*
|
|
* Create a new matrix::roomcxn object for the given roomid.
|
|
* The roomcxn will share login information with this client. Note that changing useragent,
|
|
* access token, or homeserver after creating a roomcxn MUST be synchronized between threads.
|
|
* Returns: a new matrix::roomcxn for the given roomid.
|
|
*/
|
|
roomcxn spawn_room(const raii::string_base& roomid)const;
|
|
roomcxn spawn_room(raii::string&& roomid)const;
|
|
|
|
|
|
//NOTE alias equivalents just give the uploaded file a name other than the filename.
|
|
/*
|
|
* Upload a file as a raw file.
|
|
* Takes filename as argument.
|
|
* Returns: file_info struct containing the url of the file on the homeserver.
|
|
* Note check the file_info::fileurl field to check if the upload succeeded.
|
|
*/
|
|
file_info upload_file(const raii::string_base& filename)const;
|
|
file_info upload_file(const raii::string_base& filename, const raii::string_base& alias)const;
|
|
|
|
/*
|
|
* Upload a file as an image.
|
|
* Note: requires FreeImagePlus to treat the file as an image, otherwise will just upload as a raw file.
|
|
* Returns: image_info struct containing the url of the image on the homeserver.
|
|
* Note check the image_info::fileurl field to check if the upload succeeded.
|
|
*/
|
|
image_info upload_image(const raii::string_base& filename)const;
|
|
image_info upload_image(const raii::string_base& filename, const raii::string_base& alias)const;
|
|
|
|
/*
|
|
* Upload a file as a video.
|
|
* Note: requires ffmpeg to treat the file as a video, otherwise will just upload as a raw file.
|
|
* Returns: video_info struct containing the url of the image on the homeserver.
|
|
* Note check the video_info::fileurl field to check if the upload succeeded.
|
|
*/
|
|
video_info upload_video(const raii::string_base& filename)const;
|
|
video_info upload_video(const raii::string_base& filename, const raii::string_base& alias)const;
|
|
/*
|
|
* Upload a file as an audio file.
|
|
* Note: requires ffmpeg to treat the file as a audio, otherwise will just upload as a raw file.
|
|
* Returns: audio_info struct containing the url of the image on the homeserver.
|
|
* Note check the audio_info::fileurl field to check if the upload succeeded.
|
|
*/
|
|
audio_info upload_audio(const raii::string_base& filename)const;
|
|
audio_info upload_audio(const raii::string_base& filename, const raii::string_base& alias)const;
|
|
|
|
private:
|
|
raii::rjp_string _upload_file(raii::filerd& fp, const raii::curl_llist& header)const;
|
|
};
|
|
}
|
|
|
|
#endif
|