Relationship results

FossilOrigin-Name: 0c831ab4b2eba69074b859878d533d2898ed99a001ec35dea8ad75dd431dad38
This commit is contained in:
me@ow.nekobit.net 2022-04-05 19:44:05 +00:00
parent b8fef49737
commit b2c0435aed
10 changed files with 61 additions and 16 deletions

1
1 Normal file
View file

@ -0,0 +1 @@
make: *** No rule to make target '2'. Stop.

View file

@ -17,11 +17,11 @@
#define MASTODONT_H
#include <mastodont_types.h>
#include <mastodont_timeline.h>
#include <mastodont_account.h>
#include <mastodont_list.h>
#include <mastodont_notification.h>
#include <mastodont_status.h>
#include <mastodont_relationship.h>
#include <mastodont_account.h>
/* Functions required form curl */
void mastodont_global_curl_init();

View file

@ -17,6 +17,7 @@
#define MASTODONT_ACCOUNT
#include "mastodont_types.h"
#include "mastodont_fetch.h"
#include "mastodont_relationship.h"
#include <cjson/cJSON.h>
#define MSTDNT_LOOKUP_ACCT 0
@ -55,9 +56,15 @@ struct mstdnt_account
char* mute_expires_at;
};
#define MSTDNT_ACCOUNT_ACTION_DECL(type) int mastodont_##type##_account(mastodont_t* data, char* id, struct mstdnt_storage* storage, struct mstdnt_account* acct)
int mstdnt_account_action(mastodont_t* data,
char* id,
struct mstdnt_storage* storage,
struct mstdnt_relationship* rel,
char* url_str);
#define MSTDNT_ACCOUNT_ACTION_DECL(type) int mastodont_##type##_account(mastodont_t* data, char* id, struct mstdnt_storage* storage, struct mstdnt_relationship* relationship)
#define MSTDNT_ACCOUNT_ACTION_FUNC_URL(action) { \
return mstdnt_account_action(data, id, storage, acct, "api/v1/accounts/%s/" action);\
return mstdnt_account_action(data, id, storage, relationship, "api/v1/accounts/%s/" action); \
}
MSTDNT_ACCOUNT_ACTION_DECL(follow);

View file

@ -41,6 +41,14 @@ struct mstdnt_relationship
char* note;
};
int _mstdnt_relationship_result_callback(struct mstdnt_fetch_results* results,
struct mstdnt_storage* storage,
void* _args);
int mstdnt_relationship_result(struct mstdnt_fetch_results* results,
struct mstdnt_storage* storage,
struct mstdnt_relationship* relationship);
int mstdnt_relationship_json(struct mstdnt_relationship* relationship, cJSON* js);
int mstdnt_relationships_result(struct mstdnt_fetch_results* results,
@ -50,7 +58,6 @@ int mstdnt_relationships_result(struct mstdnt_fetch_results* results,
int _mstdnt_relationships_result_callback(struct mstdnt_fetch_results* results,
struct mstdnt_storage* storage,
void* _args);
int mastodont_get_relationships(mastodont_t* data,
@ -62,4 +69,5 @@ int mastodont_get_relationships(mastodont_t* data,
void mstdnt_cleanup_relationships(struct mstdnt_relationship* rels);
#endif /* MASTODONT_RELATIONSHIP_H */

View file

@ -15,7 +15,6 @@
#ifndef MASTODONT_REQUEST_H
#define MASTODONT_REQUEST_H
#include "mastodont.h"
#include "mastodont_types.h"
#include "mastodont_fetch.h"
#include "mastodont_query.h"

View file

@ -26,8 +26,8 @@
#include "mastodont_account.h"
#include "mastodont_emoji.h"
#include "mastodont_tag.h"
#include "mastodont_account.h"
#include "mastodont_pleroma.h"
#include "mastodont_account.h"
#include "mastodont_visibility_types.h"
/* Status: Complete, not implemented */

View file

@ -13,6 +13,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <mastodont_account.h>
@ -135,11 +136,11 @@ int mstdnt_account_from_json(struct mstdnt_account* acct, cJSON* js)
}
static int mstdnt_account_action(mastodont_t* data,
char* id,
struct mstdnt_storage* storage,
struct mstdnt_account* acct,
char* url_str)
int mstdnt_account_action(mastodont_t* data,
char* id,
struct mstdnt_storage* storage,
struct mstdnt_relationship* rel,
char* url_str)
{
char url[MSTDNT_URLSIZE];
snprintf(url, MSTDNT_URLSIZE, url_str, id);
@ -150,8 +151,8 @@ static int mstdnt_account_action(mastodont_t* data,
NULL, 0,
NULL, 0,
CURLOPT_POST,
acct,
mstdnt_account_callback
rel,
_mstdnt_relationship_result_callback
};
return mastodont_request(data, &req_args);

View file

@ -105,6 +105,26 @@ int mstdnt_relationships_result(struct mstdnt_fetch_results* results,
}
}
int mstdnt_relationship_result(struct mstdnt_fetch_results* results,
struct mstdnt_storage* storage,
struct mstdnt_relationship* relationship)
{
if (!relationship) return 0;
cJSON* root;
if (_mstdnt_json_init(&root, results, storage))
return 1;
return mstdnt_relationship_json(relationship, root->child);
}
int _mstdnt_relationship_result_callback(struct mstdnt_fetch_results* results,
struct mstdnt_storage* storage,
void* _args)
{
return mstdnt_relationship_result(results, storage, (struct mstdnt_relationship*)_args);
}
int _mstdnt_relationships_result_callback(struct mstdnt_fetch_results* results,
struct mstdnt_storage* storage,
void* _args)

View file

@ -13,6 +13,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
@ -38,8 +39,13 @@ int mastodont_request(mastodont_t* data, struct mastodont_request_args* args)
post = _mstdnt_query_string(data, NULL, args->params_post, args->params_post_len);
curl_easy_setopt(data->curl, CURLOPT_POSTFIELDS, post);
}
/* Make it empty, no post data provided */
/* I'm not sure why the pleroma api does this */
else if (args->request_type == CURLOPT_POST)
curl_easy_setopt(data->curl, CURLOPT_POSTFIELDS, "");
curlerror = mastodont_fetch_curl(data, url_query, &results, args->request_type);
if (curlerror != CURLE_OK)
{
res = 1;
@ -47,12 +53,15 @@ int mastodont_request(mastodont_t* data, struct mastodont_request_args* args)
goto cleanup;
}
if (mstdnt_check_error(&results, storage))
{
res = 1;
goto cleanup_res;
}
storage->needs_cleanup = 1;
/* Optional */
if (args->callback) args->callback(&results, storage, args->args);

View file

@ -101,9 +101,7 @@ int mstdnt_status_from_result(struct mstdnt_fetch_results* results,
!cJSON_IsObject(root))
return 1;
mstdnt_status_from_json(status, root->child);
return 1;
return mstdnt_status_from_json(status, root->child);
}
int _mstdnt_status_from_result_callback(struct mstdnt_fetch_results* results,
@ -375,7 +373,9 @@ int mstdnt_status_context_from_json(struct mstdnt_fetch_results* results,
return 1;
cJSON_ArrayForEach(status_item, v)
{
mstdnt_status_from_json((*stat_ptr) + (*size_ptr)++, status_item->child);
}
}
}
}