Fix bugs, fix inbox blocks, add safety to reacts, create common cleanup_box for both inbox and outbox, start transition of ap_activity to ap_object

master
teknomunk 1 year ago
parent 498391c779
commit 91f821ce8e

@ -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);

@ -186,6 +186,7 @@ static bool process_pending()
return result;
}
bool cleanup_box( const char* box );
extern bool terminate;
void process_outbox()
@ -193,7 +194,7 @@ void process_outbox()
while( !terminate ) {
bool activity = false;
activity |= process_pending();
//activity |= cleanup_outbox();
activity |= cleanup_box("data/outbox");
if( !activity ) {
fflush(stdout);

@ -29,6 +29,11 @@ static bool handle_reactions( struct http_request* req, struct status* s )
char* react = cgi_unescape(react_cgi);
free(react_cgi);
// Make sure there is a reaction here
if( !*react ) {
return false;
}
struct account* owner = account_from_id( owner_account_id );
if( method ) {
status_add_react( s, react, owner );

@ -1 +1 @@
Subproject commit 352e288093a597f394d447cba2ed843f9424e8f0
Subproject commit 3fd94eba01d4cc6eca62c74272640883f94a7849

@ -180,6 +180,10 @@ void ap_activity_accept( struct ap_activity* act, int deliver_to_account_id )
struct ap_activity* ap_activity_create_emoji_react( struct status* s, const char* react )
{
if( !*react ) {
return NULL;
}
struct account* a = account_from_id( s->account_id );
int id = fs_list_get("data/activities/HEAD") + 1;
@ -210,6 +214,8 @@ struct ap_activity* ap_activity_create_emoji_react( struct status* s, const char
void ap_activity_react( struct status* s, const char* react )
{
struct ap_activity* act = ap_activity_create_emoji_react(s,react);
if( !act ) { return; }
ap_activity_save(act);
struct outbox_envelope* env = outbox_envelope_new();

@ -7,6 +7,9 @@
#include <time.h>
// Reference: https://www.w3.org/TR/activitystreams-vocabulary/
// TODO: rename this to ap_object, as this is really an Object base and not an Activity base
struct ap_activity_source
{
char* mime_type;
@ -28,8 +31,9 @@ struct ap_signature
char* value;
};
enum ap_activity_type
enum ap_object_type
{
// Activity Types
apat_undo = 1,
apat_follow = 2,
apat_delete = 3,
@ -57,11 +61,33 @@ enum ap_activity_type
apat_block = 25,
apat_flag = 26,
apat_dislike = 27,
apat_question = 28,
apat_emoji_react = 29,
apat_note = 30,
apat_person = 31,
apat_emoji_react = 28,
// Object Types
apat_note = 100,
apat_question = 101,
apot_article = 102,
apot_audio = 103,
apot_document = 104,
apot_event = 105,
apot_image = 106,
apot_page = 107,
apot_place = 108,
apot_profile = 109,
apot_relationship = 110,
apot_tombstone = 111,
apot_video = 112,
// Actor Types
apat_person = 200,
apot_service = 201,
apot_application = 202,
apot_group = 203,
apot_organization = 204,
};
extern struct json_enum ap_object_type_enum[];
enum ap_activity_object_type {
apaot_ref = 1,
apaot_activity = 2,

@ -11,7 +11,7 @@ extern struct json_field_type ap_signature_composite_type;
extern struct json_field_type ap_activity_source_type;
// https://www.w3.org/TR/activitystreams-vocabulary/#h-activity-types
struct json_enum ap_activity_type_enum[] = {
struct json_enum ap_object_type_enum[] = {
{ "Undo", apat_undo },
{ "Follow", apat_follow },
{ "Delete", apat_delete },
@ -43,6 +43,7 @@ struct json_enum ap_activity_type_enum[] = {
{ "EmojiReact", apat_emoji_react },
{ "Note", apat_note },
{ "Person", apat_person },
{ "Service", apot_service },
{ NULL, 0 },
};
@ -191,7 +192,7 @@ struct json_object_field ap_activity_layout[] = {
.tagged_item_types = signature_types
},
JSON_FIELD_ENUM( type, ap_activity_type_enum, true ),
JSON_FIELD_ENUM( type, ap_object_type_enum, true ),
JSON_FIELD_END,
};

@ -17,7 +17,6 @@
#include <stdlib.h>
#include <stddef.h>
extern struct rdf_enum_item ap_activity_type_enum[];
static char* type_filter( const char* name )
{
char* res;
@ -25,7 +24,7 @@ static char* type_filter( const char* name )
return res;
}
struct rdf_enum types = {
.items = ap_activity_type_enum,
.items = (struct rdf_enum_item*)ap_object_type_enum,
.filter = type_filter,
};

Loading…
Cancel
Save