Change notifications for removing followers, start code for modifying account parameters from web gui

master
teknomunk 6 months ago
parent eec6d2b80a
commit 726db04250

@ -170,14 +170,38 @@ static bool handle_relationships( struct http_request* req )
return true; 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/ // Route: /api/v1/accounts/
bool route_api_account( struct http_request* req ) bool route_api_account( struct http_request* req )
{ {
if( http_request_route_term( req, "verify_credentials" ) || http_request_route_term( req, "update_credentials" ) ) { if( http_request_route_term( req, "verify_credentials" ) ) {
struct account* owner = account_from_id(0); struct account* owner = account_from_id(owner_account_id);
bool res = handle_mastodon_api_show_account( req, owner ); bool res = handle_mastodon_api_show_account( req, owner );
account_free(owner); account_free(owner);
return res; 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?" ) ) { } else if( http_request_route( req, "relationships?" ) ) {
return handle_relationships(req); return handle_relationships(req);
} else if( http_request_route( req, "statuses" ) ) { } else if( http_request_route( req, "statuses" ) ) {
@ -191,16 +215,17 @@ bool route_api_account( struct http_request* req )
return res; return res;
} }
// Route: /api/v1/accounts/%d{id}
int id = 0; int id = 0;
if( !get_local_account_id( req, &id ) ) { if( !get_local_account_id( req, &id ) ) {
return false; return false;
} }
// Make sure the account exists before allowing anything to be done with it
struct account* a = account_from_id( id ); struct account* a = account_from_id( id );
if( !a ) { return false; } if( !a ) { return false; }
// Route: /api/v1/accounts/%d{id} // Account-specific routes
if( http_request_route( req, "statuses" ) ) { if( http_request_route( req, "statuses" ) ) {
bool res = handle_timeline( req, id ); bool res = handle_timeline( req, id );
account_free(a); account_free(a);

@ -375,6 +375,8 @@ struct account* account_from_uri_or_fetch( const char* uri )
} }
void account_index_webfinger( struct account* a ) void account_index_webfinger( struct account* a )
{ {
mkdir( "data/accounts/webfinger", 0750 );
char webfinger_name[512]; char webfinger_name[512];
snprintf( webfinger_name, 512, "%s@%s", a->handle, a->server ); snprintf( webfinger_name, 512, "%s@%s", a->handle, a->server );
hash_index_set( "data/accounts/webfinger", webfinger_name, a->id ); 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); follower->following_count = ffdb_trie_count(filename);
// create a notification for unfollow // create a notification for unfollow
struct notification* note = notification_new(); if( a->id == owner_account_id ) {
note->debug = 5; struct notification* note = notification_new();
note->type = nt_unfollow; note->debug = 5;
note->account_id = -1; note->type = nt_unfollow;
note->ref_account_id = follower->id; note->account_id = -1;
note->created_at = time(NULL); note->ref_account_id = follower->id;
notification_save( note ); note->created_at = time(NULL);
notification_free( note ); notification_save( note );
notification_free( note );
}
} }
struct int_array { struct int_array {

Loading…
Cancel
Save