Emoji reacts

FossilOrigin-Name: 8646e9448b6e79884d9c713c06907b9d9baf2d1402630d6ae25ea102783f53b3
This commit is contained in:
me@ow.nekobit.net 2022-03-01 04:30:34 +00:00
parent 2f716a7d19
commit 4e2ae058e6
9 changed files with 92 additions and 19 deletions

View file

@ -18,12 +18,6 @@
#include "mastodont_types.h"
/* Status: Complete, not implemented */
struct _mstdnt_attachment_args
{
struct mstdnt_attachment** attachments;
size_t* size;
};
enum mstdnt_attachment_type
{
MSTDNT_ATTACHMENT_UNKNOWN,

View file

@ -29,7 +29,7 @@ struct mstdnt_emoji
char* category;
};
struct mstdnt_emoji_react
struct mstdnt_emoji_reaction
{
char* name;
size_t count;
@ -37,4 +37,6 @@ struct mstdnt_emoji_react
/* TODO Accounts */
};
void _mstdnt_val_emoji_reactions_call(cJSON* v, void* _type);
#endif /* MASTODONT_EMOJI */

View file

@ -18,6 +18,12 @@
#include "mastodont_types.h"
#include "mastodont_fetch.h"
struct _mstdnt_generic_args
{
void* arg;
size_t* size;
};
struct _mstdnt_val_ref
{
const char* key;

View file

@ -18,13 +18,15 @@
#include <mastodont_types.h>
#include <mastodont_emoji.h>
struct mstdnt_pleroma
struct mstdnt_status_pleroma
{
/* content */
int conversation_id;
int direct_conversation_id;
char* expires_at;
char* in_reply_to_account_acct;
struct mstdnt_emoji_reaction* emoji_reactions;
size_t emoji_reactions_len;
mstdnt_bool local;
mstdnt_bool parent_visible;
char* pinned_at;
@ -32,7 +34,7 @@ struct mstdnt_pleroma
int thread_muted;
};
int mstdnt_load_pleroma_from_json(struct mstdnt_pleroma* pleroma, cJSON* js);
void _mstdnt_val_pleroma_call(cJSON* v, void* _type);
int mstdnt_load_status_pleroma_from_json(struct mstdnt_status_pleroma* pleroma, cJSON* js);
void _mstdnt_val_status_pleroma_call(cJSON* v, void* _type);
#endif /* MASTODONT_PLEROMA */

View file

@ -52,7 +52,7 @@ struct mstdnt_status
struct mstdnt_attachment* media_attachments;
size_t media_attachments_len;
struct mstdnt_application application;
struct mstdnt_pleroma pleroma;
struct mstdnt_status_pleroma pleroma;
/* Rendering attributes */
struct mstdnt_mention* mentions;

View file

@ -39,8 +39,8 @@ static void load_attachment_from_json(struct mstdnt_attachment* att, cJSON* att_
void _mstdnt_val_attachments_call(cJSON* v, void* _type)
{
struct _mstdnt_attachment_args* args = _type;
struct mstdnt_attachment** attachments = args->attachments;
struct _mstdnt_generic_args* args = _type;
struct mstdnt_attachment** attachments = args->arg;
cJSON* v_array = v->child;
cJSON* att = NULL;

62
src/emoji.c Normal file
View file

@ -0,0 +1,62 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <mastodont_json_helper.h>
#include <mastodont_emoji.h>
static void load_emoji_reacts_from_json(struct mstdnt_emoji_reaction* emo, cJSON* emo_json)
{
cJSON* it;
struct _mstdnt_val_ref refs[] = {
{ "name", &(emo->name), _mstdnt_val_string_call },
{ "count", &(emo->count), _mstdnt_val_uint_call },
{ "me", &(emo->me), _mstdnt_val_bool_call },
};
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)
{
struct _mstdnt_generic_args* args = _type;
struct mstdnt_emoji_reaction** 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 = malloc(sizeof(struct mstdnt_emoji_reaction) * size);
if (*emos == NULL)
return;
cJSON* it;
int i;
for (it = v_array, i = 0; it; (++i, it = it->next))
{
load_emoji_reacts_from_json((*emos) + i, it->child);
}
}

View file

@ -16,14 +16,21 @@
#include <mastodont_json_helper.h>
#include <mastodont_pleroma.h>
int mstdnt_load_pleroma_from_json(struct mstdnt_pleroma* pleroma, cJSON* js)
int mstdnt_load_status_pleroma_from_json(struct mstdnt_status_pleroma* pleroma, cJSON* js)
{
cJSON* v;
struct _mstdnt_generic_args emo_args = {
&(pleroma->emoji_reactions),
&(pleroma->emoji_reactions_len),
};
struct _mstdnt_val_ref refs[] = {
{ "conversation_id", &(pleroma->conversation_id), _mstdnt_val_sint_call },
{ "direct_conversation_id", &(pleroma->direct_conversation_id), _mstdnt_val_sint_call },
{ "expires_at", &(pleroma->expires_at), _mstdnt_val_string_call },
{ "in_reply_to_account_acct", &(pleroma->in_reply_to_account_acct), _mstdnt_val_string_call },
{ "emoji_reactions", &emo_args, _mstdnt_val_emoji_reactions_call },
{ "pinned_at", &(pleroma->pinned_at), _mstdnt_val_string_call },
{ "thread_muted", &(pleroma->thread_muted), _mstdnt_val_sint_call },
};
@ -34,9 +41,9 @@ int mstdnt_load_pleroma_from_json(struct mstdnt_pleroma* pleroma, cJSON* js)
}
}
void _mstdnt_val_pleroma_call(cJSON* v, void* _type)
void _mstdnt_val_status_pleroma_call(cJSON* v, void* _type)
{
struct mstdnt_pleroma* type = _type;
struct mstdnt_status_pleroma* type = _type;
mstdnt_load_pleroma_from_json(type, v->child);
mstdnt_load_status_pleroma_from_json(type, v->child);
}

View file

@ -25,7 +25,7 @@ int mstdnt_load_status_from_json(struct mstdnt_status* status, cJSON* js)
{
cJSON* v;
struct _mstdnt_attachment_args att_args = {
struct _mstdnt_generic_args att_args = {
&(status->media_attachments),
&(status->media_attachments_len),
};
@ -51,7 +51,7 @@ int mstdnt_load_status_from_json(struct mstdnt_status* status, cJSON* js)
{ "favourites_count", &(status->favourites_count), _mstdnt_val_uint_call },
{ "replies_count", &(status->replies_count), _mstdnt_val_uint_call },
{ "media_attachments", &att_args, _mstdnt_val_attachments_call },
{ "pleroma", &(status->pleroma), _mstdnt_val_pleroma_call }
{ "pleroma", &(status->pleroma), _mstdnt_val_status_pleroma_call }
};
for (v = js; v; v = v->next)