Load pleroma object
FossilOrigin-Name: 2caf475e4fd4d139d5074026ac8181f5c4ebd0d8331d35d02b01be88e996e792
This commit is contained in:
parent
7680cfa4be
commit
2f716a7d19
|
@ -35,6 +35,7 @@ int _mstdnt_key_val_ref(cJSON* v, struct _mstdnt_val_ref* refs,
|
|||
void _mstdnt_val_string_call(cJSON* v, void* _type);
|
||||
void _mstdnt_val_bool_call(cJSON* v, void* _type);
|
||||
void _mstdnt_val_uint_call(cJSON* v, void* _type);
|
||||
void _mstdnt_val_sint_call(cJSON* v, void* _type);
|
||||
|
||||
/* DEPRECATED */
|
||||
struct _mstdnt_str_val
|
||||
|
|
|
@ -13,16 +13,26 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef MASTODONT_PLEROMA
|
||||
#ifndef MASTODONT_PLEROMA
|
||||
#define MASTODONT_PLEROMA
|
||||
#include <mastodont_types.h>
|
||||
#include <mastodont_emojis.h>
|
||||
#include <mastodont_emoji.h>
|
||||
|
||||
struct mstdnt_pleroma
|
||||
{
|
||||
/* content */
|
||||
int conversation_id;
|
||||
int direct_conversation_id;
|
||||
char* expires_at;
|
||||
char* in_reply_to_account_acct;
|
||||
mstdnt_bool local;
|
||||
mstdnt_bool parent_visible;
|
||||
char* pinned_at;
|
||||
/* spoiler text */
|
||||
int thread_muted;
|
||||
};
|
||||
|
||||
int mstdnt_load_pleroma_from_json(struct mstdnt_pleroma* pleroma, cJSON* js);
|
||||
void _mstdnt_val_pleroma_call(cJSON* v, void* _type);
|
||||
|
||||
#endif /* MASTODONT_PLEROMA */
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#ifndef MASTODONT_STATUS
|
||||
#define MASTODONT_STATUS
|
||||
#include <cjson/cJSON.h>
|
||||
#include "mastodont_pleroma.h"
|
||||
#include "mastodont_types.h"
|
||||
#include "mastodont_fetch.h"
|
||||
#include "mastodont_attachment.h"
|
||||
|
@ -25,7 +26,7 @@
|
|||
#include "mastodont_emoji.h"
|
||||
#include "mastodont_tag.h"
|
||||
#include "mastodont_account.h"
|
||||
|
||||
#include "mastodont_pleroma.h"
|
||||
/* Status: Complete, not implemented */
|
||||
|
||||
enum mstdnt_status_visibility
|
||||
|
@ -51,6 +52,7 @@ struct mstdnt_status
|
|||
struct mstdnt_attachment* media_attachments;
|
||||
size_t media_attachments_len;
|
||||
struct mstdnt_application application;
|
||||
struct mstdnt_pleroma pleroma;
|
||||
|
||||
/* Rendering attributes */
|
||||
struct mstdnt_mention* mentions;
|
||||
|
|
|
@ -75,6 +75,18 @@ void _mstdnt_val_uint_call(cJSON* v, void* _type)
|
|||
*type = v->valueint;
|
||||
}
|
||||
|
||||
|
||||
void _mstdnt_val_sint_call(cJSON* v, void* _type)
|
||||
{
|
||||
int* type = _type;
|
||||
if (!cJSON_IsNumber(v))
|
||||
{
|
||||
*type = 0;
|
||||
return;
|
||||
}
|
||||
*type = v->valueint;
|
||||
}
|
||||
|
||||
int _mstdnt_key_val_iter(cJSON* v,
|
||||
struct _mstdnt_str_val* str,
|
||||
size_t str_len,
|
||||
|
|
42
src/pleroma.c
Normal file
42
src/pleroma.c
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* 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 <mastodont_json_helper.h>
|
||||
#include <mastodont_pleroma.h>
|
||||
|
||||
int mstdnt_load_pleroma_from_json(struct mstdnt_pleroma* pleroma, cJSON* js)
|
||||
{
|
||||
cJSON* v;
|
||||
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 },
|
||||
{ "pinned_at", &(pleroma->pinned_at), _mstdnt_val_string_call },
|
||||
{ "thread_muted", &(pleroma->thread_muted), _mstdnt_val_sint_call },
|
||||
};
|
||||
|
||||
for (v = js; v; v = v->next)
|
||||
{
|
||||
_mstdnt_key_val_ref(v, refs, _mstdnt_arr_len(refs));
|
||||
}
|
||||
}
|
||||
|
||||
void _mstdnt_val_pleroma_call(cJSON* v, void* _type)
|
||||
{
|
||||
struct mstdnt_pleroma* type = _type;
|
||||
|
||||
mstdnt_load_pleroma_from_json(type, v->child);
|
||||
}
|
|
@ -19,6 +19,7 @@
|
|||
#include <mastodont_status.h>
|
||||
#include <mastodont_account.h>
|
||||
#include <mastodont_query.h>
|
||||
#include <mastodont_pleroma.h>
|
||||
|
||||
int mstdnt_load_status_from_json(struct mstdnt_status* status, cJSON* js)
|
||||
{
|
||||
|
@ -28,7 +29,7 @@ int mstdnt_load_status_from_json(struct mstdnt_status* status, cJSON* js)
|
|||
&(status->media_attachments),
|
||||
&(status->media_attachments_len),
|
||||
};
|
||||
|
||||
|
||||
struct _mstdnt_val_ref vals[] = {
|
||||
{ "id", &(status->id), _mstdnt_val_string_call },
|
||||
{ "uri", &(status->uri), _mstdnt_val_string_call },
|
||||
|
@ -50,6 +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 }
|
||||
};
|
||||
|
||||
for (v = js; v; v = v->next)
|
||||
|
|
Loading…
Reference in a new issue