Add backoff to outbox processing, get replies federating, get emoji notifications working in Husky, get local statuses not in the uri index looking up by uri

master
teknomunk 1 year ago
parent 04c456e12d
commit a52a9b8c89

@ -36,6 +36,7 @@ static bool process_envelope( int id )
}
if( env->sent ) { return false; }
if( env->retry_after > time(NULL) ) { return false; }
printf( "Processing outbox/%d.json\n", id );
printf( "account_id=%d\n", env->account_id );
@ -116,10 +117,15 @@ static bool process_envelope( int id )
env->sent = true;
outbox_envelope_save(env);
goto discard;
} else {
printf( "\nServer returned status code %d\n", status_code );
if( env->retry_after ) {
env->retries += 1;
}
env->retry_after = time(NULL) + 60 * ( env->retries + 1 ) * ( env->retries + 1 );
outbox_envelope_save(env);
}
printf( "\nServer returned status code %d\n", status_code );
goto failed;
cleanup:
@ -166,7 +172,7 @@ void process_outbox()
if( !activity ) {
fflush(stdout);
sleep(10);
sleep(1);
}
}
}

@ -1 +1 @@
Subproject commit a71ffab0d0131cac8904dff715a1fc863ef07c48
Subproject commit 9a64b30b973aa8148855edb16bdd3d806366ff76

@ -35,6 +35,8 @@ struct ap_activity* ap_activity_dup( struct ap_activity* act )
new_act->actor = strdup(act->actor);
new_act->published = act->published;
new_act->in_reply_to = safe_strdup( act->in_reply_to );
new_act->source.content = safe_strdup(act->source.content);
new_act->source.mime_type = safe_strdup(act->source.mime_type);
@ -95,6 +97,7 @@ void ap_activity_free_composite( struct ap_activity* act )
free(act->source.content);
free(act->conversation);
free(act->summary);
free(act->in_reply_to);
for( int i = 0; i < act->tags.count; ++i ) {
ap_activity_tag_free(act->tags.items[i]);
@ -332,7 +335,9 @@ struct ap_activity* ap_activity_create_note( struct status* s )
act->source.content = strdup(s->source);
act->content.content = strdup(status_render_source(s));
if( s->in_reply_to ) {
//act->in_reply_to = TBD
struct status* s_in_reply_to = status_from_id( s->in_reply_to );
act->in_reply_to = strdup( s_in_reply_to->url );
status_free(s_in_reply_to);
}
char* str = strdup("https://www.w3.org/ns/activitystreams#Public");
array_append( &act->to, sizeof(str), &str );

@ -94,6 +94,7 @@ struct ap_activity
char* attributed_to;
char* target;
char* in_reply_to;
struct ap_activity_source content;

@ -102,6 +102,12 @@ struct json_object_field ap_activity_layout[] = {
.type = &ap_activity_source_type
},
JSON_FIELD_STRING(summary,false),
{
.key = "inReplyTo",
.offset = offsetof( OBJ_TYPE, in_reply_to ),
.required = false,
.type = &json_field_string
},
{
.key = "tag",

@ -12,6 +12,8 @@
static struct json_object_field layout[] = {
JSON_FIELD_BOOL( use_shared_inbox, false ),
JSON_FIELD_BOOL( sent, false ),
JSON_FIELD_INTEGER( retries, false ),
JSON_FIELD_DATETIME( retry_after, false ),
{
.key = "account",
.offset = offsetof( struct outbox_envelope, account_id ),

@ -1,6 +1,7 @@
#pragma once
#include <stdbool.h>
#include <time.h>
struct outbox_envelope
{
@ -9,6 +10,8 @@ struct outbox_envelope
int account_id;
bool use_shared_inbox;
bool sent;
time_t retry_after;
int retries;
};
struct outbox_envelope* outbox_envelope_new();

@ -9,6 +9,9 @@
%( if(s) { )
"status": %( api_status_write_as_json(s,f); ),
%( } )
%( if( n->type == nt_react ) { )
"emoji": %( json_write_string( f, n->react ); ),
%( } )
"type": "%(
switch(n->type) {
case nt_favorite: fprintf(f,"favourite"); break;
@ -17,6 +20,7 @@
case nt_unfollow:
case nt_block:
case nt_mention: fprintf(f,"mention"); break;
case nt_react: fprintf(f,"pleroma:emoji_reaction"); break;
default: fprintf(f,"unknown-%d",n->type); break;
}; )"
}

@ -2,6 +2,7 @@
#include "status.h"
#include "status/react.h"
#include "model/server.h"
#include "model/account.h"
#include "model/ap/activity.h"
#include "model/notification.h"
@ -79,6 +80,10 @@ struct status* status_from_id( unsigned int id )
s->source = strdup("");
}
if( !s->remote && !s->url ) {
s->url = aformat( "https://%s/note/%d", g_server_name, s->id );
}
return s;
}
struct status* status_new_repost( struct status* s, struct account* a )
@ -94,8 +99,32 @@ struct status* status_new_repost( struct status* s, struct account* a )
status_save_new(repost);
return repost;
}
static struct status* status_from_local_uri( const char* uri )
{
if( 0 != strncmp( "https://", uri, 8 ) ) { return NULL; }
uri += 8;
int server_name_length = strlen(g_server_name);
if( 0 != strncmp( g_server_name, uri, server_name_length ) ) { return NULL; }
uri += server_name_length;
if( 0 != strncmp( "/note/", uri, 6 ) ) { return NULL; }
uri += 6;
// Note: zero is never a valid status id
int id = atoi(uri);
if( id == 0 ) { return NULL; }
return status_from_id(id);
}
struct status* status_from_uri( const char* uri )
{
// Check for local
struct status* s = status_from_local_uri( uri );
if( s ) { return s; }
int id = -1;
if( !hash_index_get( "data/statuses/uri", uri, &id ) ) { return NULL; }

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

Loading…
Cancel
Save