From 0d59ccf1ce8d33f04d70f3b1c5ffd614d87458e4 Mon Sep 17 00:00:00 2001 From: "me@ow.nekobit.net" Date: Mon, 4 Apr 2022 19:40:16 +0000 Subject: [PATCH] Initial relationships stuff FossilOrigin-Name: be06c04ac980427473a9b47ff1402a8faebc896fe629fe049480b76768022d3b --- include/mastodont_pleroma.h | 2 +- include/mastodont_relationship.h | 53 ++++++++++++++++++++++++++ src/relationship.c | 64 ++++++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 include/mastodont_relationship.h create mode 100644 src/relationship.c diff --git a/include/mastodont_pleroma.h b/include/mastodont_pleroma.h index 1eeeaf9..9b3f063 100644 --- a/include/mastodont_pleroma.h +++ b/include/mastodont_pleroma.h @@ -38,4 +38,4 @@ void cleanup_status_pleroma(struct mstdnt_status_pleroma* pleroma); int mstdnt_status_pleroma_from_json(struct mstdnt_status_pleroma* pleroma, cJSON* js); void _mstdnt_val_status_pleroma_call(cJSON* v, void* _type); -#endif /* MASTODONT_PLEROMA */ +#endif /* MASTODONT_PLEROMA_H */ diff --git a/include/mastodont_relationship.h b/include/mastodont_relationship.h new file mode 100644 index 0000000..3962b12 --- /dev/null +++ b/include/mastodont_relationship.h @@ -0,0 +1,53 @@ +/* + * 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 . + */ + +#ifndef MASTODONT_RELATIONSHIP_H +#define MASTODONT_RELATIONSHIP_H +#include + +struct mstdnt_relationship +{ + char* id; + mstdnt_bool following; + mstdnt_bool requested; + mstdnt_bool endorsed; + mstdnt_bool followed_by; + mstdnt_bool muting; + mstdnt_bool muting_notifications; + mstdnt_bool showing_reblogs; + mstdnt_bool notifying; + mstdnt_bool blocking; + mstdnt_bool domain_blocking; + mstdnt_bool blocked_by; + char* note; +}; + +int mstdnt_relationships_result(struct mstdnt_fetch_results* results, + struct mstdnt_storage* storage, + struct mstdnt_relationship* relationships, + size_t* size); + +int _mstdnt_relationships_result_callback(struct mstdnt_fetch_results* results, + struct mstdnt_storage* storage, + void* _args); + +int mastodont_get_relationships(mastodont_t* data, + char** ids, + size_t ids_len, + struct mstdnt_storage* storage, + struct mstdnt_relationship* relationships[], + size_t* size); + +#endif /* MASTODONT_RELATIONSHIP_H */ diff --git a/src/relationship.c b/src/relationship.c new file mode 100644 index 0000000..9b846be --- /dev/null +++ b/src/relationship.c @@ -0,0 +1,64 @@ +/* + * 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 . + */ + +#include +#include + +struct _mstdnt_relationships_cb_args +{ + struct mstdnt_relationship* relationships; + size_t* size; +}; + +int mstdnt_relationships_result(struct mstdnt_fetch_results* results, + struct mstdnt_storage* storage, + struct mstdnt_relationship* relationships, + size_t* size) +{ +} + +int _mstdnt_relationships_result_callback(struct mstdnt_fetch_results* results, + struct mstdnt_storage* storage, + void* _args) +{ + struct _mstdnt_relationships_cb_args* args = _args; + return mstdnt_relationships_result(storage, results, args->relationships, args->size); + // TODO here +} + +int mastodont_get_relationships(mastodont_t* data, + char** ids, + size_t ids_len, + struct mstdnt_storage* storage, + struct mstdnt_relationship* relationships[], + size_t* size) +{ + /* struct _mstdnt_query_param params[] = { 0 }; */ + struct _mstdnt_relationships_cb_args cb_args = { relationships, size }; + + struct mastodont_request_args req_args = { + storage, + "api/v1/accounts/relationships", + NULL, 0, + NULL, 0, + /* params, _mstdnt_arr_len(params), */ + CURLOPT_GET, + &cb_args, + _mstdnt_relationships_result_callback, /* TODO populate the status back? + * (not sure if the api returns it or not) */ + }; + + return mastodont_request(data, &req_args); +}