You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
1.8 KiB
C

#include "../inbox.h"
// Submodules
#include "ap/object.h"
// Model
#include "model/account.h"
#include "model/status.h"
// Standard Library
#include <string.h>
#include <stdlib.h>
bool route_announce( struct ap_object* act )
{
bool result = false;
struct status* s = NULL;
struct status* original_post = NULL;
struct account* owner_account = account_from_id( owner_account_id );
struct account* actor_account = account_from_uri( act->actor );
if( !account_does_follow( owner_account, actor_account->id ) ) {
// Not following, discard
printf( "%s does not follow %s\n", owner_account->handle, actor_account->account_url );
goto discard;
}
// Reposts do not show up in notifications unless notifications for the user are enabled
if( actor_account->notify_for_posts ) {
printf( "? TODO: notification\n" );
}
if( act->object.tag != apaot_ref ) {
// Extract the ID and discard the object
char* id = act->object.ptr->id;
act->object.ptr->id = NULL;
ap_object_free( act->object.ptr );
act->object.tag = apaot_ref;
act->object.ref = id;
}
original_post = status_fetch_from_uri( act->object.ref );
if( !original_post ) {
goto discard;
}
// TODO: handle repost
s = malloc(sizeof(*s));
memset(s,0,sizeof(*s));
s->url = strdup(act->id);
s->published = act->published;
s->repost_id = original_post->id;
s->account_id = actor_account->id;
s->sensitive = act->sensitive;
status_save_new(s);
status_add_to_timeline( original_post, original_post->account_id );
status_add_to_timeline( s, home_timeline_id );
status_add_to_timeline( s, public_timeline_id );
status_add_to_timeline( s, actor_account->id );
goto discard;
cleanup:
status_free(s);
status_free(original_post);
account_free(owner_account);
account_free(actor_account);
return result;
discard:
result = true;
goto cleanup;
/*
failed:
result = false;
goto cleanup;
*/
}