diff --git a/doc/TODO b/doc/TODO index e03c750..f03e9cc 100644 --- a/doc/TODO +++ b/doc/TODO @@ -12,10 +12,7 @@ matrix: 1:register account 1:device management client: - 3:get other user presence - 3:set presence 2:query other users' data - 1:download media 1:query/set custom user data 1:query/addto public room directory 1:deactivate account diff --git a/include/matrix/client.hpp b/include/matrix/client.hpp index ea2a909..6cae8a3 100644 --- a/include/matrix/client.hpp +++ b/include/matrix/client.hpp @@ -61,7 +61,8 @@ namespace matrix{ */ bool set_profile_picture(const raii::string_base&); - + bool set_presence(const raii::string_base& status); + raii::rjp_string get_presence(const raii::string_base& userid); /* * Gets the display name of the logged in user from the homeserver. * Returns: the display name on success, an empty string on failure. @@ -143,7 +144,10 @@ namespace matrix{ return true; } template - void download_file(const raii::string_base& server, const raii::string_base& media_id, DLHandler&& dl); + bool download_file(const raii::string_base& server, const raii::string_base& media_id, DLHandler&& dl){ + raii::string url = "mxc://"_ss + server + "/"_ss + media_id; + return download_file(url, std::forward(dl)); + } private: template static size_t _download_dispatch(char* ptr, size_t size, size_t nmemb, void* userdata){ diff --git a/src/matrix/client.cpp b/src/matrix/client.cpp index c468650..84677ac 100644 --- a/src/matrix/client.cpp +++ b/src/matrix/client.cpp @@ -38,6 +38,13 @@ namespace matrix{ _put_curl(raii::string("{\"avatar_url\":\"" + media_url + "\"}"), m_ses->urls.profile_picture(), raii::curl_llist()); return http_status() == 200; } + bool client::set_presence(const raii::string_base& status){ + _put_curl(raii::string("{\"presence\":\""_ss + status + "\"}"), m_ses->urls.presence(m_ses->homeserver, m_ses->access_token, m_ses->userid), raii::curl_llist()); + return http_status() == 200; + } + raii::rjp_string client::get_presence(const raii::string_base& userid){ + return _get_and_find(m_ses->urls.presence(m_ses->homeserver, m_ses->access_token, userid), "presence"_ss); + } //networked getter raii::rjp_string client::get_display_name(void)const{ @@ -184,19 +191,18 @@ namespace matrix{ internal_upload_data upload_data = {file.data.get(), file.data.size()}; m_curl.postreq(); m_curl.setopt(CURLOPT_POSTFIELDS, NULL); - m_curl.setopt(CURLOPT_READFUNCTION, _upload_file_read_callback); - m_curl.setopt(CURLOPT_READDATA, &upload_data); + m_curl.setreadfun(_upload_file_read_callback); + m_curl.setreaddata(&upload_data); m_curl.setopt(CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t)upload_data.len); m_curl.setopt(CURLOPT_INFILESIZE_LARGE, (curl_off_t)upload_data.len); m_curl.seturl(m_ses->urls.file_upload()); m_curl.setheader(header); - m_curl.setopt(CURLOPT_WRITEFUNCTION, _reply_curl_callback); - m_curl.setopt(CURLOPT_WRITEDATA, &fileurl); - CURLcode cres = m_curl.perform(); - m_curl.setopt(CURLOPT_READDATA, NULL); - if(cres != CURLE_OK){ + m_curl.setwritefun(_reply_curl_callback); + m_curl.setwritedata(&fileurl); + bool succ = _perform_curl(); + m_curl.setreaddata(NULL); + if(!succ) return {}; - } if(!fileurl) return {};