Implement Follow activity (not yet attached to API)

master
teknomunk 1 year ago
parent 9ab772b661
commit 229ebacd78

@ -18,10 +18,12 @@
void develop()
{
struct status* s = status_from_id(89);
struct account* owner = account_from_id( owner_account_id );
struct account* to_follow = account_from_webfinger( "tester@pl.polaris-1.work" );
ap_activity_react( s, "👍" );
ap_activity_follow( owner, to_follow );
status_free(s);
account_free( owner );
account_free( to_follow );
}

@ -10,6 +10,7 @@
#include "model/account.h"
#include "model/status.h"
#include "model/ap/outbox_envelope.h"
#include "model/ap/activity/rsa_signature_2017.h"
#include <stddef.h>
#include <stdlib.h>
@ -177,19 +178,59 @@ struct ap_activity* ap_activity_create_emoji_react( struct status* s, const char
void ap_activity_react( struct status* s, const char* react )
{
struct ap_activity* act = ap_activity_create_emoji_react(s,react);
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);
}
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 );
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( follower->account_url );
act->type = apat_follow;
act->published = time(NULL);
act->object.tag = apaot_ref;
act->state = strdup("pending");
act->object.ref = strdup( following->account_url );
char* to = strdup(following->account_url);
array_append( &act->to, sizeof(to), &to );
return act;
}
void ap_activity_follow( struct account* follower, struct account* following )
{
struct ap_activity* act = ap_activity_create_follow( follower, following );
/*
ap_activity_write_to_FILE( act, stdout );
printf("\nRDF:\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;
env->account_id = following->id;
outbox_envelope_save( env );
outbox_envelope_free( env );
ap_activity_free(act);
}
void ap_activity_undo( struct activity* act )
{
// TODO: implement
}

@ -131,3 +131,8 @@ 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;
void ap_activity_follow( struct account* follower, struct account* following );
void ap_activity_undo( struct activity* act );

@ -70,8 +70,6 @@ struct json_object_field ap_activity_layout[] = {
{ "actor", offsetof( struct ap_activity, actor ), true, &json_field_string },
{ "state", offsetof( struct ap_activity, state ), false, &json_field_string },
{ "state", offsetof( struct ap_activity, state ), false, &json_field_string },
{ "content", offsetof( struct ap_activity, content ), false, &json_field_string },
{ "conversation", offsetof( struct ap_activity, conversation ), false, &json_field_string },
{ "published", offsetof( struct ap_activity, published ), false, &json_field_date_time },
@ -82,7 +80,7 @@ struct json_object_field ap_activity_layout[] = {
{ "tag", offsetof( struct ap_activity, tags ), false, &json_field_array_of, &ap_activity_tag_type },
{ "context", offsetof( struct ap_activity, context ), false, &json_field_string },
{ "context_id", offsetof( struct ap_activity, context_id ), false, &json_field_integer },
//{ "context_id", offsetof( struct ap_activity, context_id ), false, &json_field_integer },
{ "attributedTo", offsetof( struct ap_activity, attributed_to ), false, &json_field_string },

Loading…
Cancel
Save