Fix attachments
FossilOrigin-Name: 027a89e3e81deed48819357242b7b10d985dd12464adc1f6a573de14233baf71
This commit is contained in:
parent
27cde5386b
commit
4e01325e4e
5 changed files with 30 additions and 7 deletions
|
@ -18,6 +18,7 @@
|
|||
#include "mastodont_types.h"
|
||||
#include "mastodont_fetch.h"
|
||||
#include "mastodont_relationship.h"
|
||||
#include "mastodont_emoji.h"
|
||||
#include <cjson/cJSON.h>
|
||||
|
||||
#define MSTDNT_LOOKUP_ACCT 0
|
||||
|
@ -46,6 +47,9 @@ struct mstdnt_account
|
|||
mstdnt_bool locked;
|
||||
mstdnt_bool discoverable;
|
||||
|
||||
struct mstdnt_emoji* emojis;
|
||||
size_t emojis_len;
|
||||
|
||||
/* Statistic attributes */
|
||||
char* created_at;
|
||||
char* last_status_at;
|
||||
|
@ -101,4 +105,7 @@ int mstdnt_accounts_json_callback(cJSON* json, void* _args);
|
|||
void _mstdnt_val_account_call(cJSON* v, void* _type);
|
||||
void _mstdnt_val_malloc_account_call(cJSON* v, void* _type);
|
||||
|
||||
// Cleanup
|
||||
void mstdnt_cleanup_account(struct mstdnt_account* acct);
|
||||
|
||||
#endif /* MASTODONT_ACCOUNT */
|
||||
|
|
|
@ -102,6 +102,11 @@ int mstdnt_account_json(struct mstdnt_account* acct, cJSON* js)
|
|||
/* Zero out */
|
||||
memset(acct, 0, sizeof(struct mstdnt_account));
|
||||
|
||||
struct _mstdnt_generic_args emj_args = {
|
||||
&(acct->emojis),
|
||||
&(acct->emojis_len)
|
||||
};
|
||||
|
||||
struct _mstdnt_val_ref refs[] = {
|
||||
{ "id", &(acct->id), _mstdnt_val_string_call },
|
||||
{ "username", &(acct->username), _mstdnt_val_string_call },
|
||||
|
@ -112,6 +117,7 @@ int mstdnt_account_json(struct mstdnt_account* acct, cJSON* js)
|
|||
{ "url", &(acct->url), _mstdnt_val_string_call },
|
||||
{ "avatar", &(acct->avatar), _mstdnt_val_string_call },
|
||||
{ "avatar_static", &(acct->avatar_static), _mstdnt_val_string_call },
|
||||
{ "emojis", &emj_args, _mstdnt_val_emojis_call },
|
||||
{ "header", &(acct->header), _mstdnt_val_string_call },
|
||||
{ "header_static", &(acct->header_static), _mstdnt_val_string_call },
|
||||
{ "last_status_at", &(acct->last_status_at), _mstdnt_val_string_call },
|
||||
|
@ -178,3 +184,8 @@ MSTDNT_ACCOUNT_ACTION_FUNC_URL("subscribe")
|
|||
|
||||
MSTDNT_ACCOUNT_ACTION_DECL(unsubscribe)
|
||||
MSTDNT_ACCOUNT_ACTION_FUNC_URL("unsubscribe")
|
||||
|
||||
void mstdnt_cleanup_account(struct mstdnt_account* acct)
|
||||
{
|
||||
cleanup_emojis(acct->emojis);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#include <mastodont_request.h>
|
||||
#include <mastodont_query.h>
|
||||
|
||||
int mstdnt_attachment_json(struct mstdnt_attachment* att, cJSON* att_json)
|
||||
int mstdnt_attachment_json(cJSON* att_json, struct mstdnt_attachment* att)
|
||||
{
|
||||
if (!att) return 1;
|
||||
|
||||
|
@ -38,7 +38,7 @@ int mstdnt_attachment_json(struct mstdnt_attachment* att, cJSON* att_json)
|
|||
{ "blurhash", &(att->blurhash), _mstdnt_val_string_call },
|
||||
};
|
||||
|
||||
for (cJSON* it = att_json; it; it = it->next)
|
||||
for (cJSON* it = att_json->child; it; it = it->next)
|
||||
_mstdnt_key_val_ref(it, refs, _mstdnt_arr_len(refs));
|
||||
|
||||
return 0;
|
||||
|
@ -74,7 +74,7 @@ void _mstdnt_val_attachments_call(cJSON* v, void* _type)
|
|||
|
||||
static int mstdnt_attachment_json_callback(cJSON* json, void* _args)
|
||||
{
|
||||
return mstdnt_attachment_result(json, _args);
|
||||
return mstdnt_attachment_json(json, _args);
|
||||
}
|
||||
|
||||
int mastodont_upload_media(mastodont_t* api,
|
||||
|
@ -94,13 +94,13 @@ int mastodont_upload_media(mastodont_t* api,
|
|||
params, _mstdnt_arr_len(params),
|
||||
CURLOPT_MIMEPOST,
|
||||
attachment,
|
||||
mstdnt_attachment_callback,
|
||||
mstdnt_attachment_json_callback,
|
||||
};
|
||||
|
||||
return mastodont_request(api, &req_args);
|
||||
}
|
||||
|
||||
void cleanup_attachments(struct mstdnt_attachment* attachment)
|
||||
void mstdnt_cleanup_attachments(struct mstdnt_attachment* attachment)
|
||||
{
|
||||
if (attachment) free(attachment);
|
||||
}
|
||||
|
|
|
@ -130,7 +130,11 @@ void mstdnt_cleanup_notifications(struct mstdnt_notification* notifs, size_t not
|
|||
|
||||
void mstdnt_cleanup_notification(struct mstdnt_notification* notif)
|
||||
{
|
||||
if (notif->account) free(notif->account);
|
||||
if (notif->account)
|
||||
{
|
||||
mstdnt_cleanup_account(notif->account);
|
||||
free(notif->account);
|
||||
}
|
||||
if (notif->status)
|
||||
{
|
||||
mstdnt_cleanup_status(notif->status);
|
||||
|
|
|
@ -487,7 +487,8 @@ int mastodont_status_emoji_react(mastodont_t* api, char* id, char* emoji,
|
|||
|
||||
void mstdnt_cleanup_status(struct mstdnt_status* status)
|
||||
{
|
||||
cleanup_attachments(status->media_attachments);
|
||||
mstdnt_cleanup_attachments(status->media_attachments);
|
||||
mstdnt_cleanup_account(&(status->account));
|
||||
cleanup_status_pleroma(&(status->pleroma));
|
||||
cleanup_emojis(status->emojis);
|
||||
if (status->reblog)
|
||||
|
|
Loading…
Reference in a new issue