@ -2,12 +2,13 @@
# include "json/json.h"
# include "json/json.h"
# include "json/layout.h"
# include "json/layout.h"
# include " format.h"
# include " util/ format.h"
# include "model/server.h"
# include "model/server.h"
# include "model/status.h"
# include "model/status.h"
# include "model/status/react.h"
# include "model/status/react.h"
# include "model/account.h"
# include "model/account.h"
# include "model/media.h"
# include "view/api/Account.h"
# include "view/api/Account.h"
@ -27,7 +28,25 @@ bool post_reposted( void* field_data, bool is_read, bool* val )
return true ;
return true ;
}
}
static bool write_in_reply_to ( struct json_writer * jw , const char * field_name , void * field_data , struct json_object_field * layout_field_data )
bool owner_favorited_callback ( void * field_data , bool is_read , bool * value )
{
struct status * s = field_data ;
if ( ! is_read ) {
for ( int i = 0 ; i < s - > likes . count ; + + i ) {
if ( s - > likes . items [ i ] = = owner_account_id ) {
* value = true ;
return true ;
}
}
* value = false ;
return true ;
}
return false ;
}
static bool write_in_reply_to ( struct json_writer * jw , const char * field_name , void * field_data , struct json_reflection * layout_field_data , int offset )
{
{
struct status * s = field_data ;
struct status * s = field_data ;
struct status * in_reply_to = status_from_id ( s - > in_reply_to ) ;
struct status * in_reply_to = status_from_id ( s - > in_reply_to ) ;
@ -57,7 +76,7 @@ static struct json_field_type in_reply_to = {
} ;
} ;
static bool write_status_reference ( struct json_writer * jw , const char * field_name , void * field_data , struct json_ object_field* layout_field_data )
static bool write_status_reference ( 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 ) ;
json_write_field_name ( jw , field_name ) ;
int id = * ( int * ) field_data ;
int id = * ( int * ) field_data ;
@ -90,12 +109,14 @@ static struct json_object_field MediaAttachment_Pleroma_layout[] = {
JSON_FIELD_FIXED_STRING ( mime_type , " image/png " , true ) ,
JSON_FIELD_FIXED_STRING ( mime_type , " image/png " , true ) ,
JSON_FIELD_END
JSON_FIELD_END
} ;
} ;
# define OBJ_TYPE struct media
static struct json_object_field MediaAttachment_layout [ ] = {
static struct json_object_field MediaAttachment_layout [ ] = {
JSON_FIELD_FIXED_STRING ( blurhash , " eRH.A}xs0Kxv00xYR,R+t5R+9Gt6xaNG%%2-;xaM{NGRjD%%Rjs:xaxu " , true ) ,
JSON_FIELD_FIXED_STRING ( blurhash , " eRH.A}xs0Kxv00xYR,R+t5R+9Gt6xaNG%%2-;xaM{NGRjD%%Rjs:xaxu " , true ) ,
JSON_FIELD_FIXED_NULL ( description ) ,
JSON_FIELD_FIXED_NULL ( description ) ,
{
{
. key = " id " ,
. key = " id " ,
. offset = 0 ,
. offset = offsetof ( OBJ_TYPE , remote_url ) ,
. type = & json_field_string ,
. type = & json_field_string ,
} ,
} ,
{
{
@ -106,32 +127,33 @@ static struct json_object_field MediaAttachment_layout[] = {
} ,
} ,
{
{
. key = " preview_url " ,
. key = " preview_url " ,
. offset = 0 ,
. offset = offsetof ( OBJ_TYPE , preview_url ) ,
. type = & json_field_string ,
. type = & json_field_string ,
} ,
} ,
{
{
. key = " remote_url " ,
. key = " remote_url " ,
. offset = 0 ,
. offset = offsetof ( OBJ_TYPE , remote_url ) ,
. type = & json_field_string ,
. type = & json_field_string ,
} ,
} ,
{
{
. key = " text_url " ,
. key = " text_url " ,
. offset = 0 ,
. offset = offsetof ( OBJ_TYPE , remote_url ) ,
. type = & json_field_string ,
. type = & json_field_string ,
} ,
} ,
JSON_FIELD_FIXED_STRING ( type , " image " , true ) ,
JSON_FIELD_FIXED_STRING ( type , " image " , true ) ,
{
{
. key = " url " ,
. key = " url " ,
. offset = 0 ,
. offset = offsetof ( OBJ_TYPE , remote_url ) ,
. type = & json_field_string ,
. type = & json_field_string ,
} ,
} ,
JSON_FIELD_END ,
JSON_FIELD_END ,
} ;
} ;
# undef OBJ_TYPE
static struct json_field_type MediaAttachment_type = {
static struct json_field_type MediaAttachment_type = {
. layout = MediaAttachment_layout ,
. layout = MediaAttachment_layout ,
. reader = json_field_object_ composit e_reader,
. reader = json_field_object_ typ e_reader,
. writer = json_field_object_ composit e_writer,
. writer = json_field_object_ typ e_writer,
. size = sizeof ( char * ) ,
. size = sizeof ( char * ) ,
} ;
} ;
@ -171,7 +193,7 @@ static struct json_object_field api_Mention_layout[] = {
} ;
} ;
# undef OBJ_TYPE
# undef OBJ_TYPE
static bool Mention_from_id_writer ( struct json_writer * jw , const char * field_name , void * field_data , struct json_ object_field* layout_field_data )
static bool Mention_from_id_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 ) ;
json_write_field_name ( jw , field_name ) ;
int id = * ( int * ) field_data ;
int id = * ( int * ) field_data ;
@ -246,12 +268,14 @@ bool context_url_callback( void* field_data, bool is_read, char** res )
struct status * s = field_data ;
struct status * s = field_data ;
if ( ! is_read ) {
if ( ! is_read ) {
* res = aformat ( " https://%s/contexts/%d " , g_server - > domain , s - > root_status_id ) ;
* res = aformat ( " https://%s/contexts/%d " , g_server - > domain , s - > root_status_id ) ;
return true ;
}
}
return false ;
}
}
bool is_local_callback ( void * field_data , bool is_read , bool * val )
bool is_local_callback ( void * field_data , bool is_read , bool * val )
{
{
struct status * s = field_data ;
struct status * s = field_data ;
* val = fals e;
* val = ! s - > remot e;
return true ;
return true ;
}
}
@ -353,8 +377,8 @@ struct json_object_field api_Status_layout[] = {
. key = " favourited " ,
. key = " favourited " ,
. required = true ,
. required = true ,
. offset = 0 ,
. offset = 0 ,
. type = & json_field_ fixed_ bool,
. type = & json_field_ bool_callback ,
. fixed_bool = false ,
. bool_callback = owner_favorited_callback ,
} ,
} ,
{
{
. key = " favourites_count " ,
. key = " favourites_count " ,
@ -378,7 +402,7 @@ struct json_object_field api_Status_layout[] = {
JSON_FIELD_FIXED_NULL ( language ) ,
JSON_FIELD_FIXED_NULL ( language ) ,
{
{
. key = " media_attachments " ,
. key = " media_attachments " ,
. offset = offsetof ( OBJ_TYPE , media ) ,
. offset = offsetof ( OBJ_TYPE , media 2 ) ,
. type = & json_field_array_of ,
. type = & json_field_array_of ,
. array_item_type = & MediaAttachment_type ,
. array_item_type = & MediaAttachment_type ,
} ,
} ,
@ -433,7 +457,7 @@ struct json_object_field api_Status_layout[] = {
} ;
} ;
# undef OBJ_TYPE
# undef OBJ_TYPE
static bool api_Status_writer ( struct json_writer * jw , const char * field_name , void * field_data , struct json_ object_field* layout_field_data )
static bool api_Status_writer ( struct json_writer * jw , const char * field_name , void * field_data , struct json_ reflection* layout_field_data , int offset )
{
{
int status_id = * ( int * ) field_data ;
int status_id = * ( int * ) field_data ;