@ -27,10 +27,13 @@ struct ap_activity* ap_activity_new()
struct ap_activity * ap_activity_dup ( struct ap_activity * act )
{
struct ap_activity * new_act = ap_activity_new ( ) ;
memset ( new_act , 0 , sizeof ( * new_act ) ) ;
new_act - > id = strdup ( act - > id ) ;
new_act - > local_id = act - > local_id ;
new_act - > type = act - > type ;
new_act - > actor = strdup ( act - > actor ) ;
new_act - > published = act - > published ;
array_dup ( & new_act - > to , sizeof ( char * ) , & act - > to ) ;
for ( int i = 0 ; i < new_act - > to . count ; + + i ) {
@ -192,7 +195,7 @@ void ap_activity_react( struct status* s, const char* react )
struct ap_activity * ap_activity_create_follow ( struct account * follower , struct account * following )
{
int id = fs_list_get ( " data/activities/HEAD " ) + 1 ;
//fs_list_set( "data/activities/HEAD", id );
fs_list_set ( " data/activities/HEAD " , id ) ;
struct ap_activity * act = ap_activity_new ( ) ;
act - > local_id = id ;
@ -209,28 +212,74 @@ struct ap_activity* ap_activity_create_follow( struct account* follower, struct
return act ;
}
void ap_activity_follow ( struct account * follower , struct account * following )
int ap_activity_follow ( struct account * follower , struct account * following )
{
int res = - 1 ;
struct ap_activity * act = ap_activity_create_follow ( follower , following ) ;
/*
ap_activity_write_to_FILE ( act , stdout ) ;
printf ( " \n RDF: \n " ) ;
ap_activity_write_normalized_rdf ( act , stdout ) ;
//*/
if ( ! act ) { goto failed ; }
ap_activity_save ( act ) ;
res = act - > local_id ;
struct outbox_envelope * env = outbox_envelope_new ( ) ;
if ( ! env ) { goto failed ; }
env - > activity_id = act - > local_id ;
env - > account_id = following - > id ;
outbox_envelope_save ( env ) ;
outbox_envelope_free ( env ) ;
cleanup :
ap_activity_free ( act ) ;
return res ;
failed :
res = - 1 ;
goto cleanup ;
}
struct ap_activity * ap_activity_create_undo ( struct ap_activity * act_to_undo )
{
int id = fs_list_get ( " data/activities/HEAD " ) + 1 ;
fs_list_set ( " data/activities/HEAD " , id ) ;
struct ap_activity * act = ap_activity_new ( ) ;
act - > local_id = id ;
act - > id = aformat ( " https://%s/activity/%d " , g_server_name , id ) ;
act - > actor = strdup ( act_to_undo - > actor ) ;
act - > type = apat_undo ;
act - > published = time ( NULL ) ;
act - > object . tag = apaot_activity ;
act - > object . ptr = ap_activity_dup ( act_to_undo ) ;
char * to = strdup ( act_to_undo - > object . ref ) ;
array_append ( & act - > to , sizeof ( to ) , & to ) ;
return act ;
}
void ap_activity_undo ( struct activity * act )
void ap_activity_undo ( struct a p_a ctivity* act , int deliver_to_account_id )
{
// TODO: implement
struct ap_activity * undo_act = ap_activity_create_undo ( act ) ;
if ( ! undo_act ) { goto failed ; }
ap_activity_save ( undo_act ) ;
/*
printf ( " act= " ) ;
ap_activity_write_to_FILE ( act , stdout ) ;
printf ( " \n undo_act= " ) ;
ap_activity_write_to_FILE ( undo_act , stdout ) ;
printf ( " \n " ) ;
*/
struct outbox_envelope * env = outbox_envelope_new ( ) ;
if ( ! env ) { goto failed ; }
env - > activity_id = undo_act - > local_id ;
env - > account_id = deliver_to_account_id ;
outbox_envelope_save ( env ) ;
outbox_envelope_free ( env ) ;
cleanup :
ap_activity_free ( undo_act ) ;
return ;
failed :
goto cleanup ;
}