|
|
|
@ -5,6 +5,7 @@
|
|
|
|
|
#include "json/json.h"
|
|
|
|
|
#include "ffdb/fs_list.h"
|
|
|
|
|
#include "collections/array.h"
|
|
|
|
|
#include "format.h"
|
|
|
|
|
|
|
|
|
|
// Model
|
|
|
|
|
#include "model/server.h"
|
|
|
|
@ -236,16 +237,22 @@ static bool route_update( struct ap_activity* act )
|
|
|
|
|
struct status* s = NULL;
|
|
|
|
|
|
|
|
|
|
if( act->object.tag == apaot_activity ) {
|
|
|
|
|
if( act->object.ptr->type == apat_note ) {
|
|
|
|
|
s = status_from_uri( act->object.ptr->id );
|
|
|
|
|
if( !s ) { return true; } // Status not available locally, discard
|
|
|
|
|
} else if( act->object.ptr->type == apat_person ) {
|
|
|
|
|
return route_update_Person(act);
|
|
|
|
|
} else if( act->object.ptr->type == apat_question ) {
|
|
|
|
|
// TODO: update Poll
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
switch( act->object.ptr->type ) {
|
|
|
|
|
case apat_note:
|
|
|
|
|
{
|
|
|
|
|
s = status_from_uri( act->object.ptr->id );
|
|
|
|
|
if( !s ) { return true; } // Status not available locally, discard
|
|
|
|
|
|
|
|
|
|
// TODO: update status
|
|
|
|
|
}; break;
|
|
|
|
|
case apat_person:
|
|
|
|
|
return route_update_Person(act);
|
|
|
|
|
case apat_question:
|
|
|
|
|
// TODO: update Poll
|
|
|
|
|
return true;
|
|
|
|
|
case apot_service:
|
|
|
|
|
// discard
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
} else if( act->object.tag == apaot_ref ) {
|
|
|
|
|
s = status_from_uri( act->object.ref );
|
|
|
|
@ -522,25 +529,27 @@ discard:
|
|
|
|
|
goto finished;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool cleanup_inbox()
|
|
|
|
|
bool cleanup_box( const char* box )
|
|
|
|
|
{
|
|
|
|
|
int tail_pos = fs_list_get("data/inbox/TAIL");
|
|
|
|
|
int dead_pos = fs_list_get("data/inbox/DEAD");
|
|
|
|
|
char tail[512];
|
|
|
|
|
char dead[512];
|
|
|
|
|
|
|
|
|
|
int tail_pos = fs_list_get(format(tail,sizeof(tail),"%s/TAIL",box));
|
|
|
|
|
int dead_pos = fs_list_get(format(dead,sizeof(dead),"%s/DEAD",box));
|
|
|
|
|
if( dead_pos < tail_pos ) {
|
|
|
|
|
char filename[512];
|
|
|
|
|
snprintf( filename, 512, "data/inbox/%d.json", dead_pos + 1 );
|
|
|
|
|
FILE* f = fopen( filename, "r" );
|
|
|
|
|
FILE* f = fopen( format(filename,512,"%s/%d.json", box, dead_pos + 1 ), "r" );
|
|
|
|
|
if( f ) {
|
|
|
|
|
fclose(f);
|
|
|
|
|
if( 0 == remove(filename) ) {
|
|
|
|
|
// File successfully remove, advance
|
|
|
|
|
fs_list_set( "data/inbox/DEAD", dead_pos + 1 );
|
|
|
|
|
fs_list_set(dead, dead_pos + 1 );
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// File already doesn't exist, advance
|
|
|
|
|
fs_list_set( "data/inbox/DEAD", dead_pos + 1 );
|
|
|
|
|
fs_list_set( dead, dead_pos + 1 );
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
@ -553,7 +562,7 @@ void process_inbox()
|
|
|
|
|
while( !terminate ) {
|
|
|
|
|
bool activity = false;
|
|
|
|
|
activity |= process_one();
|
|
|
|
|
activity |= cleanup_inbox();
|
|
|
|
|
activity |= cleanup_box( "data/inbox" );
|
|
|
|
|
|
|
|
|
|
if( !activity ) {
|
|
|
|
|
fflush(stdout);
|
|
|
|
|