|
|
|
@ -315,39 +315,27 @@ failed:
|
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool route_create( struct ap_object* act )
|
|
|
|
|
static bool mentions_account_url( struct ap_object* obj, const char* account_url )
|
|
|
|
|
{
|
|
|
|
|
struct status* s = NULL;
|
|
|
|
|
bool result = false;
|
|
|
|
|
struct account* actor_account = NULL;
|
|
|
|
|
struct account* owner_account = NULL;
|
|
|
|
|
|
|
|
|
|
// Requires an object
|
|
|
|
|
if( act->object.tag != apaot_activity ) {
|
|
|
|
|
printf( "TODO: fetch activity from %s\n", act->object.ref );
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
struct ap_object* obj = act->object.ptr;
|
|
|
|
|
|
|
|
|
|
bool mentions_me = false;
|
|
|
|
|
bool account_followed = false;
|
|
|
|
|
|
|
|
|
|
// Does this activity have mention me
|
|
|
|
|
char owner_url[512];
|
|
|
|
|
snprintf( owner_url, sizeof(owner_url), "https://%s/owner/actor", g_server->domain );
|
|
|
|
|
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;
|
|
|
|
|
if( 0 == strcmp(tag->href, account_url) ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
check_is_follower:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
static bool account_actor_is_followed( struct ap_object* obj )
|
|
|
|
|
{
|
|
|
|
|
bool result = false;
|
|
|
|
|
struct account* actor_account = NULL;
|
|
|
|
|
struct account* owner_account = NULL;
|
|
|
|
|
|
|
|
|
|
// Get actor account
|
|
|
|
|
char* actor_uri = obj->actor;
|
|
|
|
|
if( !actor_uri ) {
|
|
|
|
@ -357,15 +345,46 @@ check_is_follower:
|
|
|
|
|
actor_account = account_from_uri_or_fetch( actor_uri );
|
|
|
|
|
if( !actor_account ) {
|
|
|
|
|
printf( "! Unable to fetch %s\n", actor_uri );
|
|
|
|
|
goto discard;
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
owner_account = account_from_id( owner_account_id );
|
|
|
|
|
|
|
|
|
|
if( account_does_follow( owner_account, actor_account->id ) ) {
|
|
|
|
|
account_followed = true;
|
|
|
|
|
goto success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
goto failed;
|
|
|
|
|
cleanup:
|
|
|
|
|
account_free(actor_account);
|
|
|
|
|
account_free(owner_account);
|
|
|
|
|
return result;
|
|
|
|
|
failed:
|
|
|
|
|
result = false;
|
|
|
|
|
goto cleanup;
|
|
|
|
|
success:
|
|
|
|
|
result = true;
|
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool route_create( struct ap_object* act )
|
|
|
|
|
{
|
|
|
|
|
struct status* s = NULL;
|
|
|
|
|
bool result = false;
|
|
|
|
|
|
|
|
|
|
// Requires an object
|
|
|
|
|
if( act->object.tag != apaot_activity ) {
|
|
|
|
|
printf( "TODO: fetch activity from %s\n", act->object.ref );
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
struct ap_object* obj = act->object.ptr;
|
|
|
|
|
|
|
|
|
|
if( !account_followed && !mentions_me ) {
|
|
|
|
|
// Does this activity have mention me
|
|
|
|
|
char owner_url[512];
|
|
|
|
|
snprintf( owner_url, sizeof(owner_url), "https://%s/owner/actor", g_server->domain );
|
|
|
|
|
|
|
|
|
|
bool mentions_me = mentions_account_url(obj,owner_url);
|
|
|
|
|
bool account_followed = account_actor_is_followed(obj);
|
|
|
|
|
if( !mentions_me && !account_followed ) {
|
|
|
|
|
// Discard without action
|
|
|
|
|
//printf( "Discarding create. account_followed=%c, mentions_me=%c\n", account_followed ? 'T' : 'F', mentions_me ? 'T' : 'F' );
|
|
|
|
|
goto discard;
|
|
|
|
@ -388,6 +407,7 @@ check_is_follower:
|
|
|
|
|
|
|
|
|
|
// TODO: create notification if user notifications are on or this is part of a watched conversation
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( mentions_me ) {
|
|
|
|
|
// Add me to mention lists
|
|
|
|
|
int id = owner_account_id;
|
|
|
|
@ -398,7 +418,7 @@ check_is_follower:
|
|
|
|
|
note->debug = 6;
|
|
|
|
|
note->type = nt_mention;
|
|
|
|
|
note->status_id = s->id;
|
|
|
|
|
note->account_id = actor_account->id;
|
|
|
|
|
note->account_id = s->account_id;
|
|
|
|
|
notification_save( note );
|
|
|
|
|
notification_free( note );
|
|
|
|
|
}
|
|
|
|
@ -406,14 +426,12 @@ check_is_follower:
|
|
|
|
|
// 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 );
|
|
|
|
|
status_add_to_timeline( s, s->account_id );
|
|
|
|
|
|
|
|
|
|
discard:
|
|
|
|
|
result = true;
|
|
|
|
|
goto cleanup;
|
|
|
|
|
cleanup:
|
|
|
|
|
account_free(actor_account);
|
|
|
|
|
account_free(owner_account);
|
|
|
|
|
status_free(s);
|
|
|
|
|
return result;
|
|
|
|
|
failed:
|
|
|
|
|