From 0a01332d1f22e7a387621c9a7a85d5c859cb780f Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Sat, 30 Oct 2021 21:07:01 +0000 Subject: [PATCH] Fix some RPC issues? git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3678 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- core/ssb.js | 19 ++++++++++++++++--- src/ssb.c | 2 +- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/core/ssb.js b/core/ssb.js index 942d98bc..4855e658 100644 --- a/core/ssb.js +++ b/core/ssb.js @@ -62,10 +62,23 @@ async function test_following() { test_following(); +async function get_latest_sequence_for_author(author) { + var sequence = 0; + await ssb.sqlStream( + 'SELECT MAX(sequence) AS sequence FROM messages WHERE author = ?1', + [author], + function(row) { + sequence = row.sequence + 1; + }); + return sequence; +} + ssb.registerConnectionsChanged(function(change, connection) { if (change == 'add') { - connection.send_json({'name': ['createHistoryStream'], 'type': 'source', 'args': [{'id': connection.id, 'seq': 0}]}, function(message) { - ssb.storeMessage(message.message.value); + get_latest_sequence_for_author(connection.id).then(function(sequence) { + connection.send_json({'name': ['createHistoryStream'], 'type': 'source', 'args': [{'id': connection.id, 'seq': sequence}]}, function(message) { + ssb.storeMessage(message.message.value); + }); }); connection.send_json({'name': ['blobs', 'createWants'], 'type': 'source', 'args': []}, function(message) { Object.keys(message.message).forEach(function(id) { @@ -78,7 +91,7 @@ ssb.registerConnectionsChanged(function(change, connection) { } } else { debug_print("blobs.get", id); - connection.send_json({'name': ['blobs', 'get'], 'type': 'source', 'args': [{'id': id}]}, function(message) { + connection.send_json({'name': ['blobs', 'get'], 'type': 'source', 'args': [id]}, function(message) { debug_print(id, '=>', debug_utf8Decode(message.message)); ssb.blobStore(message.message); }); diff --git a/src/ssb.c b/src/ssb.c index 0755ecf0..0d378d93 100644 --- a/src/ssb.c +++ b/src/ssb.c @@ -937,7 +937,7 @@ static void _tf_ssb_connection_rpc_recv(tf_ssb_connection_t* connection, uint8_t else { const char* k_unsupported = "{\"message\": \"unsupported message\", \"name\": \"Error\", \"stack\": \"none\", \"args\": []}"; - tf_ssb_connection_rpc_send(connection, k_ssb_rpc_flag_json | k_ssb_rpc_flag_end_error, -request_number, + tf_ssb_connection_rpc_send(connection, k_ssb_rpc_flag_json | k_ssb_rpc_flag_end_error | (flags & k_ssb_rpc_flag_stream), -request_number, (const uint8_t*)k_unsupported, strlen(k_unsupported), NULL, NULL); } }