You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.2 KiB
C

#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);
}