Add enough processing for Undo:Announce to discard activities that don't pertain to a locally mirrored status, fix Create Note activity following check, add 'value' field to ap_attachement

master
teknomunk 1 year ago
parent 5990049dad
commit 04c456e12d

@ -84,6 +84,17 @@ failed:
goto cleanup;
}
static bool route_undo_Announce( struct ap_activity* act )
{
struct status* s = NULL;
s = status_from_uri( act->object.ptr->id );
if( !s ) { return true; } // Status not local, discard
status_free(s);
return false;
}
static bool route_undo_activity( struct ap_activity* act )
{
if( act->object.tag != apaot_activity ) {
@ -96,7 +107,8 @@ static bool route_undo_activity( struct ap_activity* act )
}
switch( act->object.ptr->type ) {
case apat_follow: return route_undo_follow( act );
case apat_follow: return route_undo_follow( act );
case apat_announce: return route_undo_Announce( act );
default:
printf( "Unhandled object activity type %d in undo\n", act->object.ptr->type );
return false;
@ -214,7 +226,7 @@ static bool route_update( struct ap_activity* act )
if( act->object.tag == apaot_activity ) {
if( act->object.ptr->type == apat_note ) {
s = status_from_uri( act->object.ptr->id );
if( !s ) { return false; }
if( !s ) { return true; } // Status not available locally, discard
} else if( act->object.ptr->type == apat_person ) {
return route_update_Person(act);
} else {
@ -222,7 +234,7 @@ static bool route_update( struct ap_activity* act )
}
} else if( act->object.tag == apaot_ref ) {
s = status_from_uri( act->object.ref );
if( !s ) { return false; }
if( !s ) { return true; } // Status not available locally, discard
}
status_sync_from_uri( s, s->url );
@ -239,9 +251,6 @@ static bool route_move( struct ap_activity* act )
if( act->object.tag != apaot_ref ) { goto discard; }
// TODO: make this work
printf( "TODO: move %s to %s\n", act->object.ref, act->target );
// Make sure this belongs to a local account
a = account_from_uri( act->object.ref );
if( !a ) { goto discard; }
@ -272,10 +281,14 @@ static bool route_create( struct ap_activity* act )
{
struct status* s = NULL;
bool result = false;
struct account* actor_account = NULL;
struct account* owner_account = NULL;
// Requires an object
// TODO: if there is a ref here, fetch the object
if( act->object.tag != apaot_activity ) { return false; }
if( act->object.tag != apaot_activity ) {
printf( "TODO: fetch activity from %s\n", act->object.ref );
return false;
}
struct ap_activity* obj = act->object.ptr;
bool mentions_me = false;
@ -299,18 +312,20 @@ static bool route_create( struct ap_activity* act )
check_is_follower:
// Get actor account
struct account* actor_account = account_from_uri_or_fetch( obj->actor );
actor_account = account_from_uri_or_fetch( obj->actor );
if( !actor_account ) {
printf( "! Unable to fetch %s\n", obj->actor );
goto failed;
}
owner_account = account_from_id( owner_account_id );
if( account_does_follow( actor_account, owner_account_id ) ) {
if( account_does_follow( owner_account, actor_account->id ) ) {
follows_me = true;
}
if( !follows_me && !mentions_me ) {
// Discard without action
printf( "Discarding create. follows_me=%c, mentions_me=%c\n", follows_me ? 'T' : 'F', mentions_me ? 'T' : 'F' );
result = true;
goto cleanup;
}
@ -351,6 +366,7 @@ check_is_follower:
result = true;
cleanup:
account_free(actor_account);
account_free(owner_account);
status_free(s);
return result;
failed:
@ -402,6 +418,7 @@ static bool process_one()
printf( "Inbox has %d items pending processing...\n", (head_pos - tail_pos) );
int id = tail_pos + 1;
printf( "Next item is #%d\n", id );
env = ap_envelope_from_id(id);
bool step_tail = false;

@ -165,7 +165,6 @@ void process_outbox()
//activity |= cleanup_outbox();
if( !activity ) {
printf( "Sleeping for 10 seconds\n" );
fflush(stdout);
sleep(10);
}

@ -1 +1 @@
Subproject commit 0995757754e5128ba085b1cc413dc112950ad6df
Subproject commit 7b71290de5b2bb48f5899a75c897fb68a55378e9

@ -73,6 +73,7 @@ struct ap_attachement
char* mediaType;
char* name;
char* url;
char* value;
};
void ap_attachement_free( struct ap_attachement* a );
extern struct json_field_type ap_attachement_type;

@ -7,7 +7,8 @@
struct json_object_field ap_attachement_layout[] = {
JSON_FIELD_STRING( mediaType, false ),
JSON_FIELD_STRING( name, false ),
JSON_FIELD_STRING( url, true ),
JSON_FIELD_STRING( url, false ),
JSON_FIELD_STRING( value, false ),
JSON_FIELD_END
};
#undef OBJ_TYPE

@ -464,7 +464,7 @@ void status_add_react( struct status* s, const char* react, struct account* a )
}
}
if( s->account_id == owner_account_id && a->id != owner_account_id ) {
if( !s->remote && a->id != owner_account_id ) { //&& s->account_id == owner_account_id && a->id != owner_account_id ) {
if( s->id != 0 ) {
// Create notification for liking the owner's post
struct notification* note = notification_new();

Loading…
Cancel
Save