Add start of async fetch for statuses (stub statuses to be handled later), start of Announce (repost) handling

master
teknomunk 1 year ago
parent b2110eece3
commit 056c627d22

@ -130,9 +130,16 @@ static struct status* lookup_object_status( struct ap_activity* act )
switch( act->object.tag ) {
case apaot_ref:
s = status_from_uri( act->object.ref );
if( !s ) {
s = status_fetch_from_uri( act->object.ref );
}
break;
case apaot_activity:
s = status_from_uri( act->object.ptr->id );
if( !s ) {
s = status_from_activity( act->object.ptr );
status_save_new( s );
}
break;
}
@ -272,6 +279,14 @@ static bool route_accept( struct ap_activity* act )
return true;
}
static bool route_announce( struct ap_activity* act )
{
// TODO: handle repost
ap_activity_write_to_FILE( act, stdout );
return false;
}
bool route_activity( struct ap_activity* act )
{
printf( "Handling %s\n", act->id );
@ -282,6 +297,7 @@ bool route_activity( struct ap_activity* act )
case apat_like: return route_like(act);
case apat_create: return route_create(act);
case apat_accept: return route_accept(act);
case apat_announce: return route_announce(act);
case apat_emoji_react: return route_emoji_react(act);
default:
printf( "Unhandled activity type: %d\n", act->type );

@ -120,6 +120,8 @@ struct status* status_fetch_from_uri( const char* uri )
s->remote = true;
s->stub = true;
s->published = time(NULL);
s->url = strdup(uri);
status_save_new(s);
hash_index_set( "data/statuses/uri", uri, s->id );
@ -158,9 +160,6 @@ struct status* status_fetch_from_uri( const char* uri )
f = fopen(filename,"r");
if( !f ) { return NULL; }
s = malloc(sizeof(*s));
memset(s,0,sizeof(*s));
// Load the activity and sync status
act = ap_activity_from_FILE(f); f = NULL;
if( !act ) { goto failed; }
@ -171,6 +170,10 @@ cleanup:
ap_activity_free(act);
return s;
failed:
if( s ) {
status_flag_for_async_fetch(s);
}
status_free(s);
s = NULL;
goto cleanup;
@ -284,6 +287,31 @@ void status_free( struct status* s )
free(s);
}
struct async_status_fetch
{
struct {
int* items;
int count;
} ids;
};
#define OBJ_TYPE struct async_status_fetch
static struct json_object_field async_fetch_layout[] = {
JSON_FIELD_ARRAY_OF_INTS( ids, true ),
JSON_FIELD_END
};
#undef OBJ_TYPE
void status_flag_for_async_fetch( struct status* s )
{
struct async_status_fetch fetch;
memset( &fetch, 0, sizeof(fetch) );
json_read_object_layout_from_file( "data/statuses/async_fetch.json", async_fetch_layout, &fetch );
array_append( &fetch.ids, sizeof(s->id), &s->id );
json_write_object_layout_to_file( "data/statuses/async_fetch.json", "\t", async_fetch_layout, &fetch );
free( fetch.ids.items );
}
void status_add_to_timeline( struct status* s, int timeline_id )
{

@ -63,6 +63,8 @@ bool status_save_new( struct status* s );
void status_save( struct status* s );
void status_free( struct status* s );
void status_flag_for_async_fetch( struct status* s );
void status_make_reply_to( struct status* s, int in_reply_to );
void status_get_context( struct status* s, void* ancestors, void* replies );

Loading…
Cancel
Save