From 726db042506860adb4f2f19980871183940539c7 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Sun, 3 Dec 2023 19:16:23 -0600 Subject: [PATCH] Change notifications for removing followers, start code for modifying account parameters from web gui --- src/controller/api/accounts.c | 33 +++++++++++++++++++++++++++++---- src/model/account.c | 20 ++++++++++++-------- 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/src/controller/api/accounts.c b/src/controller/api/accounts.c index 5ac16a6..b3c6e14 100644 --- a/src/controller/api/accounts.c +++ b/src/controller/api/accounts.c @@ -170,14 +170,38 @@ static bool handle_relationships( struct http_request* req ) return true; } +// Route: /api/v1/accounts/update_credentials +bool route_api_account_update_credentials( struct http_request* req ) +{ + if( !http_request_route_method( req, "PATCH" ) ) { + return false; + } + + FILE* f = http_request_get_request_data( req ); + + printf( "Request body:\n" ); + int c; + while( (c=fgetc(f)) != EOF ) { + fputc(c,stdout); + } + printf( "\nEnd of body (last=%d)\n", c ); + + struct account* owner = account_from_id(owner_account_id); + bool res = handle_mastodon_api_show_account( req, owner ); + account_free(owner); + return res; +} + // Route: /api/v1/accounts/ bool route_api_account( struct http_request* req ) { - if( http_request_route_term( req, "verify_credentials" ) || http_request_route_term( req, "update_credentials" ) ) { - struct account* owner = account_from_id(0); + if( http_request_route_term( req, "verify_credentials" ) ) { + struct account* owner = account_from_id(owner_account_id); bool res = handle_mastodon_api_show_account( req, owner ); account_free(owner); return res; + } else if( http_request_route_term( req, "update_credentials" ) ) { + return route_api_account_update_credentials(req); } else if( http_request_route( req, "relationships?" ) ) { return handle_relationships(req); } else if( http_request_route( req, "statuses" ) ) { @@ -191,16 +215,17 @@ bool route_api_account( struct http_request* req ) return res; } + // Route: /api/v1/accounts/%d{id} int id = 0; if( !get_local_account_id( req, &id ) ) { return false; } + // Make sure the account exists before allowing anything to be done with it struct account* a = account_from_id( id ); if( !a ) { return false; } - // Route: /api/v1/accounts/%d{id} - + // Account-specific routes if( http_request_route( req, "statuses" ) ) { bool res = handle_timeline( req, id ); account_free(a); diff --git a/src/model/account.c b/src/model/account.c index 5298f7f..6326121 100644 --- a/src/model/account.c +++ b/src/model/account.c @@ -375,6 +375,8 @@ struct account* account_from_uri_or_fetch( const char* uri ) } void account_index_webfinger( struct account* a ) { + mkdir( "data/accounts/webfinger", 0750 ); + char webfinger_name[512]; snprintf( webfinger_name, 512, "%s@%s", a->handle, a->server ); hash_index_set( "data/accounts/webfinger", webfinger_name, a->id ); @@ -747,14 +749,16 @@ void account_remove_follower( struct account* a, struct account* follower ) follower->following_count = ffdb_trie_count(filename); // create a notification for unfollow - struct notification* note = notification_new(); - note->debug = 5; - note->type = nt_unfollow; - note->account_id = -1; - note->ref_account_id = follower->id; - note->created_at = time(NULL); - notification_save( note ); - notification_free( note ); + if( a->id == owner_account_id ) { + struct notification* note = notification_new(); + note->debug = 5; + note->type = nt_unfollow; + note->account_id = -1; + note->ref_account_id = follower->id; + note->created_at = time(NULL); + notification_save( note ); + notification_free( note ); + } } struct int_array {