Chats function

FossilOrigin-Name: a39eabab3af2ea866532ff00fedf5a037c4e98ca86b54cd2964e4fe9f082299e
This commit is contained in:
nekobit 2022-07-03 22:06:36 +00:00
parent 53d174aeb1
commit 310c6ac457
2 changed files with 105 additions and 0 deletions

45
include/mastodont_chats.h Normal file
View file

@ -0,0 +1,45 @@
/*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser 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 Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef MASTODONT_CHATS_H
#define MASTODONT_CHATS_H
#include "mastodont_types.h"
#include "mastodont_account.h"
struct mstdnt_chat
{
struct mstdnt_account account;
const char* id;
int unread;
};
struct mstdnt_chats_args
{
mstdnt_bool with_muted;
const char* max_id;
const char* min_id;
const char* since_id;
int offset;
int limit;
};
int mastodont_get_chats_v2(mastodont_t* data,
struct mstdnt_args* m_args,
struct mstdnt_chats_args* args,
struct mstdnt_storage* storage,
struct mstdnt_chat* chats[],
size_t* chats_len);
#endif // MASTODONT_CHATS_H

60
src/chats.c Normal file
View file

@ -0,0 +1,60 @@
/*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser 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 Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <string.h>
#include <stdlib.h>
#include <mastodont_chats.h>
#include <mastodont_fetch.h>
#include <mastodont_query.h>
#include <mastodont_request.h>
struct _mstdnt_chats_cb_args
{
struct mstdnt_chat** chats;
size_t* chats_len;
};
int mastodont_get_chats_v2(mastodont_t* data,
struct mstdnt_args* m_args,
struct mstdnt_chats_args* args,
struct mstdnt_storage* storage,
struct mstdnt_chat* chats[],
size_t* size)
{
struct _mstdnt_chats_cb_args cb_args = { chats, size };
struct _mstdnt_query_param params[] = {
{ _MSTDNT_QUERY_BOOL, "with_muted", { .b = args->with_muted } },
{ _MSTDNT_QUERY_STRING, "max_id", { .s = args->max_id } },
{ _MSTDNT_QUERY_STRING, "min_id", { .s = args->min_id } },
{ _MSTDNT_QUERY_STRING, "since_id", { .s = args->since_id } },
{ _MSTDNT_QUERY_INT, "limit", { .i = args->limit } },
{ _MSTDNT_QUERY_INT, "offset", { .i = args->offset } },
};
struct mastodont_request_args req_args = {
.storage = storage,
.url = "api/v2/pleroma/chats",
.params_query = params,
.params_query_len = _mstdnt_arg_len(params),
.params_post = NULL,
.params_post_len = 0,
.request_type = CURLOPT_HTTPGET,
.request_type_custom = NULL,
.args = cb_args,
.callback = mstdnt_chats_json_callback,
};
return mastodont_request(data, m_args, &req_args);
}