Start source rendering

master
teknomunk 1 year ago
parent f4b019eff0
commit 7b35934e18

@ -1 +1 @@
Subproject commit c5b4f6e732131995377c1a40b9fba1f86845e519
Subproject commit 3bd10ea74624264342c02976abc91a84f87d88ed

@ -127,6 +127,17 @@ struct account* account_from_uri( const char* uri )
return account_from_id( account_id );
}
struct account* account_from_webfinger( const char* handle )
{
printf( "account_from_webfinger( %s )\n", handle );
int id;
if( !hash_index_get( "data/accounts/webfinger", handle, &id ) ) {
printf( "! No account id for %s\n", handle );
return NULL;
}
return account_from_id(id);
}
void account_sync_from_acitvity_pub( unsigned int account_id )
{

@ -40,6 +40,7 @@ struct account
struct account* account_from_id( int id );
struct account* account_from_uri( const char* uri );
struct account* account_from_webfinger( const char* handle );
struct account* account_fetch_from_uri( const char* uri );
struct account* account_new();
void account_free( struct account* a );

@ -19,7 +19,8 @@ static struct json_object_field status_layout[] = {
{ "account_id", offsetof( struct status, account_id ), true, &json_field_integer },
{ "url", offsetof( struct status, url ), false, &json_field_string },
{ "sensitive", offsetof( struct status, sensitive ), true, &json_field_bool },
{ "content", offsetof( struct status, content ), true, &json_field_string },
{ "source", offsetof( struct status, source ), false, &json_field_string },
{ "content", offsetof( struct status, source ), false, &json_field_string },
{ "media", offsetof( struct status, media ), false, &json_field_array_of, &json_field_string },
//{ "reacts", offsetof( struct status, reacts ), false, &json_field_array_of, &status_react_type },
{ NULL }
@ -47,6 +48,10 @@ struct status* status_from_id( unsigned int id )
return NULL;
}
if( !s->source ) {
s->source = strdup("");
}
return s;
}
struct status* status_new_system_unfollow( int account_id )
@ -96,7 +101,8 @@ struct status* status_from_activity( struct ap_activity* act )
s->account_id = a->id;
account_free(a);
s->content = status_render_source( act->source );
s->source = strdup(act->source);
//s->content = status_render_source(s);
s->url = strdup( act->id );
return s;

@ -9,7 +9,8 @@ struct status
int account_id;
char* url;
char* content;
char* content; // Deprecate from file system data and render when loading
char* source;
bool sensitive;
struct {
@ -36,5 +37,5 @@ void status_free( struct status* s );
void status_add_react( struct status* s, const char* react );
char* status_render_source( const char* src );
char* status_render_source( struct status* s );

@ -1,10 +1,64 @@
#include "model/status.h"
#include "model/account.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <strings.h>
#include <ctype.h>
char* status_render_source( const char* src )
char* status_render_source( struct status* s )
{
return strdup(src);
if( s->content ) {
goto done;
}
char* result = NULL;
size_t size = 0;
FILE* f = open_memstream(&result,&size);
for( char* i = s->source; *i; ++i ) {
// Handle URLs
if( 0 == strncmp( i, "https://", 8 ) ) {
char* start = i;
while( *i && !index(" ,",*i) ) ++i;
char* url = strndup( start, i - start );
fprintf( f, "<a href='%s' rel='ugc'>%s</a>", url, url );
free(url);
} else if( isalpha(i[1]) && *i == '@' ) {
char* start = i;
while( *i && !index(" ,",*i) ) ++i;
char* handle = strndup( start, i - start );
struct account* user = account_from_webfinger( &handle[1] );
if( user ) {
fprintf( f,
"<span class='h-card'>"
"<a class='u-url mention' href='%s' rel='ugc'>"
"@<span>%s</span>"
"</a>"
"</span>",
user->account_url, user->handle
);
account_free(user);
} else {
fprintf( f, "%s", handle );
}
free(handle);
}
fputc( *i, f );
}
fputc( '\0', f );
fclose(f);
s->content = result;
done:
return s->content;
}

@ -1,9 +1,9 @@
{
"account": %( api_account_write_as_json(account,f); ),
"content": %( json_write_string(f,status_render_source(s)); ),
"application": null,
"bookmarked": false,
"card": null,
"content": %( json_write_string(f,s->content); ),
"created_at": "2022-12-12T02:52:24.000Z",
"emojis": [],
"favourited": false,

Loading…
Cancel
Save