Change order of processing status sync

master
teknomunk 5 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;
}
// Handle post visibility
bool is_public = false;
for( int i = 0; i < act->to.count; ++i ) {
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;
}
// Setup initial settings
s->account_id = a->id;
s->published = act->published;
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);
}
// Force this status to have an id
status_save_new(s);
// Copy over post URL
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 );
//struct status* parent = status_from_uri_or_stub( act->in_reply_to );
if( parent ) {
parent_id = parent->id;
status_save(parent);
status_free(parent);
}
// Populate source string
free(s->source);
s->source = safe_strdup(act->source.content);
if( parent_id ) {
status_make_reply_to( s, parent_id );
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 );
// Populate content
free(s->content);
s->content = safe_strdup( act->content.content );
//// Handle Media
// Erase existing media
for( int i = 0; i < s->media.count; ++i ) {
free( s->media.items[i] );
}
if( act->quote_url ) {
int parent_id = 0;
free(s->media.items);
memset(&s->media,0,sizeof(s->media));
struct status* parent = status_from_uri_or_fetch( act->quote_url );
if( parent ) {
parent_id = parent->id;
status_save(parent);
status_free(parent);
}
for( int i = 0; i < s->media2.count; ++i ) {
media_free( s->media2.items[i] );
}
free(s->media2.items);
memset(&s->media2,0,sizeof(s->media2));
if( parent_id ) {
status_make_quote_of( s, parent_id );
// Recreate the media field
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
if( act->one_of.count > 0 ) {
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 );
}
// Translate emoji
for( int i = 0; i < s->emoji.count; ++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);
s->source = safe_strdup(act->source.content);
// Force this status to have an id
status_save_new(s);
status_add_to_timeline( s, a->id );
free(s->url);
s->url = strdup( act->id );
// Handle InReplyTo and QuoteURL after saving to timeline, which could take a while
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
for( int i = 0; i < s->media.count; ++i ) {
free( s->media.items[i] );
if( parent_id ) {
status_make_reply_to( s, parent_id );
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);
memset(&s->media,0,sizeof(s->media));
if( act->quote_url ) {
int parent_id = 0;
for( int i = 0; i < s->media2.count; ++i ) {
media_free( s->media2.items[i] );
}
free(s->media2.items);
memset(&s->media2,0,sizeof(s->media2));
struct status* parent = status_from_uri_or_fetch( act->quote_url );
if( parent ) {
parent_id = parent->id;
status_save(parent);
status_free(parent);
}
// Recreate the media field
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 );
if( parent_id ) {
status_make_quote_of( s, parent_id );
}
}
status_save(s);
status_add_to_timeline( s, a->id );
result = true;
cleanup:
account_free(a);

Loading…
Cancel
Save