@ -7,6 +7,7 @@
// Model
# include "model/server.h"
# include "model/status.h"
# include "model/account.h"
# include "model/notification.h"
# include "model/ap/activity.h"
@ -139,11 +140,87 @@ static bool route_undo_activity( struct ap_activity* act )
return false ;
}
static bool route_follower_post ( struct ap_activity * act )
{
// TODO: check if the activity is by a follower
// Create local status
// Create notification
return false ;
}
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 ) ;
// 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 bool route_create ( struct ap_activity * act )
{
return route_follower_post ( act )
| | route_mention ( act ) ;
return false ;
}
static bool route_activity ( struct ap_activity * act )
{
printf ( " Handling %s \n " , act - > id ) ;
switch ( act - > type ) {
case apat_undo : return route_undo_activity ( act ) ;
case apat_follow : return route_follow ( act ) ;
case apat_create : return route_create ( act ) ;
default :
printf ( " Unhandled activity type: %d \n " , act - > type ) ;
}