@ -4,8 +4,11 @@
# include "ffdb/fs_list.h"
# include "collections/array.h"
# include "format.h"
# include "model/server.h"
# include "model/account.h"
# include "model/status.h"
# include "model/ap/outbox_envelope.h"
# include <stddef.h>
@ -77,6 +80,7 @@ void ap_activity_free_composite( struct ap_activity* act )
{
free ( act - > id ) ;
free ( act - > actor ) ;
free ( act - > content ) ;
for ( int i = 0 ; i < act - > to . count ; + + i ) {
free ( act - > to . items [ i ] ) ;
@ -113,16 +117,13 @@ struct ap_activity* ap_activity_create_accept( struct ap_activity* act )
int id = fs_list_get ( " data/activities/HEAD " ) + 1 ;
fs_list_set ( " data/activities/HEAD " , id ) ;
char * act_id ; asprintf ( & act_id , " https://%s/activity/%d " , g_server_name , id ) ;
char * actor ; asprintf ( & actor , " https://%s/owner/actor " , g_server_name ) ;
struct ap_activity * accept = malloc ( sizeof ( struct ap_activity ) ) ;
memset ( accept , 0 , sizeof ( * accept ) ) ;
accept - > id = act_id ;
asprintf ( & accept - > id , " https://%s/activity/%d " , g_server_name , id ) ;
accept - > local_id = id ;
accept - > type = apat_accept ;
accept - > actor = actor ;
asprintf ( & accept - > actor , " https://%s/owner/actor " , g_server_name ) ;
char * new_act_actor = strdup ( act - > actor ) ;
array_append ( & accept - > to , sizeof ( char * ) , & new_act_actor ) ;
accept - > object . tag = apaot_activity ;
@ -144,3 +145,51 @@ void ap_activity_accept( struct ap_activity* act, int deliver_to_account_id )
ap_activity_free ( accept ) ;
}
struct ap_activity * ap_activity_create_emoji_react ( struct status * s , const char * react )
{
struct account * a = account_from_id ( s - > account_id ) ;
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 = aformat ( " https://%s/owner/actor " , g_server_name ) ;
act - > type = apat_emoji_react ;
act - > content = strdup ( react ) ;
act - > published = time ( NULL ) ;
act - > object . tag = apaot_ref ;
act - > object . ref = strdup ( s - > url ) ;
char * to = aformat ( " %s/followers " , a - > account_url ) ;
array_append ( & act - > to , sizeof ( to ) , & to ) ;
char * cc = strdup ( " https://www.w3.org/ns/activitystreams#Public " ) ;
array_append ( & act - > cc , sizeof ( cc ) , & cc ) ;
cc = strdup ( a - > account_url ) ;
array_append ( & act - > cc , sizeof ( cc ) , & cc ) ;
account_free ( a ) ;
return act ;
}
void ap_activity_react ( struct status * s , const char * react )
{
struct ap_activity * act = ap_activity_create_emoji_react ( s , react ) ;
/*
ap_activity_write_to_FILE ( act , stdout ) ;
printf ( " \n RDF: \n " ) ;
ap_activity_write_normalized_rdf ( act , stdout ) ;
*/
ap_activity_save ( act ) ;
struct outbox_envelope * env = outbox_envelope_new ( ) ;
env - > activity_id = act - > local_id ;
env - > account_id = s - > account_id ;
outbox_envelope_save ( env ) ;
outbox_envelope_free ( env ) ;
ap_activity_free ( act ) ;
}