Connect up controller to more timelines, remove write_json_escaped (replace by json_write_string), add back in date to deferred inbox

master
teknomunk 1 year ago
parent a4e7e5a29e
commit 5e0a815d3a

@ -1,32 +1,13 @@
#include "inbox.h"
#include "http_server/http_request.h"
#include "json/json.h"
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <time.h>
void write_json_escaped( FILE* f, const char* str )
{
while( *str ) {
switch( *str ) {
case '\"':
fprintf( f, "\\\"" );
break;
case '\n':
fprintf( f, "\\\n" );
break;
case '\t':
fprintf( f, "\\\t" );
break;
default:
fputc( *str, f );
}
++str;
}
}
static void io_copy( FILE* in, FILE* out )
{
char buffer[512];

@ -16,16 +16,22 @@
#include "api/status.h"
#include "api/notice.h"
bool handle_timeline( struct http_request* req, const char* which )
enum timeline_ids {
tli_owner = 0,
tli_public = 1,
tli_home = 2,
};
bool handle_timeline( struct http_request* req, int timeline_id )
{
// "GET /api/v1/timelines/home?with_muted=true&limit=31"
bool with_muted = false;
unsigned int limit = 100;
struct timeline* tl = timeline_from_id( 0 );
struct timeline* tl = timeline_from_id( timeline_id );
struct status* ss[32];
int count = timeline_load_statuses( tl, 0, 32, ss );
printf( "count=%d\n", count );
show_statuses( req, ss, count );
for( int i = 0; i < count; ++i ) {
@ -68,8 +74,7 @@ bool route_mastodon_api( struct http_request* req )
}
if( http_request_route( req, "timelines/public" ) ) {
show_statuses( req, NULL, 0 );
return true;
return handle_timeline( req, tli_public );
}
//*
@ -106,28 +111,27 @@ bool route_mastodon_api( struct http_request* req )
}
}
if( http_request_route( req, "timelines/home" ) ) {
return handle_timeline( req, "home" );
if( http_request_route( req, "timelines/" ) ) {
if( http_request_route( req, "home" ) ) {
return handle_timeline( req, tli_home );
} else if( http_request_route( req, "public" ) ) {
return handle_timeline( req, tli_public );
}
} else if( http_request_route( req, "accounts/" ) ) {
if( http_request_route( req, "verify_credentials" ) ) {
return true;
} else if( http_request_route( req, "statuses" ) ) {
show_statuses( req, NULL, 0 );
return true;
return handle_timeline( req, tli_owner );
}
char* id_str = http_request_route_get_dir_or_file(req);
int id = 0;
if( http_request_route_id( req, &id ) ) {
struct account* a = account_from_id( id );
if( !a ) { return false; }
if( http_request_route( req, "statuses" ) ) {
printf( "TODO: statuses\n" );
show_statuses( req, NULL, 0 );
return true;
return handle_timeline( req, id );
} else {
return handle_mastodon_api_show_account( req, a );
}

@ -1 +1 @@
Subproject commit 3db4755b6c9544ea4c37ac33665eeba278e4d67e
Subproject commit 6491d6009cf91ac44a1b0f919f6ff8342e296647

@ -1,5 +1,6 @@
{
"signature": "%( write_json_escaped( f, signature ); )",
"signature": %( json_write_string( f, signature ); ),
"date": %( json_write_string( f, date ); )",
"when": "%llu{time_ns}",
"body": %( io_copy( body, f ); )
}

Loading…
Cancel
Save