Pleroma Get chats
FossilOrigin-Name: e9de6a96241f37a6f2ed75e10c1a8866b1831b92600339642ce67bad711085f7
This commit is contained in:
parent
310c6ac457
commit
7548de2b24
3 changed files with 41 additions and 4 deletions
|
@ -22,7 +22,7 @@ struct mstdnt_chat
|
|||
{
|
||||
struct mstdnt_account account;
|
||||
const char* id;
|
||||
int unread;
|
||||
unsigned int unread;
|
||||
};
|
||||
|
||||
struct mstdnt_chats_args
|
||||
|
@ -35,6 +35,11 @@ struct mstdnt_chats_args
|
|||
int limit;
|
||||
};
|
||||
|
||||
int mstdnt_chat_json(struct mstdnt_chat* chat, cJSON* js);
|
||||
int mstdnt_chats_json(struct mstdnt_chat* statuses[],
|
||||
size_t* size,
|
||||
cJSON* js);
|
||||
|
||||
int mastodont_get_chats_v2(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_chats_args* args,
|
||||
|
|
|
@ -38,7 +38,7 @@ struct _mstdnt_query_param
|
|||
enum _mstdnt_query_type type;
|
||||
char* key;
|
||||
union param_value {
|
||||
char* s;
|
||||
const char* s;
|
||||
int i;
|
||||
mstdnt_bool b;
|
||||
struct _mstdnt_query_array a;
|
||||
|
|
36
src/chats.c
36
src/chats.c
|
@ -19,6 +19,8 @@
|
|||
#include <mastodont_fetch.h>
|
||||
#include <mastodont_query.h>
|
||||
#include <mastodont_request.h>
|
||||
#include <mastodont_generate.h>
|
||||
#include <mastodont_json_helper.h>
|
||||
|
||||
struct _mstdnt_chats_cb_args
|
||||
{
|
||||
|
@ -26,6 +28,36 @@ struct _mstdnt_chats_cb_args
|
|||
size_t* chats_len;
|
||||
};
|
||||
|
||||
int mstdnt_chat_json(struct mstdnt_chat* chat, cJSON* js)
|
||||
{
|
||||
memset(chat, 0, sizeof(struct mstdnt_chat));
|
||||
|
||||
struct _mstdnt_val_ref vals[] = {
|
||||
{ "account", &(chat->account), _mstdnt_val_account_call },
|
||||
{ "id", &(chat->id), _mstdnt_val_string_call },
|
||||
{ "unread", &(chat->unread), _mstdnt_val_uint_call },
|
||||
};
|
||||
|
||||
for (cJSON* v = js; v; v = v->next)
|
||||
_mstdnt_key_val_ref(v, vals, _mstdnt_arr_len(vals));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mstdnt_chat_json_callback(cJSON* json, void* chat)
|
||||
{
|
||||
return mstdnt_chat_json(chat, json->child);
|
||||
}
|
||||
|
||||
// GENERATE mstdnt_chats_json
|
||||
GENERATE_JSON_ARRAY_FUNC(mstdnt_chats_json, struct mstdnt_chat, mstdnt_chat_json)
|
||||
|
||||
int mstdnt_chats_json_callback(cJSON* json, void* _args)
|
||||
{
|
||||
struct _mstdnt_chats_cb_args* args = _args;
|
||||
return mstdnt_chats_json(args->chats, args->chats_len, json);
|
||||
}
|
||||
|
||||
int mastodont_get_chats_v2(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_chats_args* args,
|
||||
|
@ -47,12 +79,12 @@ int mastodont_get_chats_v2(mastodont_t* data,
|
|||
.storage = storage,
|
||||
.url = "api/v2/pleroma/chats",
|
||||
.params_query = params,
|
||||
.params_query_len = _mstdnt_arg_len(params),
|
||||
.params_query_len = _mstdnt_arr_len(params),
|
||||
.params_post = NULL,
|
||||
.params_post_len = 0,
|
||||
.request_type = CURLOPT_HTTPGET,
|
||||
.request_type_custom = NULL,
|
||||
.args = cb_args,
|
||||
.args = &cb_args,
|
||||
.callback = mstdnt_chats_json_callback,
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue