Move ssb.appendMessageWithIdentity's DB work off the main thread.
This commit is contained in:
22
src/ssb.c
22
src/ssb.c
@ -1784,18 +1784,28 @@ static bool _tf_ssb_connection_box_stream_recv(tf_ssb_connection_t* connection)
|
||||
return true;
|
||||
}
|
||||
|
||||
JSValue tf_ssb_sign_message(tf_ssb_t* ssb, const char* author, const uint8_t* private_key, JSValue message)
|
||||
JSValue tf_ssb_sign_message(tf_ssb_t* ssb, const char* author, const uint8_t* private_key, JSValue message, const char* previous_id, int64_t previous_sequence)
|
||||
{
|
||||
char previous_id[crypto_hash_sha256_BYTES * 2];
|
||||
int64_t previous_sequence = 0;
|
||||
bool have_previous = tf_ssb_db_get_latest_message_by_author(ssb, author, &previous_sequence, previous_id, sizeof(previous_id));
|
||||
char actual_previous_id[crypto_hash_sha256_BYTES * 2];
|
||||
int64_t actual_previous_sequence = 0;
|
||||
bool have_previous = false;
|
||||
if (previous_id)
|
||||
{
|
||||
have_previous = *previous_id && previous_sequence > 0;
|
||||
snprintf(actual_previous_id, sizeof(actual_previous_id), "%s", previous_id);
|
||||
actual_previous_sequence = previous_sequence;
|
||||
}
|
||||
else
|
||||
{
|
||||
have_previous = tf_ssb_db_get_latest_message_by_author(ssb, author, &actual_previous_sequence, actual_previous_id, sizeof(actual_previous_id));
|
||||
}
|
||||
|
||||
JSContext* context = ssb->context;
|
||||
JSValue root = JS_NewObject(context);
|
||||
|
||||
JS_SetPropertyStr(context, root, "previous", have_previous ? JS_NewString(context, previous_id) : JS_NULL);
|
||||
JS_SetPropertyStr(context, root, "previous", have_previous ? JS_NewString(context, actual_previous_id) : JS_NULL);
|
||||
JS_SetPropertyStr(context, root, "author", JS_NewString(context, author));
|
||||
JS_SetPropertyStr(context, root, "sequence", JS_NewInt64(context, previous_sequence + 1));
|
||||
JS_SetPropertyStr(context, root, "sequence", JS_NewInt64(context, actual_previous_sequence + 1));
|
||||
|
||||
int64_t now = (int64_t)time(NULL);
|
||||
JS_SetPropertyStr(context, root, "timestamp", JS_NewInt64(context, now * 1000LL));
|
||||
|
Reference in New Issue
Block a user