Add ability to set/get presence
This commit is contained in:
parent
fa75e8f0d7
commit
bb6c39a109
3
doc/TODO
3
doc/TODO
@ -12,10 +12,7 @@ matrix:
|
|||||||
1:register account
|
1:register account
|
||||||
1:device management
|
1:device management
|
||||||
client:
|
client:
|
||||||
3:get other user presence
|
|
||||||
3:set presence
|
|
||||||
2:query other users' data
|
2:query other users' data
|
||||||
1:download media
|
|
||||||
1:query/set custom user data
|
1:query/set custom user data
|
||||||
1:query/addto public room directory
|
1:query/addto public room directory
|
||||||
1:deactivate account
|
1:deactivate account
|
||||||
|
|||||||
@ -61,7 +61,8 @@ namespace matrix{
|
|||||||
*/
|
*/
|
||||||
bool set_profile_picture(const raii::string_base&);
|
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.
|
* Gets the display name of the logged in user from the homeserver.
|
||||||
* Returns: the display name on success, an empty string on failure.
|
* Returns: the display name on success, an empty string on failure.
|
||||||
@ -143,7 +144,10 @@ namespace matrix{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
template<class DLHandler>
|
template<class DLHandler>
|
||||||
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<DLHandler>(dl));
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
template<class DLHandler>
|
template<class DLHandler>
|
||||||
static size_t _download_dispatch(char* ptr, size_t size, size_t nmemb, void* userdata){
|
static size_t _download_dispatch(char* ptr, size_t size, size_t nmemb, void* userdata){
|
||||||
|
|||||||
@ -38,6 +38,13 @@ namespace matrix{
|
|||||||
_put_curl(raii::string("{\"avatar_url\":\"" + media_url + "\"}"), m_ses->urls.profile_picture(), raii::curl_llist());
|
_put_curl(raii::string("{\"avatar_url\":\"" + media_url + "\"}"), m_ses->urls.profile_picture(), raii::curl_llist());
|
||||||
return http_status() == 200;
|
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
|
//networked getter
|
||||||
raii::rjp_string client::get_display_name(void)const{
|
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()};
|
internal_upload_data upload_data = {file.data.get(), file.data.size()};
|
||||||
m_curl.postreq();
|
m_curl.postreq();
|
||||||
m_curl.setopt(CURLOPT_POSTFIELDS, NULL);
|
m_curl.setopt(CURLOPT_POSTFIELDS, NULL);
|
||||||
m_curl.setopt(CURLOPT_READFUNCTION, _upload_file_read_callback);
|
m_curl.setreadfun(_upload_file_read_callback);
|
||||||
m_curl.setopt(CURLOPT_READDATA, &upload_data);
|
m_curl.setreaddata(&upload_data);
|
||||||
m_curl.setopt(CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t)upload_data.len);
|
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.setopt(CURLOPT_INFILESIZE_LARGE, (curl_off_t)upload_data.len);
|
||||||
m_curl.seturl(m_ses->urls.file_upload());
|
m_curl.seturl(m_ses->urls.file_upload());
|
||||||
m_curl.setheader(header);
|
m_curl.setheader(header);
|
||||||
m_curl.setopt(CURLOPT_WRITEFUNCTION, _reply_curl_callback);
|
m_curl.setwritefun(_reply_curl_callback);
|
||||||
m_curl.setopt(CURLOPT_WRITEDATA, &fileurl);
|
m_curl.setwritedata(&fileurl);
|
||||||
CURLcode cres = m_curl.perform();
|
bool succ = _perform_curl();
|
||||||
m_curl.setopt(CURLOPT_READDATA, NULL);
|
m_curl.setreaddata(NULL);
|
||||||
if(cres != CURLE_OK){
|
if(!succ)
|
||||||
return {};
|
return {};
|
||||||
}
|
|
||||||
|
|
||||||
if(!fileurl)
|
if(!fileurl)
|
||||||
return {};
|
return {};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user