From ca00c4fb5d1ce57c9b221bcab3058387567e3c21 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Sat, 11 May 2024 10:23:07 -0400 Subject: [PATCH] Fix multiple issues getting identity info. --- src/ssb.js.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/ssb.js.c b/src/ssb.js.c index 47e36025..c4c10432 100644 --- a/src/ssb.js.c +++ b/src/ssb.js.c @@ -399,10 +399,11 @@ static void _tf_ssb_getIdentityInfo_visit(const char* identity, void* data) identity_info_work_t* request = data; request->identities = tf_resize_vec(request->identities, (request->count + 1) * sizeof(char*)); request->names = tf_resize_vec(request->names, (request->count + 1) * sizeof(char*)); - request->identities[request->count] = tf_strdup(identity); + char buffer[k_id_base64_len]; + snprintf(buffer, sizeof(buffer), "@%s", identity); + request->identities[request->count] = tf_strdup(buffer); request->names[request->count] = NULL; request->count++; - ; } static void _tf_ssb_getIdentityInfo_work(tf_ssb_t* ssb, void* user_data) @@ -419,8 +420,8 @@ static void _tf_ssb_getIdentityInfo_work(tf_ssb_t* ssb, void* user_data) " RANK() OVER (PARTITION BY messages.author ORDER BY messages.sequence DESC) AS author_rank, " " messages.content ->> 'name' AS name " " FROM messages " - " JOIN identities ON messages.author = ids.value " - " WHERE WHERE identities.user = ? AND json_extract(messages.content, '$.type') = 'about' AND content ->> 'about' = messages.author AND name IS NOT NULL) " + " JOIN identities ON messages.author = ('@' || identities.public_key) " + " WHERE identities.user = ? AND json_extract(messages.content, '$.type') = 'about' AND content ->> 'about' = messages.author AND name IS NOT NULL) " "WHERE author_rank = 1 ", -1, &statement, NULL); if (request->result == SQLITE_OK) @@ -428,7 +429,7 @@ static void _tf_ssb_getIdentityInfo_work(tf_ssb_t* ssb, void* user_data) if (sqlite3_bind_text(statement, 1, request->name, -1, NULL) == SQLITE_OK) { int r = SQLITE_OK; - while ((r = sqlite3_step(statement)) == SQLITE_OK) + while ((r = sqlite3_step(statement)) == SQLITE_ROW) { for (int i = 0; i < request->count; i++) { @@ -444,6 +445,10 @@ static void _tf_ssb_getIdentityInfo_work(tf_ssb_t* ssb, void* user_data) } sqlite3_finalize(statement); } + else + { + tf_printf("prepare failed: %s.\n", sqlite3_errmsg(db)); + } tf_ssb_db_identity_get_active(db, request->name, request->package_owner, request->package_name, request->active_identity, sizeof(request->active_identity)); if (!*request->active_identity && request->count)