Start implementing tags

master
teknomunk 11 months ago
parent e510eeb57b
commit 67b6f6b73f

@ -1 +1 @@
Subproject commit a419c6373c59e3e5a2094180213d94924ca41317
Subproject commit 45790a0384ac4fb95c07fe3d97669b6b7bc743bc

@ -62,6 +62,7 @@ static struct json_object_field status_layout[] = {
JSON_FIELD_ARRAY_OF_INTS( quotes, false ),
JSON_FIELD_ARRAY_OF_INTS( mentions, false ),
JSON_FIELD_ARRAY_OF_TYPE( emoji, false, emoji_type ),
JSON_FIELD_ARRAY_OF_STRINGS( tags, false ),
JSON_FIELD_BOOL( sensitive, true ),
@ -81,6 +82,7 @@ void status_model_init()
mkdir( "data", 0755 );
mkdir( "data/statuses", 0755 );
mkdir( "data/statuses/ap", 0755 );
mkdir( "data/statuses/tags", 0755 );
}
static const char* get_status_data_filename( unsigned int id, char* filename, int size )
@ -351,6 +353,9 @@ bool status_sync_from_activity_pub( struct status* s, struct ap_object* act )
e->shortcode[ strlen(e->shortcode) - 1 ] = '\0';
array_append( &s->emoji, sizeof(e), &e );
} else if( tag->type == aptag_hashtag && tag->name ) {
char* tag_name = safe_strdup( &tag->name[1] );
array_append( &s->tags, sizeof(tag_name), &tag_name );
}
}
@ -360,11 +365,7 @@ bool status_sync_from_activity_pub( struct status* s, struct ap_object* act )
free(s->url);
s->url = strdup( act->id );
if( !s->source ) {
printf( "? No source, using content directly\n" );
free(s->content);
s->content = safe_strdup(act->content.content);
}
s->content = safe_strdup( act->content.content );
// Erase existing media
for( int i = 0; i < s->media.count; ++i ) {
@ -575,6 +576,7 @@ bool status_save_new( struct status* s )
return true;
}
void key_for_post( struct status* s, char* key, int sizeof_key );
void status_save( struct status* s )
{
char filename[512];
@ -592,6 +594,18 @@ void status_save( struct status* s )
} else {
ffdb_trie_remove( "data/statuses/stubs", format(filename,512,"%d",s->id) );
}
// Set the tags
for( int i = 0; i < s->tags.count; ++i ) {
char tag_file[512];
ffdb_trie_set( "data/statuses/tags", s->tags.items[i], "T" );
char time[512];
key_for_post( s, time, 512 );
ffdb_trie_set( format(tag_file,512, "data/statuses/tags/%s", s->tags.items[i] ), time, format( filename,512,"%d",s->id) );
}
}
void status_clean_tags()
{
}
void status_write_to_FILE( struct status* s, FILE* f )
{
@ -635,6 +649,12 @@ void status_free( struct status* s )
}
free(s->emoji.items);
// Free tags
for( int i = 0; i < s->tags.count; ++i ) {
free(s->tags.items[i]);
}
free(s->tags.items);
free(s);
}
void status_delete( struct status* s )

@ -76,6 +76,11 @@ struct status
struct emoji** items;
int count;
} emoji;
struct {
char** items;
int count;
} tags;
};
void status_model_init();

@ -61,7 +61,7 @@ int timeline_load_statuses( struct timeline* tl, int offset_from_head, int count
free(values.items);
return result_count;
}
static void key_for_post( struct status* s, char* key, int sizeof_key )
void key_for_post( struct status* s, char* key, int sizeof_key )
{
struct tm gmtime_data;
gmtime_r( &s->published, &gmtime_data );

@ -1,9 +1,5 @@
#include "Status.h"
#include "json/json.h"
#include "json/layout.h"
#include "util/format.h"
#include "model/server.h"
#include "model/status.h"
#include "model/status/react.h"
@ -11,6 +7,11 @@
#include "model/media.h"
#include "view/api/Account.h"
#include "view/api/Tag.h"
#include "json/json.h"
#include "json/layout.h"
#include "util/format.h"
#include <string.h>
@ -188,7 +189,7 @@ static struct json_field_type MediaAttachment_type = {
.layout = MediaAttachment_layout,
.reader = json_field_object_type_reader,
.writer = json_field_object_type_writer,
.size = sizeof(char*),
.size = sizeof(struct media*),
};
#define OBJ_TYPE struct account
@ -554,7 +555,12 @@ struct json_object_field api_Status_layout[] = {
.allow_drop_empty = false,
.type = &json_field_string,
},
JSON_FIELD_EMPTY_ARRAY( tags, true ),
{
.key = "tags",
.offset = offsetof( OBJ_TYPE, tags ),
.type = &json_field_array_of,
.array_item_type = &Tag_type,
},
JSON_FIELD_FIXED_NULL( text ),
{
.key = "uri",

@ -0,0 +1,46 @@
#include "Tag.h"
#include "model/server.h"
#include "json/json.h"
#include "json/layout.h"
#include "util/format.h"
static bool simple_copy_callback( void* field_data, bool is_read, char** val )
{
if( is_read ) { return false; }
char* tag = field_data;
*val = safe_strdup(tag);
return true;
};
static bool tag_url_callback( void* field_data, bool is_read, char** val )
{
if( is_read ) { return false; }
char* tag = field_data;
*val = aformat( "https://%s/tag/%s", g_server->domain, tag );
return true;
};
static struct json_object_field Tag_layout[] = {
{
.key = "name",
.offset = 0,
.type = &json_field_callback_string,
.string_callback = simple_copy_callback,
},
{
.key = "url",
.offset = 0,
.type = &json_field_callback_string,
.string_callback = tag_url_callback,
},
JSON_FIELD_END,
};
struct json_field_type Tag_type = {
.layout = Tag_layout,
.reader = json_field_object_type_reader,
.writer = json_field_object_type_writer,
.size = sizeof(char*),
};

@ -0,0 +1,4 @@
#pragma once
extern struct json_field_type Tag_type;
Loading…
Cancel
Save