Fill out Status response fields for reply and to further match Pleroma, pull mentions and parent posts for replies

master
teknomunk 1 year ago
parent 91f821ce8e
commit 80a0278495

@ -43,11 +43,14 @@ bool route_statuses_1f( struct http_request* req )
bool result = false;
struct status* s = NULL;
if( http_request_route_term( req, "" ) && http_request_route_method( req, "POST" ) ) {
struct account* owner = account_from_id(owner_account_id);
bool res = handle_post(req, owner);
account_free(owner);
return res;
if( http_request_route_term( req, "" ) ) {
if( http_request_route_method( req, "POST" ) ) {
struct account* owner = account_from_id(owner_account_id);
bool res = handle_post(req, owner);
account_free(owner);
return res;
}
return false;
}
if( !http_request_route( req, "/" ) ) { return false; }

@ -30,6 +30,7 @@ static bool process_envelope( struct outbox_envelope* env )
if( env->sent ) { return false; }
if( env->retry_after > time(NULL) ) { return false; }
if( env->account_id == 0 ) { goto discard; }
printf( "Processing outbox/%d.json\n", env->id );
printf( "account_id=%d\n", env->account_id );
@ -123,8 +124,6 @@ static bool process_envelope( struct outbox_envelope* env )
if( status_code == 200 || status_code == 202 ) {
printf( "Submitted successfully\n" );
env->sent = true;
outbox_envelope_save(env);
goto discard;
} else {
printf( "\nServer returned status code %d\n", status_code );
@ -134,7 +133,7 @@ static bool process_envelope( struct outbox_envelope* env )
if( env->retries > 10 ) {
// Force discard after 10 delivery attempts
// TODO: change this to a configuration option
env->sent = true;
goto discard;
}
env->retry_after = time(NULL) + 60 * ( env->retries + 1 ) * ( env->retries + 1 );
outbox_envelope_save(env);
@ -155,6 +154,8 @@ failed:
result = false;
goto cleanup;
discard:
env->sent = true;
outbox_envelope_save(env);
result = true;
goto cleanup;
}

@ -1 +1 @@
Subproject commit 4c171f6f63f37156b830cb71f8001ad803411f68
Subproject commit 93740b63638063a131736b1394bc99f957e24f39

@ -1 +1 @@
Subproject commit 3fd94eba01d4cc6eca62c74272640883f94a7849
Subproject commit c2f69469881dbc5b4a4cd976f5d58d7700f83ccb

@ -180,6 +180,23 @@ bool status_sync_from_activity_pub( struct status* s, struct ap_activity* act )
s->remote = true;
s->stub = false;
if( act->in_reply_to ) {
struct status* parent = status_from_uri_or_fetch( act->in_reply_to );
s->in_reply_to = parent->id;
status_free(parent);
}
for( int i = 0; i < act->tags.count; ++i ) {
struct ap_activity_tag* tag = act->tags.items[i];
if( tag->type == aptag_mention ) {
struct account* a = account_from_uri_or_fetch( tag->href );
if( a ) {
int item = a->id;
array_append( &s->mentions, sizeof(item), &item );
account_free(a);
}
}
}
s->source = safe_strdup(act->source.content);
s->url = strdup( act->id );
if( !s->source ) {

@ -54,6 +54,7 @@ char* status_render_source( struct status* s )
free(handle);
} else if( *i == '\n' ) {
fprintf( f, "<br/>" );
continue;
} else if( *i == '\r' ) {
// Ignore
}

@ -4,6 +4,7 @@
#include "json/layout.h"
#include "format.h"
#include "model/server.h"
#include "model/status.h"
#include "model/status/react.h"
#include "model/account.h"
@ -35,7 +36,7 @@ static bool write_in_reply_to( struct json_writer* jw, const char* field_name, v
json_write_indention(jw);
json_write_field_name(jw,"in_reply_to_id");
fprintf( jw->f, "%d", in_reply_to->id );
fprintf( jw->f, "\"%d\"", in_reply_to->id );
} else {
json_write_field_name(jw,"in_reply_to_account_id");
fprintf( jw->f, "null" );
@ -225,6 +226,32 @@ bool render_source_callback( void* field_data, bool is_read, char** res )
return true;
}
bool in_reply_to_account_acct_callback( void* field_data, bool is_read, char** res )
{
struct status* s = field_data;
if( s->mentions.count > 0 ) {
struct account* a = account_from_id( s->mentions.items[0] );
*res = aformat( "%s@%s", a->handle, a->server );
account_free(a);
return true;
}
*res = strdup("");
return false;
}
bool context_url_callback( void* field_data, bool is_read, char** res )
{
struct status* s = field_data;
if( !is_read ) {
*res = aformat( "https://%s/contexts/%d", g_server_name, s->root_status_id );
}
}
bool is_local_callback( void* field_data, bool is_read, bool* val )
{
struct status* s = field_data;
*val = false;
return true;
}
#define OBJ_TYPE struct status
static struct json_object_field content_layout[] = {
{
@ -242,6 +269,13 @@ static struct json_object_field pleroma_layout[] = {
.type = &json_field_object_composite,
.composite_layout = content_layout,
},
JSON_FIELD_FIXED_NULL( content_type ),
{
.key = "context",
.offset = 0,
.type = &json_field_callback_string,
.string_callback = context_url_callback,
},
{
.key = "conversation_id",
.offset = offsetof( OBJ_TYPE, root_status_id ),
@ -255,19 +289,25 @@ static struct json_object_field pleroma_layout[] = {
.type = &json_field_array_of,
.array_item_type = &EmojiReact_type,
},
JSON_FIELD_FIXED_NULL( event ),
JSON_FIELD_FIXED_NULL( expires_at ),
/*%(
if( in_reply_to_account ) { )
"in_reply_to_account_acct": "%s{in_reply_to_account->handle}@%s{in_reply_to_account->server}",
"local": %s{ s->remote ? "false" : "true" },
"parent_visible": true,%(
} else { )
"in_reply_to_account_acct": null,
"local": %s{ s->remote ? "false" : "true" },
"parent_visible": false,%(
} )
*/
{
.key = "in_reply_to_account_acct",
.offset = 0,
.type = &json_field_callback_string,
.string_callback = in_reply_to_account_acct_callback,
},
{
.key = "local",
.offset = 0,
.type = &json_field_bool_callback,
.bool_callback = is_local_callback,
},
JSON_FIELD_FIXED_BOOL( parent_visible, true ),
JSON_FIELD_FIXED_NULL( pinned_at ),
JSON_FIELD_FIXED_NULL( quote ),
JSON_FIELD_FIXED_NULL( quote_url ),
JSON_FIELD_FIXED_BOOL( quote_visible, false ),
/*
"spoiler_text": {
"text/plain": ""

Loading…
Cancel
Save