Link status/repost to the activity that created them for use in /outbox, start renaming ap_activity to ap_object, move code that creates Create activity to account model

master
teknomunk 1 year ago
parent ed4fbf7fde
commit 668e9e2d42

@ -143,28 +143,12 @@ bool handle_post( struct http_request* req, struct account* a )
if( params.in_reply_to_id ) {
status_make_reply_to( s, atoi( params.in_reply_to_id ) );
}
status_save(s);
// Add to owner timeline, public timeline and home timelines
status_add_to_timeline( s, a->id );
status_add_to_timeline( s, public_timeline_id );
status_add_to_timeline( s, home_timeline_id );
//status_add_post_to_timeline( s, federated_timeline_id );
// Save status data
status_save(s);
// Federate
struct ap_activity* note = ap_activity_create_note(s);
struct ap_activity* create = ap_activity_create_Create(note);
ap_activity_save(create);
struct outbox_envelope_list oel;
memset(&oel,0,sizeof(oel));
account_deliver_activity_to_followers( a, create, &oel );
printf( "Delivering to %d inboxes\n", oel.count );
outbox_envelope_list_save(&oel);
outbox_envelope_list_free_composite(&oel);
ap_activity_free(create);
ap_activity_free(note);
account_create( a, s );
http_request_send_headers( req, 200, "application/json", true );
FILE* f = http_request_get_response_body(req);

@ -3,13 +3,13 @@
#include <stdbool.h>
struct http_request;
struct ap_activity;
struct ap_object;
bool route_undo_follow( struct ap_activity* act );
bool route_announce( struct ap_activity* act );
bool route_add( struct ap_activity* act );
bool route_undo_follow( struct ap_object* act );
bool route_announce( struct ap_object* act );
bool route_add( struct ap_object* act );
bool route_inbox( struct http_request* req );
bool route_activity( struct ap_activity* act );
bool route_activity( struct ap_object* act );
void process_inbox();

