From 4e01325e4e3316886f2ee38619a3913b16e4b375 Mon Sep 17 00:00:00 2001 From: nekobit Date: Sun, 15 May 2022 05:29:04 +0000 Subject: [PATCH] Fix attachments FossilOrigin-Name: 027a89e3e81deed48819357242b7b10d985dd12464adc1f6a573de14233baf71 --- include/mastodont_account.h | 7 +++++++ src/account.c | 11 +++++++++++ src/attachment.c | 10 +++++----- src/notification.c | 6 +++++- src/status.c | 3 ++- 5 files changed, 30 insertions(+), 7 deletions(-) diff --git a/include/mastodont_account.h b/include/mastodont_account.h index bbea237..459e189 100644 --- a/include/mastodont_account.h +++ b/include/mastodont_account.h @@ -18,6 +18,7 @@ #include "mastodont_types.h" #include "mastodont_fetch.h" #include "mastodont_relationship.h" +#include "mastodont_emoji.h" #include #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 */ diff --git a/src/account.c b/src/account.c index 38a91e5..f650fab 100644 --- a/src/account.c +++ b/src/account.c @@ -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); +} diff --git a/src/attachment.c b/src/attachment.c index 96d3b9d..ef7817e 100644 --- a/src/attachment.c +++ b/src/attachment.c @@ -20,7 +20,7 @@ #include #include -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); } diff --git a/src/notification.c b/src/notification.c index 67e7d2c..73d44c1 100644 --- a/src/notification.c +++ b/src/notification.c @@ -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); diff --git a/src/status.c b/src/status.c index f06a141..709c16c 100644 --- a/src/status.c +++ b/src/status.c @@ -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)