Reworked some following math.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4601 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2023-11-03 00:45:30 +00:00
parent 8fe7adc50e
commit 4cedc54d2d
6 changed files with 143 additions and 33 deletions

View File

@ -105,7 +105,7 @@ static JSValue _tf_ssb_set_server_following_me(JSContext* context, JSValueConst
else
{
const char* server_id_ptr = server_id;
const char** current_following = tf_ssb_db_following_deep(ssb, &server_id_ptr, 1, 1);
const char** current_following = tf_ssb_db_following_deep_ids(ssb, &server_id_ptr, 1, 1);
bool is_following = false;
for (const char** it = current_following; *it; it++)
{
@ -1519,7 +1519,7 @@ typedef struct _following_t
JSContext* context;
JSValue promise[2];
const char** out_ids;
tf_ssb_following_t* out_following;
int depth;
int ids_count;
@ -1529,7 +1529,7 @@ typedef struct _following_t
static void _tf_ssb_following_work(uv_work_t* work)
{
following_t* following = work->data;
following->out_ids = tf_ssb_db_following_deep(following->ssb, following->ids, following->ids_count, following->depth);
following->out_following = tf_ssb_db_following_deep(following->ssb, following->ids, following->ids_count, following->depth);
}
static void _tf_ssb_following_after_work(uv_work_t* work, int status)
@ -1538,13 +1538,18 @@ static void _tf_ssb_following_after_work(uv_work_t* work, int status)
JSContext* context = following->context;
if (status == 0)
{
JSValue array = JS_NewArray(context);
for (int i = 0; following->out_ids[i]; i++)
JSValue object = JS_NewObject(context);
for (int i = 0; *following->out_following[i].id; i++)
{
JS_SetPropertyUint32(context, array, i, JS_NewString(context, following->out_ids[i]));
JSValue entry = JS_NewObject(context);
JS_SetPropertyStr(context, entry, "of", JS_NewInt32(context, following->out_following[i].following_count));
JS_SetPropertyStr(context, entry, "ob", JS_NewInt32(context, following->out_following[i].blocking_count));
JS_SetPropertyStr(context, entry, "if", JS_NewInt32(context, following->out_following[i].followed_by_count));
JS_SetPropertyStr(context, entry, "ib", JS_NewInt32(context, following->out_following[i].blocked_by_count));
JS_SetPropertyStr(context, object, following->out_following[i].id, entry);
}
JS_Call(context, following->promise[0], JS_UNDEFINED, 1, &array);
JS_FreeValue(context, array);
JS_Call(context, following->promise[0], JS_UNDEFINED, 1, &object);
JS_FreeValue(context, object);
}
else
{
@ -1559,7 +1564,7 @@ static void _tf_ssb_following_after_work(uv_work_t* work, int status)
{
tf_free((void*)following->ids[i]);
}
tf_free(following->out_ids);
tf_free(following->out_following);
tf_free(following);
}