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:
19
core/ssb.js
19
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);
|
||||
});
|
||||
|
Reference in New Issue
Block a user