@ -489,6 +489,32 @@ void account_follow( struct account* a, struct account* to_follow )
// Save account data
account_save(a);
}
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);
ap_activity_save(create);
// Link status to activity
s->activity_id = create->local_id;
status_save(s);
// Add to owner timeline, public timeline and home timelines
status_add_to_timeline( s, a->id );
status_add_to_timeline( s, public_timeline_id );
status_add_to_timeline( s, home_timeline_id );
//status_add_post_to_timeline( s, federated_timeline_id );
struct outbox_envelope_list oel;
memset(&oel,0,sizeof(oel));
account_deliver_activity_to_followers( a, create, &oel );
printf( "Delivering to %d inboxes\n", oel.count );
outbox_envelope_list_save(&oel);
outbox_envelope_list_free_composite(&oel);
ap_activity_free(create);
ap_activity_free(note);
}
void account_announce( struct account* a, struct status* s )
{
struct ap_activity* act = ap_activity_new();
@ -526,6 +552,10 @@ void account_announce( struct account* a, struct status* s )
ap_activity_save(act);
ap_activity_write_to_FILE( act, stdout );
// Link status to activity
s->activity_id = act->local_id;
status_save(s);
cleanup:
account_free(origin_post_account);
ap_activity_free(act);

@ -5,7 +5,7 @@
struct crypto_keys;
struct status;
struct ap_activity;
struct ap_object;
struct ap_account;
struct outbox_envelope;
struct outbox_envelope_list;
@ -75,7 +75,7 @@ void account_save( struct account* a );
// Update from external activity pub data
bool account_sync_from_activity_pub( unsigned int id );
bool account_sync_from_activity( struct account* a, struct ap_activity* act );
bool account_sync_from_activity( struct account* a, struct ap_object* act );
// Data requests
struct crypto_keys* account_get_public_key( struct account* a, const char* key_name );
@ -83,7 +83,7 @@ struct crypto_keys* account_get_private_key( struct account* a );
void account_list_followers( struct account* a, int offset, int limit, void* id_array );
void account_list_following( struct account* a, int offset, int limit, void* id_array );
struct ap_account* account_activity_pub_data( struct account* a );
struct ap_activity* account_activity_pub( struct account* a );
struct ap_object* account_activity_pub( struct account* a );
// Local actions
void account_add_follower( struct account* a, struct account* follower );
@ -92,8 +92,9 @@ void account_move( struct account* a, const char* new_uri );
bool account_does_follow( struct account* a, int account_id );
// Federated actions
void account_deliver_activity( struct account* a, struct ap_activity* act, struct outbox_envelope_list* oel );
void account_deliver_activity_to_followers( 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 );
void account_deliver_activity_to_followers( struct account* a, struct ap_object* act, struct outbox_envelope_list* oel );
void account_create( struct account* a, struct status* s );
void account_announce( struct account* a, struct status* s );
void account_follow( struct account* a, struct account* to_follow );
void account_unfollow( struct account* a, struct account* to_unfollow );

@ -156,6 +156,11 @@ void ap_activity_free_composite( struct ap_activity* act )
}
free(act->also_known_as.items);
for( int i = 0; i < act->ordered_items.count; ++i ) {
ap_object_ptr_or_ref_free( act->ordered_items.items[i] );
}
free( act->ordered_items.items );
for( int i = 0; i < act->to.count; ++i ) {
free(act->to.items[i]);
}
@ -173,18 +178,29 @@ void ap_activity_free_composite( struct ap_activity* act )
free( act->state );
switch( act->object.tag ) {
ap_object_ptr_or_ref_free_composite( &act->object );
free( act->signature.creator );
free( act->signature.value );
}
void ap_object_ptr_or_ref_free( struct ap_object_ptr_or_ref* o )
{
if( !o ) { return; }
ap_object_ptr_or_ref_free_composite(o);
free(o);
}
void ap_object_ptr_or_ref_free_composite( struct ap_object_ptr_or_ref* o )
{
switch( o->tag ) {
case apaot_ref:
free( act->object.ref );
free( o->ref );
break;
case apaot_activity:
ap_activity_free( act->object.ptr );
act->object.ptr = NULL;
ap_activity_free( o->ptr );
o->ptr = NULL;
break;
};
free( act->signature.creator );
free( act->signature.value );
}
struct ap_activity* ap_activity_create_accept( struct ap_activity* act )

