|
|
|
@ -55,6 +55,7 @@ static struct json_field_type string_pair_type = {
|
|
|
|
|
#define OBJ_TYPE struct account
|
|
|
|
|
static struct json_object_field account_layout[] = {
|
|
|
|
|
JSON_FIELD_STRING( handle, true ),
|
|
|
|
|
JSON_FIELD_INTEGER( replaced_by, false ),
|
|
|
|
|
JSON_FIELD_BOOL( local, false ),
|
|
|
|
|
JSON_FIELD_BOOL( defunct, false ),
|
|
|
|
|
JSON_FIELD_STRING( server, true ),
|
|
|
|
@ -158,8 +159,13 @@ void account_reindex()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct account* account_from_id( int id )
|
|
|
|
|
static struct account* account_load_from_id( int id, int recurse_limit )
|
|
|
|
|
{
|
|
|
|
|
if( recurse_limit <= 0 ) {
|
|
|
|
|
printf( "Recursion safetly limit hit while loading account %d\n", id );
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch( id ) {
|
|
|
|
|
case -1:
|
|
|
|
|
case system_account_id:
|
|
|
|
@ -177,6 +183,11 @@ struct account* account_from_id( int id )
|
|
|
|
|
account_free(a);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
if( a->replaced_by && a->replaced_by != a->id ) {
|
|
|
|
|
int new_id = a->replaced_by;
|
|
|
|
|
account_free(a);
|
|
|
|
|
return account_load_from_id( new_id, recurse_limit - 1 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( !a->banner ) {
|
|
|
|
|
a->banner = aformat( "https://%s/server/default-banner.blob", g_server->domain );
|
|
|
|
@ -189,6 +200,11 @@ struct account* account_from_id( int id )
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct account* account_from_id( int id )
|
|
|
|
|
{
|
|
|
|
|
return account_load_from_id( id, 10 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool index_uri_to_account_id( const char* uri, int account_id )
|
|
|
|
|
{
|
|
|
|
|
return hash_index_set( "data/accounts/uri_index/", uri, account_id );
|
|
|
|
@ -223,7 +239,7 @@ struct account* account_from_uri( const char* uri )
|
|
|
|
|
|
|
|
|
|
int account_id = lookup_account_id_from_uri( uri );
|
|
|
|
|
if( account_id == -1 ) {
|
|
|
|
|
//printf( "Failed to lookup local account id for %s\n", uri );
|
|
|
|
|
printf( "Failed to lookup local account id for %s\n", uri );
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -231,6 +247,7 @@ struct account* account_from_uri( const char* uri )
|
|
|
|
|
|
|
|
|
|
// Only return non-stub accounts here. This will force a refetch attempt
|
|
|
|
|
if( a && a->stub ) {
|
|
|
|
|
printf( "This account is a stub\n" );
|
|
|
|
|
account_free(a);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
@ -503,9 +520,50 @@ void account_list_following( struct account* a, int offset, int limit, void* id_
|
|
|
|
|
char filename[512];
|
|
|
|
|
account_list( format( filename, sizeof(filename), "data/accounts/%d/following", a->id ), offset, limit, id_array );
|
|
|
|
|
}
|
|
|
|
|
void account_move( struct account* a, const char* new_uri )
|
|
|
|
|
void account_move( struct account* old_account, const char* new_uri )
|
|
|
|
|
{
|
|
|
|
|
printf( "TODO: implement account move\n" );
|
|
|
|
|
struct account* new_account = account_from_uri_or_fetch(new_uri);
|
|
|
|
|
if( !new_account ) {
|
|
|
|
|
printf( "! Failed to move account %s (%d) to %s\n", old_account->account_url, old_account->id, new_uri );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update Followers list
|
|
|
|
|
struct {
|
|
|
|
|
int* items;
|
|
|
|
|
int count;
|
|
|
|
|
} existing;
|
|
|
|
|
account_list_followers( old_account, 0, INT_MAX, &existing );
|
|
|
|
|
for( int i = 0; i < existing.count; ++i ) {
|
|
|
|
|
struct account* follower = account_from_id(existing.items[i]);
|
|
|
|
|
if( !follower ) { continue; }
|
|
|
|
|
|
|
|
|
|
account_add_follower( new_account, follower );
|
|
|
|
|
account_remove_follower( old_account, follower );
|
|
|
|
|
account_free(follower);
|
|
|
|
|
}
|
|
|
|
|
existing.count = 0;
|
|
|
|
|
|
|
|
|
|
// Update following list
|
|
|
|
|
account_list_following( old_account, 0, INT_MAX, &existing );
|
|
|
|
|
for( int i = 0; i < existing.count; ++i ) {
|
|
|
|
|
struct account* following = account_from_id(existing.items[i]);
|
|
|
|
|
|
|
|
|
|
account_add_follower( following, new_account );
|
|
|
|
|
account_remove_follower( following, old_account );
|
|
|
|
|
account_free(following);
|
|
|
|
|
}
|
|
|
|
|
free(existing.items);
|
|
|
|
|
|
|
|
|
|
old_account->replaced_by = new_account->id;
|
|
|
|
|
account_save(old_account);
|
|
|
|
|
|
|
|
|
|
struct notification* note = notification_new();
|
|
|
|
|
note->type = nt_move;
|
|
|
|
|
note->account_id = old_account->id;
|
|
|
|
|
note->ref_account_id = new_account->id;
|
|
|
|
|
notification_save(note);
|
|
|
|
|
notification_free(note);
|
|
|
|
|
}
|
|
|
|
|
bool account_does_follow( struct account* a, int account_id )
|
|
|
|
|
{
|
|
|
|
|