forked from cory/tildefriends
Fix some RPC issues?
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3678 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
256c47c33c
commit
0a01332d1f
17
core/ssb.js
17
core/ssb.js
@ -62,11 +62,24 @@ async function test_following() {
|
|||||||
|
|
||||||
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) {
|
ssb.registerConnectionsChanged(function(change, connection) {
|
||||||
if (change == 'add') {
|
if (change == 'add') {
|
||||||
connection.send_json({'name': ['createHistoryStream'], 'type': 'source', 'args': [{'id': connection.id, 'seq': 0}]}, function(message) {
|
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);
|
ssb.storeMessage(message.message.value);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
connection.send_json({'name': ['blobs', 'createWants'], 'type': 'source', 'args': []}, function(message) {
|
connection.send_json({'name': ['blobs', 'createWants'], 'type': 'source', 'args': []}, function(message) {
|
||||||
Object.keys(message.message).forEach(function(id) {
|
Object.keys(message.message).forEach(function(id) {
|
||||||
if (message.message[id] < 0) {
|
if (message.message[id] < 0) {
|
||||||
@ -78,7 +91,7 @@ ssb.registerConnectionsChanged(function(change, connection) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
debug_print("blobs.get", id);
|
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));
|
debug_print(id, '=>', debug_utf8Decode(message.message));
|
||||||
ssb.blobStore(message.message);
|
ssb.blobStore(message.message);
|
||||||
});
|
});
|
||||||
|
@ -937,7 +937,7 @@ static void _tf_ssb_connection_rpc_recv(tf_ssb_connection_t* connection, uint8_t
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
const char* k_unsupported = "{\"message\": \"unsupported message\", \"name\": \"Error\", \"stack\": \"none\", \"args\": []}";
|
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);
|
(const uint8_t*)k_unsupported, strlen(k_unsupported), NULL, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user