Pull emoji from account AP data and provide via api to clients

master
teknomunk 1 year ago
parent a5795f23bb
commit bbdbf937ca

@ -1 +1 @@
Subproject commit f89ea12f8cea8e5ee96e0c7eba0891b4a0829884
Subproject commit 934dcd3d7f92975680b7c1a4574a86010417c7c7

@ -1 +1 @@
Subproject commit 1b383544af9f221777c2de40c684e04af2a65393
Subproject commit 4acc7829bf2e27a2c98695ce622dbfe9d4cc6013

@ -99,6 +99,19 @@ static struct json_object_field account_layout[] = {
.type = &json_field_array_of,
.array_item_type = &string_pair_type,
},
{
.key = "emoji",
.offset = offsetof(OBJ_TYPE, emoji),
.required = false,
.type = &json_field_array_of,
.array_item_type = &string_pair_type,
},
{
.key = "pinned",
.offset = offsetof(OBJ_TYPE,pinned_posts),
.type = &json_field_array_of,
.array_item_type = &json_field_integer,
},
JSON_FIELD_INTEGER( follow_activity, false ),
JSON_FIELD_STRING( account_url, true ),
JSON_FIELD_END,
@ -368,6 +381,13 @@ void account_free( struct account* a )
}
free( a->fields.items );
for( int i = 0; i < a->emoji.count; ++i ) {
free( a->emoji.items[i].key );
free( a->emoji.items[i].value );
}
free( a->emoji.items );
free( a->pinned_posts.items );
free(a->note);
free(a);

@ -64,6 +64,16 @@ struct account
int count;
} fields;
struct {
struct string_pair* items;
int count;
} emoji;
struct {
int* items;
int count;
} pinned_posts;
int followers_count;
int following_count;
int status_count;

@ -77,7 +77,9 @@ bool account_sync_from_activity_pub( unsigned int account_id )
} else {
goto failed;
}
a->inbox = strdup(obj->inbox);
if( obj->inbox ) {
a->inbox = strdup(obj->inbox);
}
if( obj->summary ) {
a->note = strdup(obj->summary);
}
@ -93,6 +95,26 @@ bool account_sync_from_activity_pub( unsigned int account_id )
a->server = server_name;
}
// Clear out existing emoji
for( int i = 0; i < a->emoji.count; ++i ) {
free( a->emoji.items[i].key );
free( a->emoji.items[i].value );
}
a->emoji.count = 0;
// Pull in emoji
for( int i = 0; i < obj->tags.count; ++i ) {
struct ap_activity_tag* tag = obj->tags.items[i];
if( tag->type == aptag_emoji ) {
struct string_pair item;
memset(&item,0,sizeof(item));
item.key = strndup(&tag->name[1],strlen(tag->name)-2);
item.value = strdup(tag->icon.url);
array_append( &a->emoji, sizeof(item), &item );
}
}
// Extract out the public key
char* id = strdup(obj->public_key->id);
char* key_id = NULL;

@ -10,6 +10,37 @@
#include <string.h>
#define OBJ_TYPE struct string_pair
static struct json_object_field emoji_layout[] = {
{
.key = "shortcode",
.offset = offsetof( OBJ_TYPE, key ),
.type = &json_field_string,
},
{
.key = "static_url",
.offset = offsetof( OBJ_TYPE, value ),
.type = &json_field_string,
},
{
.key = "url",
.offset = offsetof( OBJ_TYPE, value ),
.type = &json_field_string,
},
JSON_FIELD_FIXED_BOOL( visible_in_picker, false ),
JSON_FIELD_END,
};
#undef OBJ_TYPE
struct json_field_type emoji_composite_type = {
.reader = json_field_object_composite_reader,
.writer = json_field_object_composite_writer,
.size = sizeof( struct string_pair ),
.layout = emoji_layout,
.alloc = NULL,
.free = NULL,
};
#define OBJ_TYPE struct account
static struct json_object_field pleroma_layout[] = {
JSON_FIELD_FIXED_BOOL( accepts_chat_messages, false ),
@ -125,7 +156,12 @@ struct json_object_field api_Account_layout[] = {
.type = &json_field_callback_string,
.string_callback = display_name_callback,
},
JSON_FIELD_EMPTY_ARRAY( emojis, true ),
{
.key = "emojis",
.offset = offsetof( OBJ_TYPE, emoji ),
.type = &json_field_array_of,
.array_item_type = &emoji_composite_type,
},
JSON_FIELD_EMPTY_ARRAY( fields, true ),
JSON_FIELD_INTEGER( followers_count, true ),
JSON_FIELD_INTEGER( following_count, true ),

Loading…
Cancel
Save