Get first mention handled

master
teknomunk 1 year ago
parent 11f1e90628
commit 9a3a759dd5

@ -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 );
}

@ -1 +1 @@
Subproject commit 5205ad49d932341983ef5c8ef5b0c09433f8e06f
Subproject commit c6cadd36b1b0e969b89d74683c525dd9ce69d0c5

@ -46,6 +46,7 @@ static struct json_object_field account_layout[] = {
{ "account_type", offsetof( struct account, account_type ), true, &json_field_enum, account_types_enum },
{ "account_url", offsetof( struct account, account_url ), true, &json_field_string },
{ "inbox", offsetof( struct account, inbox ), false, &json_field_string },
{ "note", offsetof( struct account, note ), false, &json_field_string },
{ NULL },
};
@ -241,6 +242,7 @@ void account_free( struct account* a )
free(a->account_url);
free(a->avatar.url);
free(a->avatar.static_url);
free(a->note);
free(a);
}
@ -262,11 +264,8 @@ void account_remove_follower( struct account* a, struct account* follower )
printf( "TODO: implement account_remove_follower()\n" );
}
// TODO: move to controller/view
void account_write_as_json( struct account* a, FILE* f )
{
#define RENDER
#include "src/model/account.json.inc"
#undef RENDER
#include "src/view/api/account.json.inc"
}

@ -29,6 +29,11 @@ struct account
char* static_url;
} avatar;
int followers_count;
int following_count;
char* note;
bool bot;
bool locked;
};

@ -81,7 +81,7 @@ struct ap_activity
bool sensitive;
struct {
struct tag** items;
struct ap_activity_tag** items;
int count;
} tags;

@ -74,7 +74,7 @@ struct json_object_field ap_activity_layout[] = {
{ "content", offsetof( struct ap_activity, content ), false, &json_field_string },
{ "conversation", offsetof( struct ap_activity, conversation ), false, &json_field_string },
{ "published", offsetof( struct ap_activity, published ), false, &json_field_date_time },
{ "sensitive", offsetof( struct ap_activity, sensitive ), false, &json_field_bool },
{ "sensitive", offsetof( struct ap_activity, sensitive ), false, &json_field_bool_or_null },
{ "source", offsetof( struct ap_activity, source ), false, &json_field_string },
{ "summary", offsetof( struct ap_activity, summary), false, &json_field_string },

@ -31,6 +31,7 @@ void ap_activity_tag_free( struct ap_activity_tag* tag )
static void* alloc()
{
struct ap_activity_tag* ptr = malloc(sizeof(struct ap_activity_tag));
printf( "alloc -> %p\n", ptr );
memset(ptr,0,sizeof(*ptr));
return ptr;
}

@ -14,8 +14,9 @@
#include <string.h>
static struct json_enum notification_type_enum[] = {
{ "favorite", 1 },
{ "follow", 2 },
{ "favorite", nt_favorite },
{ "follow", nt_follow },
{ "mention", nt_mention },
{ NULL, -1 },
};

@ -19,6 +19,7 @@ enum notification_type
{
nt_favorite = 1,
nt_follow = 2,
nt_mention = 3,
};
struct notification* notification_from_id( int id );

@ -13,6 +13,7 @@
switch(n->type) {
case nt_favorite: fprintf(f,"favourite"); break;
case nt_follow: fprintf(f,"follow"); break;
case nt_mention: fprintf(f,"mention"); break;
default: fprintf(f,"unknown-%d",n->type); break;
}; )"
}

@ -1,6 +1,7 @@
#include "status.h"
#include "model/account.h"
#include "model/ap/activity.h"
#include "json/json.h"
#include "json/layout.h"
@ -46,6 +47,26 @@ struct status* status_from_id( unsigned int id )
return s;
}
char* render_source( const char* src )
{
return strdup(src);
}
struct status* status_from_activity( struct ap_activity* act )
{
struct status* s;
s = malloc(sizeof(*s));
memset(s,0,sizeof(*s));
struct account* a = account_from_uri(act->actor);
s->account_id = a->id;
account_free(a);
s->content = render_source( act->source );
return s;
}
bool status_save_new( struct status* s )
{
int head = -1;

@ -24,6 +24,9 @@ struct status
struct status* status_from_id( unsigned int id );
struct ap_activity;
struct status* status_from_activity( struct ap_activity* act );
bool status_save_new( struct status* s );
void status_save( struct status* s );
void status_free( struct status* s );

@ -7,14 +7,14 @@
"display_name": "%s{ safe( a->display_name, a->handle )}",
"emojis": [],
"fields": [],
"followers_count": 0,
"following_count": 0,
"followers_count": %d{ a->followers_count },
"following_count": %d{ a->following_count },
"fqn": "%s{a->handle}%( if( a->server ) { )@%s{a->server}%( } )",
"header": "https://pl.polaris-1.work/images/banner.png",
"header_static": "https://pl.polaris-1.work/images/banner.png",
"id": "%d{ a->id }",
"locked": %s{b(a->locked)},
"note": "Humble twitter aggregator for all those banned from it, feel free so steal my stuff and post it anywhere almost all of my stuff is stolen from twitter anyways, also im not Kinochet<br/>",
"note": "%s{a->note}",
"pleroma": {
"accepts_chat_messages": true,
"also_known_as": [],
Loading…
Cancel
Save