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.
62 lines
1.2 KiB
C
62 lines
1.2 KiB
C
#include "follow.h"
|
|
|
|
// Submodules
|
|
#include "ap/object.h"
|
|
|
|
// Model
|
|
#include "model/activity.h"
|
|
#include "model/account.h"
|
|
#include "model/server.h"
|
|
|
|
// Standard Library
|
|
#include <string.h>
|
|
|
|
bool route_follow( struct ap_object* act )
|
|
{
|
|
struct account* follower = NULL;
|
|
bool res = false;
|
|
|
|
const char* target = act->object.ref;
|
|
struct account* a = account_from_uri( target );
|
|
|
|
// Don't process follows for remote users
|
|
if( !a || 0 != strcmp( a->server, g_server->domain ) ) {
|
|
printf( "Unfollow not targeted at local account. Discarding.\n" );
|
|
goto success;
|
|
}
|
|
|
|
// Get account for the follower
|
|
follower = account_from_uri( act->actor );
|
|
if( !follower ) {
|
|
follower = account_fetch_from_uri( act->actor );
|
|
}
|
|
if( follower->id == owner_account_id ) {
|
|
// Something went wrong, bail
|
|
goto failed;
|
|
}
|
|
if( !follower ) {
|
|
printf( "Unable to fetch account for %s\n", act->actor );
|
|
goto failed;
|
|
}
|
|
|
|
// Add the follower
|
|
account_add_follower( a, follower );
|
|
|
|
// Create Accept activity
|
|
activity_accept( act, follower->id );
|
|
|
|
goto success;
|
|
success:
|
|
res = true;
|
|
goto cleanup;
|
|
cleanup:
|
|
account_free(a);
|
|
account_free(follower);
|
|
|
|
return res;
|
|
failed:
|
|
res = false;
|
|
goto cleanup;
|
|
}
|
|
|