Handle account moves (experimental), fix spoiler text crashing Husky

master
teknomunk 1 year ago
parent e2428eefae
commit 3aa19cde4e

@ -292,7 +292,8 @@ static bool route_move( struct ap_object* act )
// Make sure this belongs to a local account
a = account_from_uri( act->object.ref );
if( !a ) { goto discard; }
if( !a ) {
goto discard; }
// Verify the target is an existing alias
for( int i = 0; i < a->aliases.count; ++i ) {
@ -300,6 +301,13 @@ static bool route_move( struct ap_object* act )
goto is_alias;
}
}
// Actor matches object
if( 0 == strcmp( act->object.ref, act->actor ) ) {
goto is_alias;
}
printf( "%s is not an alias of %s\n", act->target, a->account_url );
goto failed;
is_alias:
account_move( a, act->target );

@ -18,6 +18,12 @@ bool route_announce( struct ap_object* act )
struct status* original_post = NULL;
struct account* owner_account = account_from_id( owner_account_id );
struct account* actor_account = account_from_uri( act->actor );
if( !actor_account ) {
printf( "%s does not have a local account\n", act->actor );
goto failed;
}
if( !account_does_follow( owner_account, actor_account->id ) ) {
// Not following, discard
printf( "%s does not follow %s\n", owner_account->handle, actor_account->account_url );
@ -72,11 +78,11 @@ cleanup:
discard:
result = true;
goto cleanup;
/*
//*
failed:
result = false;
goto cleanup;
*/
//*/
}

@ -1 +1 @@
Subproject commit 1d59e38974df4022d3d84af7ae8e765b76611461
Subproject commit d5ab61ee7297302aff9391e8809f94a949a03f3c

@ -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 )
{

@ -42,6 +42,7 @@ struct account
bool stub;
bool defunct;
time_t next_stub_recheck;
int replaced_by;
int account_type;
char* account_url;

@ -49,6 +49,9 @@ bool account_sync_from_activity_pub( unsigned int account_id )
if( !account_sync_from_activity( a, obj ) ) { goto failed; }
// If we got here, this account can't be a stub any more
a->stub = false;
account_save(a);
account_index_webfinger(a);

@ -22,6 +22,7 @@ static struct json_enum notification_type_enum[] = {
{ "block", nt_block },
{ "like", nt_like },
{ "react", nt_react },
{ "move", nt_move },
{ NULL, -1 },
};

@ -31,6 +31,7 @@ enum notification_type
nt_block = 5,
nt_like = 6,
nt_react = 7,
nt_move = 8,
};
struct notification* notification_from_id( int id );

@ -19,6 +19,7 @@ static struct json_enum type_enum[] = {
{ "mention", nt_unfollow },
{ "mention", nt_block },
{ "mention", nt_mention },
{ "move", nt_move },
{ "pleroma:emoji_reaction", nt_react },
{ NULL, 0 },

@ -521,8 +521,8 @@ struct json_object_field api_Status_layout[] = {
{
.key = "spoiler_text",
.offset = offsetof( OBJ_TYPE, spoiler_text ),
.required = false,
.allow_drop_empty = true,
.required = true,
.allow_drop_empty = false,
.type = &json_field_string,
},
JSON_FIELD_EMPTY_ARRAY( tags, true ),

Loading…
Cancel
Save