FossilOrigin-Name: c87963a13123cd3adc3abc37e785b05d1f5354c31fce8ac577cb458c647cf6fe
This commit is contained in:
me@ow.nekobit.net 2022-04-20 14:49:19 +00:00
parent 415409a53b
commit d1623660d4
4 changed files with 67 additions and 5 deletions

View file

@ -37,8 +37,12 @@ struct mstdnt_emoji_reaction
/* TODO Accounts */
};
void load_emoji_from_json(struct mstdnt_emoji* emo, cJSON* emo_json);
void load_emoji_react_from_json(struct mstdnt_emoji_reaction* emo, cJSON* emo_json);
void _mstdnt_val_emojis_call(cJSON* v, void* _type);
void _mstdnt_val_emoji_reactions_call(cJSON* v, void* _type);
void cleanup_emoji_reaction(struct mstdnt_emoji_reaction* reactions);
void cleanup_emoji_reactions(struct mstdnt_emoji_reaction* reactions, size_t s);
void _mstdnt_val_emoji_reactions_call(cJSON* v, void* _type);
void cleanup_emojis(struct mstdnt_emoji* emo);
#endif /* MASTODONT_EMOJI */

View file

@ -50,6 +50,7 @@ struct mstdnt_status
struct mstdnt_mention* mentions;
struct mstdnt_tag* tags;
struct mstdnt_emoji* emojis;
size_t emojis_len;
/* Information attributes */
unsigned reblogs_count;

View file

@ -18,7 +18,26 @@
#include <mastodont_json_helper.h>
#include <mastodont_emoji.h>
static void load_emoji_reacts_from_json(struct mstdnt_emoji_reaction* emo, cJSON* emo_json)
void load_emoji_from_json(struct mstdnt_emoji* emo, cJSON* emo_json)
{
cJSON* it;
/* Zero out */
memset(emo, 0, sizeof(struct mstdnt_emoji));
struct _mstdnt_val_ref refs[] = {
{ "shortcode", &(emo->shortcode), _mstdnt_val_string_call },
{ "url", &(emo->url), _mstdnt_val_string_call },
{ "static_url", &(emo->static_url), _mstdnt_val_string_call },
{ "visible_in_picker", &(emo->visible_in_picker), _mstdnt_val_bool_call },
{ "category", &(emo->category), _mstdnt_val_string_call },
};
for (it = emo_json; it; it = it->next)
_mstdnt_key_val_ref(it, refs, _mstdnt_arr_len(refs));
}
void load_emoji_react_from_json(struct mstdnt_emoji_reaction* emo, cJSON* emo_json)
{
cJSON* it;
@ -32,9 +51,7 @@ static void load_emoji_reacts_from_json(struct mstdnt_emoji_reaction* emo, cJSON
};
for (it = emo_json; it; it = it->next)
{
_mstdnt_key_val_ref(it, refs, _mstdnt_arr_len(refs));
}
}
void _mstdnt_val_emoji_reactions_call(cJSON* v, void* _type)
@ -61,10 +78,38 @@ void _mstdnt_val_emoji_reactions_call(cJSON* v, void* _type)
int i;
for (it = v_array, i = 0; it; (++i, it = it->next))
{
load_emoji_reacts_from_json((*emos) + i, it->child);
load_emoji_react_from_json((*emos) + i, it->child);
}
}
void _mstdnt_val_emojis_call(cJSON* v, void* _type)
{
struct _mstdnt_generic_args* args = _type;
struct mstdnt_emoji** emos = args->arg;
cJSON* v_array = v->child;
cJSON* att = NULL;
size_t size = cJSON_GetArraySize(v);
*(args->size) = size;
/* No attachments, ignore */
if (size == 0)
{
*emos = NULL;
return;
}
*emos = calloc(1, sizeof(struct mstdnt_emoji) * size);
if (*emos == NULL)
return;
cJSON* it;
int i;
for (it = v_array, i = 0; it; (++i, it = it->next))
{
load_emoji_from_json((*emos) + i, it->child);
}
}
void cleanup_emoji_reaction(struct mstdnt_emoji_reaction* reaction)
{
/* NOP, this will be implemented soon*/
@ -79,3 +124,9 @@ void cleanup_emoji_reactions(struct mstdnt_emoji_reaction* reactions, size_t s)
cleanup_emoji_reaction(reactions + s);
free(reactions);
}
void cleanup_emojis(struct mstdnt_emoji* emo)
{
if (!emo) return;
free(emo);
}

View file

@ -56,6 +56,11 @@ int mstdnt_status_from_json(struct mstdnt_status* status, cJSON* js)
&(status->media_attachments_len),
};
struct _mstdnt_generic_args emj_args = {
&(status->emojis),
&(status->emojis_len)
};
struct _mstdnt_val_ref vals[] = {
{ "id", &(status->id), _mstdnt_val_string_call },
{ "uri", &(status->uri), _mstdnt_val_string_call },
@ -72,6 +77,7 @@ int mstdnt_status_from_json(struct mstdnt_status* status, cJSON* js)
{ "favourited", &(status->favourited), _mstdnt_val_bool_call },
{ "reblogged", &(status->reblogged), _mstdnt_val_bool_call },
{ "muted", &(status->muted), _mstdnt_val_bool_call },
{ "emojis", &emj_args, _mstdnt_val_emojis_call },
{ "bookmarked", &(status->bookmarked), _mstdnt_val_bool_call },
{ "pinned", &(status->pinned), _mstdnt_val_bool_call },
{ "reblogs_count", &(status->reblogs_count), _mstdnt_val_uint_call },