|
|
|
@ -12,26 +12,37 @@
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
struct timeline* timeline_from_id( int id )
|
|
|
|
|
struct timeline* timeline_new()
|
|
|
|
|
{
|
|
|
|
|
struct timeline* tl;
|
|
|
|
|
tl = malloc(sizeof(*tl));
|
|
|
|
|
memset(tl,0,sizeof(*tl));
|
|
|
|
|
return tl;
|
|
|
|
|
}
|
|
|
|
|
struct timeline* timeline_from_id( int id )
|
|
|
|
|
{
|
|
|
|
|
struct timeline* tl = timeline_new();
|
|
|
|
|
|
|
|
|
|
tl->id = id;
|
|
|
|
|
tl->path = aformat( "data/accounts/%d/timeline", tl->id );
|
|
|
|
|
|
|
|
|
|
return tl;
|
|
|
|
|
}
|
|
|
|
|
struct timeline* timeline_new()
|
|
|
|
|
struct timeline* timeline_from_path( const char* path )
|
|
|
|
|
{
|
|
|
|
|
struct timeline* tl;
|
|
|
|
|
tl = malloc(sizeof(*tl));
|
|
|
|
|
memset(tl,0,sizeof(*tl));
|
|
|
|
|
struct timeline* tl = timeline_new();
|
|
|
|
|
|
|
|
|
|
tl->id = -1;
|
|
|
|
|
tl->path = strdup(path);
|
|
|
|
|
|
|
|
|
|
return tl;
|
|
|
|
|
}
|
|
|
|
|
void timeline_free( struct timeline* tl )
|
|
|
|
|
{
|
|
|
|
|
if( !tl ) { return; }
|
|
|
|
|
|
|
|
|
|
free( tl->path );
|
|
|
|
|
|
|
|
|
|
free(tl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -43,10 +54,7 @@ int timeline_load_statuses( struct timeline* tl, int offset_from_head, int count
|
|
|
|
|
} values;
|
|
|
|
|
memset(&values,0,sizeof(values));
|
|
|
|
|
|
|
|
|
|
char filename[512];
|
|
|
|
|
snprintf( filename, sizeof(filename), "data/accounts/%d/timeline", tl->id );
|
|
|
|
|
|
|
|
|
|
ffdb_trie_list( filename, offset_from_head, count, NULL, &values );
|
|
|
|
|
ffdb_trie_list( tl->path, offset_from_head, count, NULL, &values );
|
|
|
|
|
int result_count = 0;
|
|
|
|
|
for( int i = 0; i < values.count && result_count < count; ++i ) {
|
|
|
|
|
char* id_str = values.items[i];
|
|
|
|
@ -61,7 +69,7 @@ int timeline_load_statuses( struct timeline* tl, int offset_from_head, int count
|
|
|
|
|
free(values.items);
|
|
|
|
|
return result_count;
|
|
|
|
|
}
|
|
|
|
|
void key_for_post( struct status* s, char* key, int sizeof_key )
|
|
|
|
|
static void key_for_post( struct status* s, char* key, int sizeof_key )
|
|
|
|
|
{
|
|
|
|
|
struct tm gmtime_data;
|
|
|
|
|
gmtime_r( &s->published, &gmtime_data );
|
|
|
|
@ -76,23 +84,17 @@ void key_for_post( struct status* s, char* key, int sizeof_key )
|
|
|
|
|
}
|
|
|
|
|
void timeline_add_post( struct timeline* tl, struct status* s )
|
|
|
|
|
{
|
|
|
|
|
char filename[512];
|
|
|
|
|
snprintf( filename, sizeof(filename), "data/accounts/%d/timeline", tl->id );
|
|
|
|
|
|
|
|
|
|
char key[512];
|
|
|
|
|
key_for_post(s,key,sizeof(key));
|
|
|
|
|
|
|
|
|
|
char value[32];
|
|
|
|
|
ffdb_trie_set( filename, key, format( value, sizeof(value), "%d", s->id ) );
|
|
|
|
|
ffdb_trie_set( tl->path, key, format( value, sizeof(value), "%d", s->id ) );
|
|
|
|
|
}
|
|
|
|
|
void timeline_remove_post( struct timeline* tl, struct status* s )
|
|
|
|
|
{
|
|
|
|
|
char filename[512];
|
|
|
|
|
snprintf( filename, sizeof(filename), "data/accounts/%d/timeline", tl->id );
|
|
|
|
|
|
|
|
|
|
char key[512];
|
|
|
|
|
key_for_post(s,key,sizeof(key));
|
|
|
|
|
|
|
|
|
|
ffdb_trie_remove( filename, key );
|
|
|
|
|
ffdb_trie_remove( tl->path, key );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|