parent
60ca308c7c
commit
9e27168c6e
@ -0,0 +1,53 @@
|
||||
#include "poll.h"
|
||||
|
||||
#include "model/emoji.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#define OBJ_TYPE struct status_poll_option
|
||||
struct json_object_field status_poll_option_layout[] = {
|
||||
JSON_FIELD_STRING( title, true ),
|
||||
JSON_FIELD_ARRAY_OF_INTS( votes, false ),
|
||||
JSON_FIELD_END,
|
||||
};
|
||||
#undef OBJ_TYPE
|
||||
JSON_FIELD_TYPE_OBJECT_LAYOUT_WITH_DEFAULTS( status_poll_option );
|
||||
|
||||
#define OBJ_TYPE struct status_poll
|
||||
struct json_object_field status_poll_layout[] = {
|
||||
JSON_FIELD_INTEGER( id, false ),
|
||||
JSON_FIELD_BOOL( multiple_choice, false ),
|
||||
JSON_FIELD_DATETIME( expires_at, false ),
|
||||
JSON_FIELD_BOOL( voted, false ),
|
||||
JSON_FIELD_ARRAY_OF_TYPE( options, false, status_poll_option_type ),
|
||||
JSON_FIELD_ARRAY_OF_TYPE( emoji, false, emoji_type ),
|
||||
JSON_FIELD_END,
|
||||
};
|
||||
#undef OBJ_TYPE
|
||||
JSON_FIELD_TYPE_OBJECT_LAYOUT_WITH_DEFAULTS( status_poll );
|
||||
|
||||
void status_poll_option_free( struct status_poll_option* o )
|
||||
{
|
||||
if( !o ) { return; }
|
||||
|
||||
free(o);
|
||||
}
|
||||
void status_poll_free( struct status_poll* p )
|
||||
{
|
||||
if( !p ) { return; }
|
||||
|
||||
for( int i = 0; i < p->options.count; ++i ) {
|
||||
status_poll_option_free( p->options.items[i] );
|
||||
}
|
||||
free( p->options.items );
|
||||
|
||||
for( int i = 0; i < p->emoji.count; ++i ) {
|
||||
emoji_free( p->emoji.items[i] );
|
||||
}
|
||||
free( p->emoji.items );
|
||||
|
||||
free(p);
|
||||
}
|
||||
|
@ -0,0 +1,75 @@
|
||||
#include "Poll.h"
|
||||
|
||||
#include "model/status/poll.h"
|
||||
|
||||
#include "json/layout.h"
|
||||
|
||||
extern struct json_field_type api_Emoji_type;
|
||||
|
||||
#define OBJ_TYPE struct status_poll_option
|
||||
struct json_object_field api_PollOption_layout[] = {
|
||||
JSON_FIELD_STRING( title, false ),
|
||||
{
|
||||
.key = "votes_count",
|
||||
.offset = offsetof( OBJ_TYPE, votes.count ),
|
||||
.required = true,
|
||||
.type = &json_field_integer,
|
||||
},
|
||||
JSON_FIELD_END,
|
||||
};
|
||||
#undef OBJ_TYPE
|
||||
|
||||
struct json_field_type api_PollOption_type = {
|
||||
.reader = json_field_object_type_reader,
|
||||
.writer = json_field_object_type_writer,
|
||||
.size = sizeof( struct status* ),
|
||||
.layout = api_PollOption_layout,
|
||||
.type_string = "Poll::Option",
|
||||
};
|
||||
|
||||
bool int_to_string_callback( void* field_data, bool is_read, char** res );
|
||||
|
||||
#define OBJ_TYPE struct status_poll
|
||||
struct json_object_field api_Poll_layout[] = {
|
||||
{
|
||||
.key = "id",
|
||||
.offset = offsetof( OBJ_TYPE, id ),
|
||||
.type = &json_field_callback_string,
|
||||
.string_callback = int_to_string_callback,
|
||||
},
|
||||
JSON_FIELD_DATETIME( expires_at, false ),
|
||||
JSON_FIELD_FIXED_BOOL( expired, false ),
|
||||
{
|
||||
.key = "multiple",
|
||||
.offset = offsetof( OBJ_TYPE, multiple_choice ),
|
||||
.required = true,
|
||||
.type = &json_field_bool,
|
||||
},
|
||||
JSON_FIELD_INTEGER( votes_count, true ),
|
||||
JSON_FIELD_FIXED_NULL( voters_count ),
|
||||
JSON_FIELD_BOOL( voted, true ),
|
||||
{
|
||||
.key = "options",
|
||||
.offset = offsetof( OBJ_TYPE, options ),
|
||||
.type = &json_field_array_of,
|
||||
.array_item_type = &api_PollOption_type,
|
||||
},
|
||||
{
|
||||
.key = "emojis",
|
||||
.offset = offsetof( OBJ_TYPE, emoji ),
|
||||
.required = true,
|
||||
.type = &json_field_array_of,
|
||||
.array_item_type = &api_Emoji_type,
|
||||
},
|
||||
JSON_FIELD_END,
|
||||
};
|
||||
#undef OBJ_TYPE
|
||||
|
||||
struct json_field_type api_Poll_type = {
|
||||
.reader = json_field_object_type_reader,
|
||||
.writer = json_field_object_type_writer,
|
||||
.size = sizeof( struct status* ),
|
||||
.layout = api_Poll_layout,
|
||||
.type_string = "Poll",
|
||||
};
|
||||
|
@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
struct json_field_type;
|
||||
extern struct json_field_type api_Poll_type;
|
||||
|
Loading…
Reference in new issue