@ -4,6 +4,7 @@
# include "http/server/request.h"
# include "json/json.h"
# include "ffdb/fs_list.h"
# include "collections/array.h"
// Model
# include "model/server.h"
@ -116,6 +117,10 @@ static struct status* lookup_object_status( struct ap_activity* act, int* error
s = status_from_uri ( act - > object . ref ) ;
if ( ! s ) {
s = status_fetch_from_uri ( act - > object . ref ) ;
if ( ! s ) {
* error = error_lookup_failed ;
return NULL ;
}
status_save_new ( s ) ;
}
break ;
@ -183,6 +188,50 @@ static bool route_emoji_react( struct ap_activity* act )
return true ;
}
static bool route_update_Person ( struct ap_activity * act )
{
bool result = false ;
struct account * a = account_fetch_from_uri ( act - > object . ptr - > id ) ;
if ( ! a ) { return true ; } // We don't have this user locally, we can safely discard
if ( ! account_sync_from_activity ( a , act - > object . ptr ) ) { goto failed ; }
account_save ( a ) ;
result = true ;
cleanup :
account_free ( a ) ;
return result ;
failed :
result = false ;
goto cleanup ;
}
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 false ; }
} else if ( act - > object . ptr - > type = = apat_person ) {
return route_update_Person ( act ) ;
} else {
return false ;
}
} else if ( act - > object . tag = = apaot_ref ) {
s = status_from_uri ( act - > object . ref ) ;
if ( ! s ) { return false ; }
}
status_sync_from_uri ( s , s - > url ) ;
status_save ( s ) ;
status_free ( s ) ;
return true ;
}
static bool route_create ( struct ap_activity * act )
{
struct status * s = NULL ;
@ -207,6 +256,7 @@ static bool route_create( struct ap_activity* act )
if ( tag - > type ! = aptag_mention ) { continue ; }
if ( 0 = = strcmp ( tag - > href , owner_url ) ) {
mentions_me = true ;
int id = owner_account_id ;
goto check_is_follower ;
}
}
@ -243,8 +293,13 @@ 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 ;
array_append ( & s - > mentions , sizeof ( id ) , & id ) ;
// Create notification
struct notification * note = notification_new ( ) ;
note - > debug = 6 ;
note - > type = nt_mention ;
note - > status_id = s - > id ;
note - > account_id = actor_account - > id ;
@ -288,6 +343,7 @@ bool route_activity( struct ap_activity* act )
case apat_announce : return route_announce ( act ) ;
case apat_add : return route_add ( act ) ;
case apat_emoji_react : return route_emoji_react ( act ) ;
case apat_update : return route_update ( act ) ;
default :
printf ( " Unhandled activity type: %d \n " , act - > type ) ;
}