|
|
|
@ -45,11 +45,13 @@ static struct json_object_field account_layout[] = {
|
|
|
|
|
{ "handle", offsetof( struct account, handle ), true, &json_field_string },
|
|
|
|
|
{ "server", offsetof( struct account, server ), true, &json_field_string },
|
|
|
|
|
{ "display_name", offsetof( struct account, display_name ), true, &json_field_string },
|
|
|
|
|
{ "avatar", offsetof( struct account, avatar.url ), true, &json_field_string },
|
|
|
|
|
{ "avatar_static", offsetof( struct account, avatar.static_url ), true, &json_field_string },
|
|
|
|
|
{ "avatar", offsetof( struct account, avatar.url ), false, &json_field_string },
|
|
|
|
|
{ "avatar_static", offsetof( struct account, avatar.static_url ), false, &json_field_string },
|
|
|
|
|
{ "account_type", offsetof( struct account, account_type ), true, &json_field_enum, account_types_enum },
|
|
|
|
|
{ "inbox", offsetof( struct account, inbox ), false, &json_field_string },
|
|
|
|
|
{ "note", offsetof( struct account, note ), false, &json_field_string },
|
|
|
|
|
{ "followers", offsetof( struct account, followers_count ), false, &json_field_integer },
|
|
|
|
|
{ "following", offsetof( struct account, following_count ), false, &json_field_integer },
|
|
|
|
|
{ "account_url", offsetof( struct account, account_url ), true, &json_field_string },
|
|
|
|
|
|
|
|
|
|
{ NULL },
|
|
|
|
@ -71,6 +73,25 @@ static struct account* new_system_account()
|
|
|
|
|
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
static bool index_uri_to_account_id( const char* uri, int account_id );
|
|
|
|
|
void account_reindex()
|
|
|
|
|
{
|
|
|
|
|
int max_account_id = fs_list_get( "data/accounts/HEAD" );
|
|
|
|
|
for( int i = 0; i < max_account_id+1; ++i ) {
|
|
|
|
|
struct account* a = account_from_id(i);
|
|
|
|
|
if( !a ) { continue; }
|
|
|
|
|
|
|
|
|
|
if( a->account_url ) {
|
|
|
|
|
index_uri_to_account_id( a->account_url, a->id );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char webfinger_name[512];
|
|
|
|
|
snprintf( webfinger_name, 512, "%s@%s", a->handle, a->server );
|
|
|
|
|
hash_index_set( "data/accounts/webfinger", webfinger_name, a->id );
|
|
|
|
|
|
|
|
|
|
account_free(a);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct account* account_from_id( int id )
|
|
|
|
|
{
|
|
|
|
@ -156,8 +177,10 @@ bool account_sync_from_acitvity_pub( unsigned int account_id )
|
|
|
|
|
a->id = account_id;
|
|
|
|
|
a->handle = strdup(ap->preferredUsername);
|
|
|
|
|
a->display_name = strdup(ap->name);
|
|
|
|
|
a->avatar.url = strdup(ap->avatar);
|
|
|
|
|
a->avatar.static_url = strdup(ap->avatar);
|
|
|
|
|
if( ap->avatar ) {
|
|
|
|
|
a->avatar.url = strdup(ap->avatar);
|
|
|
|
|
a->avatar.static_url = strdup(ap->avatar);
|
|
|
|
|
}
|
|
|
|
|
a->bot = ( ap->type != apacct_Person );
|
|
|
|
|
a->account_type = at_remote_activity_pub;
|
|
|
|
|
a->account_url = strdup(ap->url);
|
|
|
|
@ -345,6 +368,33 @@ void account_remove_follower( struct account* a, struct account* follower )
|
|
|
|
|
notification_save( note );
|
|
|
|
|
notification_free( note );
|
|
|
|
|
}
|
|
|
|
|
void account_list_followers( struct account* a, int offset, int limit, void* id_array )
|
|
|
|
|
{
|
|
|
|
|
struct int_array {
|
|
|
|
|
int* items;
|
|
|
|
|
int count;
|
|
|
|
|
} *array = id_array;
|
|
|
|
|
|
|
|
|
|
char filename[512];
|
|
|
|
|
snprintf( filename, sizeof(filename), "data/accounts/%d/followers", a->id );
|
|
|
|
|
|
|
|
|
|
struct {
|
|
|
|
|
char** items;
|
|
|
|
|
int count;
|
|
|
|
|
} keys;
|
|
|
|
|
memset( &keys, 0, sizeof(keys) );
|
|
|
|
|
|
|
|
|
|
ffdb_trie_list( filename, offset, limit, &keys, NULL );
|
|
|
|
|
|
|
|
|
|
array->items = malloc( sizeof(int) * keys.count );
|
|
|
|
|
for( int i = 0; i < keys.count; ++i ) {
|
|
|
|
|
char* str = keys.items[i];
|
|
|
|
|
array->items[i] = atoi( str );
|
|
|
|
|
free( str );
|
|
|
|
|
}
|
|
|
|
|
free(keys.items);
|
|
|
|
|
array->count = keys.count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: move to controller/view
|
|
|
|
|
void api_account_write_as_json( struct account* a, FILE* f )
|
|
|
|
|