@ -9,6 +9,8 @@
// Reference: https://www.w3.org/TR/activitystreams-vocabulary/
// TODO: rename this to ap_object, as this is really an Object base and not an Activity base
struct ap_object;
#define ap_activity ap_object
struct ap_activity_source
{
@ -104,7 +106,18 @@ struct ap_attachement
void ap_attachement_free( struct ap_attachement* a );
extern struct json_field_type ap_attachement_type;
struct ap_activity
struct ap_object_ptr_or_ref
{
int tag;
union {
char* ref;
struct ap_object* ptr;
};
};
void ap_object_ptr_or_ref_free( struct ap_object_ptr_or_ref* oor );
void ap_object_ptr_or_ref_free_composite( struct ap_object_ptr_or_ref* oor );
struct ap_object
{
struct ap_activity_context ap_context;
@ -147,18 +160,17 @@ struct ap_activity
int count;
} also_known_as;
struct {
struct ap_object_ptr_or_ref** items;
int count;
} ordered_items;
struct {
char** items;
int count;
} to, cc, bcc;
struct {
int tag;
union {
char* ref;
struct ap_activity* ptr;
};
} object;
struct ap_object_ptr_or_ref object;
char* state;
@ -170,33 +182,31 @@ struct json_object_field;
extern struct json_field_type ap_activity_type;
extern struct json_object_field ap_activity_layout[];
struct ap_activity* ap_activity_new();
struct ap_activity* ap_activity_dup( struct ap_activity* act );
struct ap_activity* ap_activity_from_FILE( FILE* f );
struct ap_activity* ap_activity_from_local_id( int id );
void ap_activity_free( struct ap_activity* act );
void ap_activity_free_composite( struct ap_activity* act );
struct ap_object* ap_activity_new();
struct ap_object* ap_activity_dup( struct ap_object* o );
struct ap_object* ap_activity_from_FILE( FILE* f );
struct ap_object* ap_activity_from_local_id( int id );
void ap_activity_free( struct ap_object* o );
void ap_activity_free_composite( struct ap_object* o );
void ap_activity_write_to_FILE( struct ap_activity* act, FILE* f );
void ap_activity_save( struct ap_activity* act );
void ap_activity_write_to_FILE( struct ap_object* o, FILE* f );
void ap_activity_save( struct ap_object* o );
struct ap_activity* ap_activity_create_accept( struct ap_activity* act );
void ap_activity_accept( struct ap_activity* act, int deliver_to_account_id );
struct ap_object* ap_activity_create_accept( struct ap_object* act );
void ap_activity_accept( struct ap_object* act, int deliver_to_account_id );
struct status;
struct ap_activity* ap_activity_create_emoji_react( struct status* s, const char* react );
void ap_activity_react( struct status* s, const char* react );
struct account;
int ap_activity_follow( struct account* follower, struct account* following );
void ap_activity_unfollow( struct account* follower, struct account* to_unfollow );
struct ap_activity* ap_activity_create_undo( struct ap_activity* act );
void ap_activity_undo( struct ap_activity* act, int deliver_to_account_id );
struct ap_activity* ap_activity_create_like( struct status* s );
int ap_activity_like( struct status* s );
struct ap_activity* ap_activity_create_note( struct status* s );
struct ap_activity* ap_activity_create_Create( struct ap_activity* act );
struct ap_object* ap_activity_create_emoji_react( struct status* s, const char* react );
struct ap_object* ap_activity_create_undo( struct ap_object* act );
struct ap_object* ap_activity_create_like( struct status* s );
struct ap_object* ap_activity_create_note( struct status* s );
struct ap_object* ap_activity_create_Create( struct ap_object* act );
// These should be elsewhere
void ap_activity_react( struct status* s, const char* react );
int ap_activity_follow( struct account* follower, struct account* following );
void ap_activity_unfollow( struct account* follower, struct account* to_unfollow );
void ap_activity_undo( struct ap_activity* act, int deliver_to_account_id );
int ap_activity_like( struct status* s );

@ -3,9 +3,9 @@
#include <stdbool.h>
#include <stdio.h>
struct ap_activity;
struct ap_object;
struct crypto_keys;
bool ap_activity_create_rsa_signature_2017( struct ap_activity* act, struct crypto_keys* keys );
void ap_activity_write_normalized_rdf( struct ap_activity* act, FILE* out );
bool ap_activity_create_rsa_signature_2017( struct ap_object* act, struct crypto_keys* keys );
void ap_activity_write_normalized_rdf( struct ap_object* act, FILE* out );

@ -15,7 +15,6 @@ struct ap_envelope
bool validated;
//struct ap_activity activity;
char* body;
};

@ -28,6 +28,7 @@
#define OBJ_TYPE struct status
static struct json_object_field status_layout[] = {
JSON_FIELD_INTEGER( account_id, true ),
JSON_FIELD_INTEGER( activity_id, false ),
JSON_FIELD_STRING( url, false ),
JSON_FIELD_BOOL( stub, false ),

@ -11,6 +11,7 @@ struct status
{
unsigned int id;
int account_id;
int activity_id;
char* url;
bool stub;
@ -73,9 +74,9 @@ struct status* status_from_uri( const char* uri );
struct status* status_fetch_from_uri( const char* uri );
struct status* status_from_uri_or_fetch( const char* uri );
struct ap_activity;
struct status* status_from_activity( struct ap_activity* act );
bool status_sync_from_activity_pub( struct status* s, struct ap_activity* act );
struct ap_object;
struct status* status_from_activity( struct ap_object* act );
bool status_sync_from_activity_pub( struct status* s, struct ap_object* act );
bool status_sync_from_uri( struct status* s, const char* uri );
bool status_sync( struct status* s );

Loading…
Cancel
Save