Change order of processing status sync

master
teknomunk 6 months ago
parent afb6afd0ee
commit ce124ae8e9

@ -381,6 +381,7 @@ bool status_sync_from_activity_pub( struct status* s, struct ap_object* act )
goto failed; goto failed;
} }
// Handle post visibility
bool is_public = false; bool is_public = false;
for( int i = 0; i < act->to.count; ++i ) { for( int i = 0; i < act->to.count; ++i ) {
if( 0 == strcmp( act->to.items[i], "https://www.w3.org/ns/activitystreams#Public" ) ) { if( 0 == strcmp( act->to.items[i], "https://www.w3.org/ns/activitystreams#Public" ) ) {
@ -399,6 +400,7 @@ bool status_sync_from_activity_pub( struct status* s, struct ap_object* act )
s->visibility = status_visibility_direct; s->visibility = status_visibility_direct;
} }
// Setup initial settings
s->account_id = a->id; s->account_id = a->id;
s->published = act->published; s->published = act->published;
s->remote = true; s->remote = true;
@ -408,42 +410,47 @@ bool status_sync_from_activity_pub( struct status* s, struct ap_object* act )
s->spoiler_text = strdup(act->summary); s->spoiler_text = strdup(act->summary);
} }
// Force this status to have an id // Copy over post URL
status_save_new(s); free(s->url);
s->url = strdup( act->id );
if( act->in_reply_to ) {
printf( "Status %d is reply to %s\n", s->id, act->in_reply_to );
int parent_id = 0;
struct status* parent = status_from_uri_or_fetch( act->in_reply_to ); // Populate source string
//struct status* parent = status_from_uri_or_stub( act->in_reply_to ); free(s->source);
if( parent ) { s->source = safe_strdup(act->source.content);
parent_id = parent->id;
status_save(parent);
status_free(parent);
}
if( parent_id ) { // Populate content
status_make_reply_to( s, parent_id ); free(s->content);
s->in_reply_to = parent_id; s->content = safe_strdup( act->content.content );
}
//printf( "Status %d has been marked as a reply to %d (%s)\n", s->id, parent_id, act->in_reply_to ); //// Handle Media
// Erase existing media
for( int i = 0; i < s->media.count; ++i ) {
free( s->media.items[i] );
} }
if( act->quote_url ) { free(s->media.items);
int parent_id = 0; memset(&s->media,0,sizeof(s->media));
struct status* parent = status_from_uri_or_fetch( act->quote_url ); for( int i = 0; i < s->media2.count; ++i ) {
if( parent ) { media_free( s->media2.items[i] );
parent_id = parent->id; }
status_save(parent); free(s->media2.items);
status_free(parent); memset(&s->media2,0,sizeof(s->media2));
}
if( parent_id ) { // Recreate the media field
status_make_quote_of( s, parent_id ); for( int i = 0; i < act->attachments.count; ++i ) {
struct ap_object* att = act->attachments.items[i];
if( att && att->url.count == 1 ) {
struct media* media = media_new();
media->remote_url = strdup( att->url.items[0].ref );
if( att->media_type ) {
media->content_type = strdup(att->media_type);
}
array_append( &s->media2, sizeof(char*), &media );
} }
} }
// Handle Polls
// TODO: move this out to another function to use same code for any_of and one_of // TODO: move this out to another function to use same code for any_of and one_of
if( act->one_of.count > 0 ) { if( act->one_of.count > 0 ) {
if( !s->poll ) { if( !s->poll ) {
@ -475,6 +482,8 @@ bool status_sync_from_activity_pub( struct status* s, struct ap_object* act )
sync_poll( s, &act->any_of ); sync_poll( s, &act->any_of );
} }
// Translate emoji
for( int i = 0; i < s->emoji.count; ++i ) { for( int i = 0; i < s->emoji.count; ++i ) {
emoji_free( s->emoji.items[i] ); emoji_free( s->emoji.items[i] );
} }
@ -505,42 +514,45 @@ bool status_sync_from_activity_pub( struct status* s, struct ap_object* act )
} }
} }
free(s->source); // Force this status to have an id
s->source = safe_strdup(act->source.content); status_save_new(s);
status_add_to_timeline( s, a->id );
free(s->url); // Handle InReplyTo and QuoteURL after saving to timeline, which could take a while
s->url = strdup( act->id ); if( act->in_reply_to ) {
printf( "Status %d is reply to %s\n", s->id, act->in_reply_to );
int parent_id = 0;
s->content = safe_strdup( act->content.content ); struct status* parent = status_from_uri_or_fetch( act->in_reply_to );
//struct status* parent = status_from_uri_or_stub( act->in_reply_to );
if( parent ) {
parent_id = parent->id;
status_save(parent);
status_free(parent);
}
// Erase existing media if( parent_id ) {
for( int i = 0; i < s->media.count; ++i ) { status_make_reply_to( s, parent_id );
free( s->media.items[i] ); s->in_reply_to = parent_id;
}
//printf( "Status %d has been marked as a reply to %d (%s)\n", s->id, parent_id, act->in_reply_to );
} }
free(s->media.items); if( act->quote_url ) {
memset(&s->media,0,sizeof(s->media)); int parent_id = 0;
for( int i = 0; i < s->media2.count; ++i ) { struct status* parent = status_from_uri_or_fetch( act->quote_url );
media_free( s->media2.items[i] ); if( parent ) {
} parent_id = parent->id;
free(s->media2.items); status_save(parent);
memset(&s->media2,0,sizeof(s->media2)); status_free(parent);
}
// Recreate the media field if( parent_id ) {
for( int i = 0; i < act->attachments.count; ++i ) { status_make_quote_of( s, parent_id );
struct ap_object* att = act->attachments.items[i];
if( att && att->url.count == 1 ) {
struct media* media = media_new();
media->remote_url = strdup( att->url.items[0].ref );
if( att->media_type ) {
media->content_type = strdup(att->media_type);
}
array_append( &s->media2, sizeof(char*), &media );
} }
} }
status_save(s); status_save(s);
status_add_to_timeline( s, a->id );
result = true; result = true;
cleanup: cleanup:
account_free(a); account_free(a);

Loading…
Cancel
Save