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.

69 lines
1.9 KiB
C

#include "Relationship.h"
#include "json/json.h"
#include "json/layout.h"
#include "util/format.h"
#include "model/account.h"
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
#define OBJ_TYPE struct Relationship
static struct json_object_field Relationship_layout[] = {
JSON_FIELD_STRING( id, true ),
JSON_FIELD_BOOL( following, true ),
JSON_FIELD_BOOL( showing_reblogs, true ),
JSON_FIELD_BOOL( notifying, true ),
JSON_FIELD_BOOL( followed_by, true ),
JSON_FIELD_BOOL( blocking, true ),
JSON_FIELD_BOOL( blocked_by, true ),
JSON_FIELD_BOOL( muting, true ),
JSON_FIELD_BOOL( muting_notifications, true ),
JSON_FIELD_BOOL( requested, true ),
JSON_FIELD_BOOL( domain_blocking, true ),
JSON_FIELD_BOOL( endorsed, true ),
JSON_FIELD_STRING( note, true ),
JSON_FIELD_END,
};
#undef OBJ_TYPE
void api_Relationship_init( struct Relationship* r, struct account* a, struct account* rel )
{
memset( r, 0, sizeof(*r) );
r->id = aformat( "%018u",rel->id );
r->followed_by = account_does_follow( rel, a->id );
r->following = account_does_follow( a, rel->id );
}
void api_Relationship_write( struct account* a, struct account* rel, FILE* f, int indent )
{
struct Relationship r;
api_Relationship_init( &r, a, rel );
struct json_writer jw = {
.f = f,
.indentation = "\t",
.indent = indent,
};
json_write_pretty_object_layout( &jw, Relationship_layout, &r );
free(r.id);
}
static bool api_Relationship_to_owner_writer( struct json_writer* jw, const char* field_name, void* field_data, struct json_reflection* layout_field_data, int offset )
{
json_write_field_name( jw, field_name );
struct account* owner_account = account_from_id( owner_account_id );
api_Relationship_write( field_data, owner_account, jw->f, jw->indent );
account_free(owner_account);
return true;
}
struct json_field_type api_Relationship_to_owner = {
.writer = api_Relationship_to_owner_writer,
};