Add status_add_to_timeline, fix reacts field in json layout table

master
teknomunk 1 year ago
parent 30feff8246
commit 783ac01a20

@ -7,7 +7,6 @@
#include "model/status.h"
#include "model/status/react.h"
#include "model/account.h"
#include "model/timeline.h"
#include <stdio.h>
#include <stdlib.h>
@ -116,11 +115,10 @@ bool handle_post( struct http_request* req, struct account* a )
status_save(s);
// Add to owner timeline, public timeline and home timelines
for( int i = 0; i < 3; ++i ) {
struct timeline* tl = timeline_from_id(i);
timeline_add_post( tl, s );
timeline_free(tl);
}
status_add_to_timeline( s, a->id );
status_add_to_timeline( s, public_timeline_id );
status_add_to_timeline( s, home_timeline_id );
//status_add_post_to_timeline( s, federated_timeline_id );
http_request_send_headers( req, 200, "application/json", true );
FILE* f = http_request_get_response_body(req);

@ -13,7 +13,7 @@
#include "model/ap/activity.h"
#include "model/ap/inbox_envelope.h"
#include "model/crypto/http_sign.h"
#include "model/timeline.h"
//#include "model/timeline.h"
// Stdlib
#include <stdio.h>
@ -123,13 +123,6 @@ static bool route_undo_activity( struct ap_activity* act )
return false;
}
void add_post_to_timeline( int timeline_id, struct status* s )
{
struct timeline* tl = timeline_from_id(timeline_id);
timeline_add_post( tl, s );
timeline_free(tl);
}
static bool route_follower_post( struct ap_activity* act )
{
// Requires an object
@ -154,9 +147,9 @@ static bool route_follower_post( struct ap_activity* act )
status_save_new(s);
// Add to timelines
add_post_to_timeline( 1, s );
add_post_to_timeline( 2, s );
add_post_to_timeline( actor_account->id, s );
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
@ -174,7 +167,7 @@ static bool route_mention( struct ap_activity* act )
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 );
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; }
@ -199,10 +192,8 @@ does_mention:
status_save_new(s);
// Add status to account timeline
struct timeline* tl = timeline_from_id( mentioner->id );
printf( "tl->id=%d, s->id=%d\n", tl->id, s->id );
timeline_add_post(tl,s);
timeline_free(tl);
status_add_to_timeline( s, mentioner->id );
status_add_to_timeline( s, owner_account_id );
// Create notification
struct notification* note = notification_new();
@ -272,8 +263,10 @@ static bool route_emoji_react( struct ap_activity* act )
static bool route_create( struct ap_activity* act )
{
return route_follower_post(act)
|| route_mention(act);
return
route_mention(act)
|| route_follower_post(act)
;
return false;
}

@ -7,6 +7,8 @@ struct crypto_keys;
enum {
owner_account_id = 0,
home_timeline_id = 1,
public_timeline_id = 2,
};
enum account_type

@ -5,6 +5,7 @@
#include "model/account.h"
#include "model/ap/activity.h"
#include "model/notification.h"
#include "model/timeline.h"
// Submodules
#include "json/json.h"
@ -34,7 +35,7 @@ static struct json_object_field status_layout[] = {
JSON_FIELD_INTEGER( root_status_id, false ),
JSON_FIELD_ARRAY_OF_STRINGS( media, false ),
JSON_FIELD_ARRAY_OF_TYPE( media, false, status_react_type ),
JSON_FIELD_ARRAY_OF_TYPE( reacts, false, status_react_type ),
JSON_FIELD_ARRAY_OF_INTS( likes, false ),
JSON_FIELD_ARRAY_OF_INTS( replies, false ),
@ -194,6 +195,13 @@ void status_free( struct status* s )
free(s);
}
void status_add_to_timeline( struct status* s, int timeline_id )
{
struct timeline* tl = timeline_from_id(timeline_id);
timeline_add_post( tl, s );
timeline_free(tl);
}
void status_make_reply_to( struct status* s, int in_reply_to_id )
{
// Add this status to the other

@ -63,6 +63,8 @@ void status_free( struct status* s );
void status_make_reply_to( struct status* s, int in_reply_to );
void status_add_to_timeline( struct status* s, int timeline_id );
void status_add_react( struct status* s, const char* react, struct account* a );
void status_remove_react( struct status* s, const char* react, struct account* a );
void status_add_like( struct status* s, struct account* a );

Loading…
Cancel
Save