Start implementing followers logic, start react logic

master
teknomunk 1 year ago
parent 9a3a759dd5
commit 697df4f3c0

@ -1,10 +1,12 @@
#include "test.h"
#include "test/crypto.h"
#include "ffdb/test.h"
#include <stdio.h>
void built_in_test()
{
if( !ffdb_test() ) { printf( "[FAIL] ffdb_test\n" ); }
if( !test_crypto() ) { printf( "[FAIL] test_crypto\n" ); }
}

@ -76,6 +76,7 @@ static bool test_http_signature_2()
if( !http_signature_make( "https://example.com/inbox", keys, &hs ) ) {
return false;
}
free(hs.host);
char signature_header[512];
snprintf( signature_header, sizeof(signature_header), "keyId=\"Test\",headers=\"(request-target) host date\",signature=\"%s\"", hs.signature );

@ -1 +1 @@
Subproject commit 41dd937d41dd06a74965efdf1ef1423cefbb4617
Subproject commit 3cacd9fa083d94088c87e826be5f123c8056b880

@ -1 +1 @@
Subproject commit c6cadd36b1b0e969b89d74683c525dd9ce69d0c5
Subproject commit 1a302a180b0eb93a4c716975dd5a35c5b98957de

@ -6,6 +6,7 @@
#include "http_client/client.h"
#include "ffdb/fs_list.h"
#include "ffdb/hash_index.h"
#include "ffdb/trie.h"
// Model
#include "model/server.h"
@ -257,11 +258,29 @@ void account_save( struct account* a )
void account_add_follower( struct account* a, struct account* follower )
{
printf( "TODO: implement account_add_follower()\n" );
char filename[512];
snprintf( filename, sizeof(filename), "data/accounts/%d/followers", a->id );
// Insert an entry for this follower (only does something if not already set)
char key[32];
snprintf( key, sizeof(key), "%d", follower->id );
ffdb_trie_set( filename, key, "T" );
// Update follower count
a->followers_count = ffdb_trie_count(filename);
}
void account_remove_follower( struct account* a, struct account* follower )
{
printf( "TODO: implement account_remove_follower()\n" );
char filename[512];
snprintf( filename, sizeof(filename), "data/accounts/%d/followers", a->id );
// Remove the follow
char key[32];
snprintf( key, sizeof(key), "%d", follower->id );
ffdb_trie_remove( filename, key );
// Update follower count
a->followers_count = ffdb_trie_count(filename);
}
// TODO: move to controller/view

@ -50,6 +50,7 @@ enum ap_activity_type
apat_flag = 26,
apat_dislike = 27,
apat_question = 28,
apat_emoji_react = 29,
};
enum ap_activity_object_type {
apaot_ref = 1,

@ -50,6 +50,7 @@ struct json_enum ap_activity_type_enum[] = {
{ "Flag", apat_flag },
{ "Dislike", apat_dislike },
{ "Question", apat_question },
{ "EmojiReact", apat_emoji_react },
{ NULL, 0 },
};

@ -1,11 +1,12 @@
#include "status.h"
#include "status/react.h"
#include "model/account.h"
#include "model/ap/activity.h"
// Submodules
#include "json/json.h"
#include "json/layout.h"
#include "sha256/sha256.h"
#include <stdio.h>
@ -18,7 +19,7 @@ static struct json_object_field status_layout[] = {
{ "sensitive", offsetof( struct status, sensitive ), true, &json_field_bool },
{ "content", offsetof( struct status, content ), true, &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, &json_field_string },
{ "reacts", offsetof( struct status, reacts ), false, &json_field_array_of, &status_react_type },
{ NULL }
};
@ -47,11 +48,6 @@ struct status* status_from_id( unsigned int id )
return s;
}
char* render_source( const char* src )
{
return strdup(src);
}
struct status* status_from_activity( struct ap_activity* act )
{
struct status* s;
@ -62,7 +58,7 @@ struct status* status_from_activity( struct ap_activity* act )
s->account_id = a->id;
account_free(a);
s->content = render_source( act->source );
s->content = status_render_source( act->source );
return s;
}

@ -17,7 +17,7 @@ struct status
} media;
struct {
char** items;
struct status_react** items;
int count;
} reacts;
};
@ -31,3 +31,5 @@ bool status_save_new( struct status* s );
void status_save( struct status* s );
void status_free( struct status* s );
char* status_render_source( const char* src );

@ -0,0 +1,7 @@
#include "react.h"
#include "json/layout.h"
struct json_field_type status_react_type = {
};

@ -0,0 +1,13 @@
#pragma once
struct status_react
{
char* code;
struct {
int* accounts;
int count;
};
};
extern struct json_field_type status_react_type;

@ -0,0 +1,10 @@
#include "model/status.h"
#include <string.h>
#include <stdlib.h>
char* status_render_source( const char* src )
{
return strdup(src);
}
Loading…
Cancel
Save