Implement emoji for local posts

master
teknomunk 1 year ago
parent c66f92924d
commit aad7a1f82f

@ -36,11 +36,9 @@ bool route_custom_emojis( struct http_request* req )
char* remain = NULL;
char* shortcode = strtok_r(filename, ".", &remain );
struct emoji e;
e.shortcode = shortcode;
e.url = aformat( "https://%s/emoji/%s", g_server_name, shortcode );
api_Emoji_write( &e, f, 1 );
free(e.url);
struct emoji* e = emoji_from_shortcode( shortcode );
api_Emoji_write( e, f, 1 );
emoji_free(e);
free(filename);
first = false;

@ -1,6 +1,9 @@
#include "emoji.h"
#include "json/layout.h"
#include "format.h"
#include "model/server.h"
#include <dirent.h>
#include <string.h>
@ -32,6 +35,20 @@ char* filename_for_shortcode( const char* shortcode )
return NULL;
}
struct emoji* emoji_from_shortcode( const char* shortcode )
{
char* filename = filename_for_shortcode( shortcode );
if( !filename ) { return NULL; }
struct emoji* e;
e = malloc(sizeof(*e));
memset(e,0,sizeof(*e));
e->shortcode = strdup(shortcode);
e->url = aformat( "https://%s/emoji/%s", g_server_name, shortcode );
return e;
}
void emoji_free( struct emoji* e )
{
if( !e ) { return; }

@ -10,6 +10,8 @@ struct emoji
char* url;
};
struct emoji* emoji_from_shortcode( const char* shortcode );
void emoji_free( struct emoji* e );
extern struct json_object_field emoji_layout[];

@ -1,6 +1,9 @@
#include "model/status.h"
#include "collections/array.h"
#include "model/account.h"
#include "model/emoji.h"
#include <string.h>
#include <stdlib.h>
@ -52,6 +55,28 @@ char* status_render_source( struct status* s )
fprintf( f, "%s", handle );
}
free(handle);
} else if( *i == ':' ) {
// Emoji
++i;
char* start = i;
while( *i && !index(" ,:",*i) ) ++i;
char* shortcode = strndup( start, i - start );
// Check if shortcode is already present in status
for( int i = 0; i < s->emoji.count; ++i ) {
struct emoji* e = s->emoji.items[i];
if( 0 == strcmp( e->shortcode, shortcode ) ) { goto already_has_emoji; }
}
struct emoji* e = emoji_from_shortcode( shortcode );
if( e ) {
array_append( &s->emoji, sizeof(e), &e );
}
already_has_emoji:
fprintf( f, ":%s", shortcode );
free(shortcode);
} else if( *i == '\n' ) {
fprintf( f, "<br/>" );
continue;

Loading…
Cancel
Save