|
|
|
@ -11,6 +11,7 @@
|
|
|
|
|
#include "model/account.h"
|
|
|
|
|
#include "model/notification.h"
|
|
|
|
|
#include "model/ap/activity.h"
|
|
|
|
|
#include "model/ap/account.h"
|
|
|
|
|
#include "model/ap/inbox_envelope.h"
|
|
|
|
|
#include "model/crypto/http_sign.h"
|
|
|
|
|
//#include "model/timeline.h"
|
|
|
|
@ -39,26 +40,6 @@ bool route_inbox( struct http_request* req )
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool route_undo_follow( struct ap_activity* act )
|
|
|
|
|
{
|
|
|
|
|
const char* target = act->object.ptr->object.ref;
|
|
|
|
|
struct account* a = account_from_uri( target );
|
|
|
|
|
if( !a || 0 != strcmp( a->server, g_server_name ) ) {
|
|
|
|
|
printf( "Unfollow not targeted at local account. Discarding.\n" );
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct account* follower = account_from_uri( act->actor );
|
|
|
|
|
if( !follower ) {
|
|
|
|
|
printf( "Follower account not present local. Active follow not possible. Discarding undo\n" );
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
account_remove_follower( a, follower );
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool route_follow( struct ap_activity* act )
|
|
|
|
|
{
|
|
|
|
|
struct account* follower = NULL;
|
|
|
|
@ -105,8 +86,8 @@ failed:
|
|
|
|
|
static bool route_undo_activity( struct ap_activity* act )
|
|
|
|
|
{
|
|
|
|
|
if( act->object.tag != apaot_activity ) {
|
|
|
|
|
// Don't undo activities that are references
|
|
|
|
|
return false;
|
|
|
|
|
printf( "Can't undo reference activities, discarding...\n" );
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if( !act->object.ptr ) {
|
|
|
|
|
printf( "No object in activity\n" );
|
|
|
|
@ -280,65 +261,6 @@ static bool route_accept( struct ap_activity* act )
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool route_announce( struct ap_activity* act )
|
|
|
|
|
{
|
|
|
|
|
bool result = false;
|
|
|
|
|
struct status* s = 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 ) {
|
|
|
|
|
printf( "! object not reference\n" );
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct status* 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( s, home_timeline_id );
|
|
|
|
|
status_add_to_timeline( s, public_timeline_id );
|
|
|
|
|
status_add_to_timeline( s, actor_account->id );
|
|
|
|
|
|
|
|
|
|
result = true;
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool route_activity( struct ap_activity* act )
|
|
|
|
|
{
|
|
|
|
|
printf( "Handling %s\n", act->id );
|
|
|
|
@ -351,6 +273,7 @@ bool route_activity( struct ap_activity* act )
|
|
|
|
|
case apat_create: return route_create(act);
|
|
|
|
|
case apat_accept: return route_accept(act);
|
|
|
|
|
case apat_announce: return route_announce(act);
|
|
|
|
|
case apat_add: return route_add(act);
|
|
|
|
|
case apat_emoji_react: return route_emoji_react(act);
|
|
|
|
|
default:
|
|
|
|
|
printf( "Unhandled activity type: %d\n", act->type );
|
|
|
|
|