forked from cory/tildefriends
Add a button in the profile editor to ask the server to follow you. I'm hoping this helps replicating accounts that are otherwise difficult to discover.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4558 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
77
src/ssb.db.c
77
src/ssb.db.c
@ -1258,7 +1258,10 @@ void tf_ssb_db_identity_visit_all(tf_ssb_t* ssb, void (*callback)(const char* id
|
||||
bool tf_ssb_db_identity_get_private_key(tf_ssb_t* ssb, const char* user, const char* public_key, uint8_t* out_private_key, size_t private_key_size)
|
||||
{
|
||||
bool success = false;
|
||||
memset(out_private_key, 0, crypto_sign_SECRETKEYBYTES);
|
||||
if (out_private_key)
|
||||
{
|
||||
memset(out_private_key, 0, private_key_size);
|
||||
}
|
||||
sqlite3* db = tf_ssb_acquire_db_reader(ssb);
|
||||
sqlite3_stmt* statement = NULL;
|
||||
if (sqlite3_prepare(db, "SELECT private_key FROM identities WHERE user = ? AND public_key = ?", -1, &statement, NULL) == SQLITE_OK)
|
||||
@ -1269,8 +1272,15 @@ bool tf_ssb_db_identity_get_private_key(tf_ssb_t* ssb, const char* user, const c
|
||||
if (sqlite3_step(statement) == SQLITE_ROW)
|
||||
{
|
||||
const char* key = (const char*)sqlite3_column_text(statement, 0);
|
||||
int r = tf_base64_decode(key, sqlite3_column_bytes(statement, 0) - strlen(".ed25519"), out_private_key, private_key_size);
|
||||
success = r > 0;
|
||||
if (out_private_key && private_key_size)
|
||||
{
|
||||
int r = tf_base64_decode(key, sqlite3_column_bytes(statement, 0) - strlen(".ed25519"), out_private_key, private_key_size);
|
||||
success = r > 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
sqlite3_finalize(statement);
|
||||
@ -1289,6 +1299,7 @@ typedef struct _following_t
|
||||
int following_count;
|
||||
int blocking_count;
|
||||
int depth;
|
||||
int ref_count;
|
||||
} following_t;
|
||||
|
||||
static int _following_compare(const void* a, const void* b)
|
||||
@ -1301,7 +1312,7 @@ static int _following_compare(const void* a, const void* b)
|
||||
static void _add_following_entry(following_t*** list, int* count, following_t* add)
|
||||
{
|
||||
int index = tf_util_insert_index(add->id, *list, *count, sizeof(following_t*), _following_compare);
|
||||
if (index >= *count || strcmp(add->id, (*list)[index]->id) == 0)
|
||||
if (index >= *count || strcmp(add->id, (*list)[index]->id) != 0)
|
||||
{
|
||||
*list = tf_resize_vec(*list, sizeof(**list) * (*count + 1));
|
||||
if (*count - index)
|
||||
@ -1309,6 +1320,21 @@ static void _add_following_entry(following_t*** list, int* count, following_t* a
|
||||
memmove(*list + index + 1, *list + index, sizeof(following_t*) * (*count - index));
|
||||
}
|
||||
(*list)[index] = add;
|
||||
(*count)++;
|
||||
}
|
||||
}
|
||||
|
||||
static void _remove_following_entry(following_t*** list, int* count, following_t* remove)
|
||||
{
|
||||
int index = tf_util_insert_index(remove->id, *list, *count, sizeof(following_t*), _following_compare);
|
||||
if (index < *count && strcmp(remove->id, (*list)[index]->id) == 0)
|
||||
{
|
||||
if (*count - index > 1)
|
||||
{
|
||||
memmove(*list + index, *list + index + 1, sizeof(following_t*) * (*count - index));
|
||||
}
|
||||
*list = tf_resize_vec(*list, sizeof(**list) * (*count - 1));
|
||||
(*count)--;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1354,21 +1380,31 @@ static following_t* _get_following(tf_ssb_t* ssb, const char* id, following_t***
|
||||
const char* contact = (const char*)sqlite3_column_text(statement, 0);
|
||||
if (sqlite3_column_type(statement, 1) != SQLITE_NULL)
|
||||
{
|
||||
bool is_following = sqlite3_column_int(statement, 1);
|
||||
bool is_following = sqlite3_column_int(statement, 1) != 0;
|
||||
following_t* next = _get_following(ssb, contact, following, following_count, depth + 1, max_depth);
|
||||
if (is_following)
|
||||
{
|
||||
_add_following_entry(&entry->following, &entry->following_count, next);
|
||||
next->ref_count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
_remove_following_entry(&entry->following, &entry->following_count, next);
|
||||
next->ref_count--;
|
||||
}
|
||||
}
|
||||
if (sqlite3_column_type(statement, 2) != SQLITE_NULL)
|
||||
{
|
||||
bool is_blocking = sqlite3_column_int(statement, 2);
|
||||
bool is_blocking = sqlite3_column_int(statement, 2 != 0);
|
||||
following_t* next = _get_following(ssb, contact, following, following_count, depth + 1, 0 /* don't dig deeper into blocked users */);
|
||||
if (is_blocking)
|
||||
{
|
||||
_add_following_entry(&entry->blocking, &entry->blocking_count, next);
|
||||
}
|
||||
else
|
||||
{
|
||||
_remove_following_entry(&entry->blocking, &entry->blocking_count, next);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1385,18 +1421,33 @@ const char** tf_ssb_db_following_deep(tf_ssb_t* ssb, const char** ids, int count
|
||||
int following_count = 0;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
_get_following(ssb, ids[i], &following, &following_count, 0, depth);
|
||||
following_t* entry = _get_following(ssb, ids[i], &following, &following_count, 0, depth);
|
||||
entry->ref_count++;
|
||||
}
|
||||
|
||||
char** result = tf_malloc(sizeof(char*) * (following_count + 1) + k_id_base64_len * following_count);
|
||||
char* result_ids = (char*)result + sizeof(char*) * (following_count + 1);
|
||||
|
||||
int actual_following_count = 0;
|
||||
for (int i = 0; i < following_count; i++)
|
||||
{
|
||||
result[i] = result_ids + k_id_base64_len * i;
|
||||
snprintf(result[i], k_id_base64_len, "%s", following[i]->id);
|
||||
if (following[i]->ref_count > 0)
|
||||
{
|
||||
actual_following_count++;
|
||||
}
|
||||
}
|
||||
result[following_count] = NULL;
|
||||
|
||||
char** result = tf_malloc(sizeof(char*) * (actual_following_count + 1) + k_id_base64_len * actual_following_count);
|
||||
char* result_ids = (char*)result + sizeof(char*) * (actual_following_count + 1);
|
||||
|
||||
int write_index = 0;
|
||||
for (int i = 0; i < following_count; i++)
|
||||
{
|
||||
if (following[i]->ref_count > 0)
|
||||
{
|
||||
result[write_index] = result_ids + k_id_base64_len * write_index;
|
||||
snprintf(result[write_index], k_id_base64_len, "%s", following[i]->id);
|
||||
write_index++;
|
||||
}
|
||||
}
|
||||
result[actual_following_count] = NULL;
|
||||
|
||||
for (int i = 0; i < following_count; i++)
|
||||
{
|
||||
|
Reference in New Issue
Block a user