Appending a message produces the ID. And bump the version.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4344 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2023-07-13 00:20:12 +00:00
parent c4a2d790a3
commit 18128303b6
7 changed files with 29 additions and 16 deletions

View File

@ -1666,7 +1666,7 @@ static bool _tf_ssb_connection_box_stream_recv(tf_ssb_connection_t* connection)
return true;
}
void tf_ssb_append_message_with_keys(tf_ssb_t* ssb, const char* author, const uint8_t* private_key, JSValue message)
bool tf_ssb_append_message_with_keys(tf_ssb_t* ssb, const char* author, const uint8_t* private_key, JSValue message, char* out_id, size_t out_id_size)
{
char previous_id[crypto_hash_sha256_BYTES * 2];
int64_t previous_sequence = 0;
@ -1718,12 +1718,15 @@ void tf_ssb_append_message_with_keys(tf_ssb_t* ssb, const char* author, const ui
JS_FreeCString(context, json);
JS_FreeValue(context, jsonval);
bool stored = false;
char id[sodium_base64_ENCODED_LEN(crypto_hash_sha256_BYTES, sodium_base64_VARIANT_ORIGINAL) + 7 + 1];
if (valid && tf_ssb_verify_and_strip_signature(ssb->context, root, id, sizeof(id), NULL, 0, NULL))
{
if (tf_ssb_db_store_message(ssb, ssb->context, id, root, signature_base64, false))
{
tf_ssb_notify_message_added(ssb, id);
snprintf(out_id, out_id_size, "%s", id);
stored = true;
}
else
{
@ -1735,7 +1738,13 @@ void tf_ssb_append_message_with_keys(tf_ssb_t* ssb, const char* author, const ui
tf_printf("Failed to verify message signature.\n");
}
if (!stored && out_id && out_id_size)
{
*out_id = '\0';
}
JS_FreeValue(context, root);
return stored;
}
static void _tf_ssb_connection_dispatch_scheduled(tf_ssb_connection_t* connection)