|
|
|
@ -5,11 +5,17 @@
|
|
|
|
|
#include "util/format.h"
|
|
|
|
|
|
|
|
|
|
#include "model/account.h"
|
|
|
|
|
#include "model/server.h"
|
|
|
|
|
|
|
|
|
|
#include "view/api/Relationship.h"
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
struct Account_user_data
|
|
|
|
|
{
|
|
|
|
|
bool is_tor_request;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#define OBJ_TYPE struct string_pair
|
|
|
|
|
static struct json_object_field emoji_layout[] = {
|
|
|
|
|
{
|
|
|
|
@ -129,6 +135,25 @@ bool int_to_string_callback( void* field_data, bool is_read, char** res )
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
bool account_url_string_callback( void* field_data, bool is_read, char** res )
|
|
|
|
|
{
|
|
|
|
|
struct account* a = field_data;
|
|
|
|
|
struct Account_user_data* ud = a->user;
|
|
|
|
|
if( is_read ) { return false; }
|
|
|
|
|
|
|
|
|
|
if( !ud || !ud->is_tor_request || a->id != owner_account_id ) {
|
|
|
|
|
if( !a->account_url ) {
|
|
|
|
|
* res = strdup("");
|
|
|
|
|
} else {
|
|
|
|
|
*res = safe_strdup( a->account_url );
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*res = aformat( "http://%s/owner/account", g_server->tor_hidden_service );
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct json_object_field api_Account_layout[] = {
|
|
|
|
|
{
|
|
|
|
|
.key = "acct",
|
|
|
|
@ -208,8 +233,9 @@ struct json_object_field api_Account_layout[] = {
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
.key = "url",
|
|
|
|
|
.offset = offsetof( OBJ_TYPE, account_url ),
|
|
|
|
|
.type = &json_field_string
|
|
|
|
|
//.offset = offsetof( OBJ_TYPE, account_url ),
|
|
|
|
|
.type = &json_field_callback_string,
|
|
|
|
|
.string_callback = account_url_string_callback,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
.key = "username",
|
|
|
|
@ -245,13 +271,18 @@ struct json_field_type api_Account_type = {
|
|
|
|
|
.layout = api_Account_layout,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void api_Account_write( struct account* a, FILE* f, int indent )
|
|
|
|
|
void api_Account_write( struct account* a, FILE* f, int indent, bool is_tor_request )
|
|
|
|
|
{
|
|
|
|
|
struct Account_user_data ud;
|
|
|
|
|
ud.is_tor_request = is_tor_request;
|
|
|
|
|
|
|
|
|
|
struct json_writer jw = {
|
|
|
|
|
.f = f,
|
|
|
|
|
.indentation = "\t",
|
|
|
|
|
.indent = indent,
|
|
|
|
|
.user = &ud,
|
|
|
|
|
};
|
|
|
|
|
a->user = &ud;
|
|
|
|
|
|
|
|
|
|
json_write_pretty_object_layout( &jw, api_Account_layout, a );
|
|
|
|
|
}
|
|
|
|
|