|
|
|
@ -123,96 +123,6 @@ static bool route_undo_activity( struct ap_activity* act )
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool route_follower_post( struct ap_activity* act )
|
|
|
|
|
{
|
|
|
|
|
// Requires an object
|
|
|
|
|
// TODO: if there is a ref here, fetch the object
|
|
|
|
|
if( act->object.tag != apaot_activity ) { return false; }
|
|
|
|
|
struct ap_activity* obj = act->object.ptr;
|
|
|
|
|
|
|
|
|
|
// Is this activity from a follower?
|
|
|
|
|
struct account* actor_account = account_from_uri( act->actor );
|
|
|
|
|
if( !actor_account ) {
|
|
|
|
|
printf( "No local data, can't be follower\n" );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( !account_does_follow( actor_account, owner_account_id ) ) {
|
|
|
|
|
printf( "Doesn't follower owner\n" );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create local status
|
|
|
|
|
struct status* s = status_from_activity(obj);
|
|
|
|
|
status_save_new(s);
|
|
|
|
|
|
|
|
|
|
// Add to timelines
|
|
|
|
|
status_add_to_timeline( s, home_timeline_id );
|
|
|
|
|
status_add_to_timeline( s, public_timeline_id );
|
|
|
|
|
status_add_to_timeline( s, actor_account->id );
|
|
|
|
|
|
|
|
|
|
// TODO: create notification if user notifications are on or this is part of a watched conversation
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
static bool route_mention( struct ap_activity* act )
|
|
|
|
|
{
|
|
|
|
|
// Requires an object
|
|
|
|
|
if( act->object.tag != apaot_activity ) { return false; }
|
|
|
|
|
struct ap_activity* obj = act->object.ptr;
|
|
|
|
|
|
|
|
|
|
// Does this activity have mention me
|
|
|
|
|
char owner_url[512];
|
|
|
|
|
snprintf( owner_url, sizeof(owner_url), "https://%s/owner/actor", g_server_name );
|
|
|
|
|
for( int i = 0; i < obj->tags.count; ++i ) {
|
|
|
|
|
struct ap_activity_tag* tag = obj->tags.items[i];
|
|
|
|
|
|
|
|
|
|
printf( "tag = { &=%p, .type=%d, .href=%s, .name=%s }\n", tag, tag->type, tag->href, tag->name );
|
|
|
|
|
|
|
|
|
|
if( tag->type != aptag_mention ) { continue; }
|
|
|
|
|
if( 0 == strcmp(tag->href, owner_url) ) { goto does_mention; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf( "Doesn't mention, discard\n" );
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
does_mention:
|
|
|
|
|
printf( "Does mention\n" );
|
|
|
|
|
|
|
|
|
|
bool result = false;
|
|
|
|
|
|
|
|
|
|
// Get actor account
|
|
|
|
|
struct account* mentioner = account_from_uri( obj->actor );
|
|
|
|
|
if( !mentioner ) {
|
|
|
|
|
mentioner = account_fetch_from_uri( obj->actor );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create local status
|
|
|
|
|
struct status* s = status_from_activity(obj);
|
|
|
|
|
status_save_new(s);
|
|
|
|
|
|
|
|
|
|
// Add status to account timeline
|
|
|
|
|
status_add_to_timeline( s, mentioner->id );
|
|
|
|
|
status_add_to_timeline( s, owner_account_id );
|
|
|
|
|
|
|
|
|
|
// Create notification
|
|
|
|
|
struct notification* note = notification_new();
|
|
|
|
|
note->type = nt_mention;
|
|
|
|
|
note->status_id = s->id;
|
|
|
|
|
note->account_id = mentioner->id;
|
|
|
|
|
notification_save( note );
|
|
|
|
|
notification_free( note );
|
|
|
|
|
|
|
|
|
|
result = true;
|
|
|
|
|
cleanup:
|
|
|
|
|
account_free(mentioner);
|
|
|
|
|
status_free(s);
|
|
|
|
|
return result;
|
|
|
|
|
failed:
|
|
|
|
|
result = false;
|
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct status* lookup_object_status( struct ap_activity* act )
|
|
|
|
|
{
|
|
|
|
|
struct status* s = NULL;
|
|
|
|
@ -263,12 +173,85 @@ static bool route_emoji_react( struct ap_activity* act )
|
|
|
|
|
|
|
|
|
|
static bool route_create( struct ap_activity* act )
|
|
|
|
|
{
|
|
|
|
|
return
|
|
|
|
|
route_mention(act)
|
|
|
|
|
|| route_follower_post(act)
|
|
|
|
|
;
|
|
|
|
|
bool result = false;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
// Requires an object
|
|
|
|
|
// TODO: if there is a ref here, fetch the object
|
|
|
|
|
if( act->object.tag != apaot_activity ) { return false; }
|
|
|
|
|
struct ap_activity* obj = act->object.ptr;
|
|
|
|
|
|
|
|
|
|
bool mentions_me = false;
|
|
|
|
|
bool follows_me = false;
|
|
|
|
|
|
|
|
|
|
// Does this activity have mention me
|
|
|
|
|
char owner_url[512];
|
|
|
|
|
snprintf( owner_url, sizeof(owner_url), "https://%s/owner/actor", g_server_name );
|
|
|
|
|
for( int i = 0; i < obj->tags.count; ++i ) {
|
|
|
|
|
struct ap_activity_tag* tag = obj->tags.items[i];
|
|
|
|
|
|
|
|
|
|
//printf( "tag = { &=%p, .type=%d, .href=%s, .name=%s }\n", tag, tag->type, tag->href, tag->name );
|
|
|
|
|
|
|
|
|
|
if( tag->type != aptag_mention ) { continue; }
|
|
|
|
|
if( 0 == strcmp(tag->href, owner_url) ) {
|
|
|
|
|
mentions_me = true;
|
|
|
|
|
goto check_is_follower;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
check_is_follower:
|
|
|
|
|
// Get actor account
|
|
|
|
|
struct account* actor_account = account_from_uri( obj->actor );
|
|
|
|
|
if( !actor_account ) {
|
|
|
|
|
actor_account = account_fetch_from_uri( obj->actor );
|
|
|
|
|
}
|
|
|
|
|
if( !actor_account ) {
|
|
|
|
|
printf( "! Unable to fetch %s\n", obj->actor );
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( account_does_follow( actor_account, owner_account_id ) ) {
|
|
|
|
|
follows_me = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( !follows_me && !mentions_me ) {
|
|
|
|
|
// Discard without action
|
|
|
|
|
result = true;
|
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create local status
|
|
|
|
|
struct status* s = status_from_activity(obj);
|
|
|
|
|
status_save_new(s);
|
|
|
|
|
|
|
|
|
|
// Add to timelines
|
|
|
|
|
if( follows_me ) {
|
|
|
|
|
status_add_to_timeline( s, home_timeline_id );
|
|
|
|
|
|
|
|
|
|
// TODO: create notification if user notifications are on or this is part of a watched conversation
|
|
|
|
|
}
|
|
|
|
|
if( mentions_me ) {
|
|
|
|
|
// Create notification
|
|
|
|
|
struct notification* note = notification_new();
|
|
|
|
|
note->type = nt_mention;
|
|
|
|
|
note->status_id = s->id;
|
|
|
|
|
note->account_id = actor_account->id;
|
|
|
|
|
notification_save( note );
|
|
|
|
|
notification_free( note );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add to standard timelines
|
|
|
|
|
status_add_to_timeline( s, public_timeline_id );
|
|
|
|
|
//status_add_to_timeline( s, federated_timeline_id );
|
|
|
|
|
status_add_to_timeline( s, actor_account->id );
|
|
|
|
|
|
|
|
|
|
result = true;
|
|
|
|
|
cleanup:
|
|
|
|
|
account_free(actor_account);
|
|
|
|
|
status_free(s);
|
|
|
|
|
return result;
|
|
|
|
|
failed:
|
|
|
|
|
result = false;
|
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool route_accept( struct ap_activity* act )
|
|
|
|
|