Change ap_object.first to a ap_object_ptr_or_ref to handle when the first object is not a reference, correct page limit in /outbox, swap out ap_activity for ap_object in src/model/account.c

master
teknomunk 1 year ago
parent 80e3284bf4
commit b6d0d4686d

@ -66,6 +66,7 @@ bool route_ap_outbox( struct http_request* req )
if( !page_str || (1 != sscanf(page_str,"%d",&page) ) || page < 0 ) { goto failed; }
struct ap_object* outbox_page = account_ap_outbox_page( owner_account, page );
if( !outbox_page ) { return false; }
http_request_send_headers( req, 200, "application/ld+json", true );
FILE* f = http_request_get_response_body( req );

@ -254,7 +254,8 @@ struct ap_object* account_ap_outbox( struct account* a )
outbox->type = apot_ordered_collection;
outbox->published = time(NULL);
outbox->id = aformat( "https://%s/outbox", g_server_name );
outbox->first = aformat( "https://%s/outbox/page-0", g_server_name );
outbox->first.tag = apaot_ref;
outbox->first.ref = aformat( "https://%s/outbox/page-0", g_server_name );
char buffer[512];
outbox->total_items = ffdb_trie_count( format( buffer, 512, "data/accounts/%d/timeline", a->id ) );
@ -265,7 +266,7 @@ struct ap_object* account_ap_outbox_page( struct account* a, int page )
enum { items_per_page = 10 };
char buffer[512];
int total_items = ffdb_trie_count( format( buffer, 512, "data/accounts/%d/timeline", a->id ) );
int page_count = ( total_items + items_per_page - 1 ) - items_per_page;
int page_count = ( total_items + items_per_page - 1 ) / items_per_page;
if( page >= page_count ) { return NULL; }
@ -285,6 +286,8 @@ struct ap_object* account_ap_outbox_page( struct account* a, int page )
int activity_id = 0;
if( 1 == sscanf( values.items[i], "%d", &id ) ) {
struct status* s = status_from_id(id);
if( !s ) { goto include_tombstone; }
activity_id = s->activity_id;
if( s->activity_id == 0 ) {
goto include_tombstone;
@ -335,12 +338,12 @@ struct ap_object* account_ap_outbox_page( struct account* a, int page )
return outbox;
}
struct ap_activity* account_activity_pub( struct account* a )
struct ap_object* account_activity_pub( struct account* a )
{
return account_ap_actor(a);
}
bool account_sync_from_activity( struct account* a, struct ap_activity* act )
bool account_sync_from_activity( struct account* a, struct ap_object* act )
{
for( int i = 0; i < a->aliases.count; ++i ) {
free( a->aliases.items[i] );
@ -623,8 +626,8 @@ void account_follow( struct account* a, struct account* to_follow )
}
void account_create( struct account* a, struct status* s )
{
struct ap_activity* note = ap_activity_create_note(s);
struct ap_activity* create = ap_activity_create_Create(note);
struct ap_object* note = ap_activity_create_note(s);
struct ap_object* create = ap_activity_create_Create(note);
ap_activity_save(create);
// Link status to activity
@ -649,7 +652,7 @@ void account_create( struct account* a, struct status* s )
}
void account_announce( struct account* a, struct status* original_post, struct status* local_repost )
{
struct ap_activity* act = ap_activity_new();
struct ap_object* act = ap_activity_new();
int id = fs_list_get("data/activities/HEAD") + 1;
fs_list_set("data/activities/HEAD", id );
@ -697,7 +700,7 @@ cleanup:
ap_object_free(act);
}
void account_deliver_activity( struct account* a, struct ap_activity* act, struct outbox_envelope_list* oel )
void account_deliver_activity( struct account* a, struct ap_object* act, struct outbox_envelope_list* oel )
{
printf( "Delivering activity %s to account %s\n", act->id, a->account_url );
@ -721,7 +724,7 @@ void account_deliver_activity( struct account* a, struct ap_activity* act, struc
env->account_id = a->id;
array_append( oel, sizeof(env), &env );
}
void account_deliver_activity_to_followers( struct account* a, struct ap_activity* act, struct outbox_envelope_list* oel )
void account_deliver_activity_to_followers( struct account* a, struct ap_object* act, struct outbox_envelope_list* oel )
{
printf( "Delivering activity %s to followers of account %s\n", act->id, a->account_url );
struct {
@ -768,7 +771,7 @@ void account_unfollow( struct account* a, struct account* to_unfollow )
}
// Lookup the Activity used to federate following this account
struct ap_activity* act = ap_activity_from_local_id( atoi(res) );
struct ap_object* act = ap_activity_from_local_id( atoi(res) );
free(res);
// Federate Undo Activity

@ -184,7 +184,7 @@ void ap_activity_free_composite( struct ap_activity* act )
free( act->signature.creator );
free( act->signature.value );
free( act->first );
ap_object_ptr_or_ref_free_composite( &act->first );
free( act->next );
free( act->prev );
free( act->part_of );

@ -183,7 +183,7 @@ struct ap_object
struct ap_signature signature;
// Collection fields
char* first;
struct ap_object_ptr_or_ref first;
char* next;
char* prev;
char* part_of;

@ -188,12 +188,17 @@ struct json_object_field ap_object_layout[] = {
.tagged_item_types = signature_types
},
JSON_FIELD_STRING( first, false ),
{
.key = "first",
.offset = offsetof( OBJ_TYPE, first ),
.required = false,
.type = &ap_object_ptr_or_ref_type,
},
JSON_FIELD_STRING( next, false ),
JSON_FIELD_STRING( prev, false ),
{
.key = "partOf",
.offset = offsetof( struct ap_object, part_of ),
.offset = offsetof( OBJ_TYPE, part_of ),
.required = false,
.type = &json_field_string,
},

Loading…
Cancel
Save