|
|
|
@ -1,24 +1,43 @@
|
|
|
|
|
#include "cli.h"
|
|
|
|
|
|
|
|
|
|
#include "model/account.h"
|
|
|
|
|
#include "model/status.h"
|
|
|
|
|
#include "controller/inbox.h"
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
static char* binary_name = NULL;
|
|
|
|
|
struct cli_request
|
|
|
|
|
{
|
|
|
|
|
char** argv;
|
|
|
|
|
int argc;
|
|
|
|
|
char* binary_name;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static bool handle_command_follow( char** argv, int argc )
|
|
|
|
|
static int cli_route_command( struct cli_request* req, const char* cmd, int count, const char* usage_args )
|
|
|
|
|
{
|
|
|
|
|
if( 0 != strcmp(argv[0],"follow") ) { return false; }
|
|
|
|
|
if( 0 != strcmp(req->argv[0], cmd ) ) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
req->argv += 1;
|
|
|
|
|
req->argc -= 1;
|
|
|
|
|
|
|
|
|
|
if( argc < 2 ) {
|
|
|
|
|
printf( "Usage: %s follow [account webfinger]\n", binary_name );
|
|
|
|
|
return true;
|
|
|
|
|
if( req->argc < count ) {
|
|
|
|
|
printf( "Usage: %s %s %s", req->binary_name, cmd, usage_args );
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool handle_command_follow( struct cli_request* req )
|
|
|
|
|
{
|
|
|
|
|
int res = cli_route_command( req, "follow", 1, "[account webfinger]" );
|
|
|
|
|
if( res != 1 ) { return !!res; }
|
|
|
|
|
|
|
|
|
|
struct account* owner = account_from_id( owner_account_id );
|
|
|
|
|
struct account* to_follow = account_from_webfinger( argv[1] );
|
|
|
|
|
struct account* to_follow = account_from_webfinger( req->argv[0] );
|
|
|
|
|
|
|
|
|
|
account_follow( owner, to_follow );
|
|
|
|
|
|
|
|
|
@ -27,17 +46,13 @@ static bool handle_command_follow( char** argv, int argc )
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
static bool handle_command_unfollow( char** argv, int argc )
|
|
|
|
|
static bool handle_command_unfollow( struct cli_request* req )
|
|
|
|
|
{
|
|
|
|
|
if( 0 != strcmp(argv[0],"unfollow") ) { return false; }
|
|
|
|
|
|
|
|
|
|
if( argc < 2 ) {
|
|
|
|
|
printf( "Usage: %s unfollow [account webfinger]\n", binary_name );
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
int res = cli_route_command( req, "unfollow", 1, "[account webfinger]" );
|
|
|
|
|
if( res != 1 ) { return !!res; }
|
|
|
|
|
|
|
|
|
|
struct account* owner = account_from_id( owner_account_id );
|
|
|
|
|
struct account* to_unfollow = account_from_webfinger( argv[1] );
|
|
|
|
|
struct account* to_unfollow = account_from_webfinger( req->argv[0] );
|
|
|
|
|
|
|
|
|
|
account_unfollow( owner, to_unfollow );
|
|
|
|
|
|
|
|
|
@ -46,12 +61,57 @@ static bool handle_command_unfollow( char** argv, int argc )
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
static bool handle_command_activity_import( struct cli_request* req )
|
|
|
|
|
{
|
|
|
|
|
int res = cli_route_command( req, "import", 1, "[activity uri]" );
|
|
|
|
|
if( res != 1 ) { return !!res; }
|
|
|
|
|
|
|
|
|
|
printf( "TODO: import activity from %s\n", req->argv[0] );
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
static bool handle_command_activity( struct cli_request* req )
|
|
|
|
|
{
|
|
|
|
|
int res = cli_route_command( req, "activity", 1, "(import) ..." );
|
|
|
|
|
if( res != 1 ) { return !!res; }
|
|
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|| handle_command_activity_import( req )
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool handle_command_status_import( struct cli_request* req )
|
|
|
|
|
{
|
|
|
|
|
int res = cli_route_command( req, "import", 1, "[status uri]" );
|
|
|
|
|
if( res != 1 ) { return !!res; }
|
|
|
|
|
|
|
|
|
|
struct status* s = status_fetch_from_uri( req->argv[0] );
|
|
|
|
|
if( s ) {
|
|
|
|
|
printf( "Status id=%d\n", s->id );
|
|
|
|
|
status_free(s);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
static bool handle_command_status( struct cli_request* req )
|
|
|
|
|
{
|
|
|
|
|
int res = cli_route_command( req, "status", 1, "(import) ..." );
|
|
|
|
|
if( res != 1 ) { return !!res; }
|
|
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|| handle_command_status_import( req );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void handle_command( char** argv, int argc )
|
|
|
|
|
{
|
|
|
|
|
binary_name = argv[0];
|
|
|
|
|
struct cli_request req = {
|
|
|
|
|
.argv = &argv[1],
|
|
|
|
|
.argc = argc - 1,
|
|
|
|
|
.binary_name = argv[0]
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
false
|
|
|
|
|
|| handle_command_follow(&argv[1],argc-1)
|
|
|
|
|
|| handle_command_unfollow(&argv[1],argc-1)
|
|
|
|
|
|| handle_command_follow(&req)
|
|
|
|
|
|| handle_command_unfollow(&req)
|
|
|
|
|
|| handle_command_activity(&req)
|
|
|
|
|
|| handle_command_status(&req)
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|