Trying to make refresh more sensible.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3622 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2021-01-02 18:35:12 +00:00
parent 79022e1e1f
commit 22078fcd2c
5 changed files with 27 additions and 21 deletions

View File

@@ -291,6 +291,20 @@ async function getPosts(db, ids) {
}
async function ready() {
return refresh();
}
core.register('onBroadcastsChanged', async function() {
await app.postMessage({broadcasts: await ssb.getBroadcasts()});
});
core.register('onConnectionsChanged', async function() {
var connections = await ssb.connections();
await app.postMessage({connections: connections});
});
async function refresh() {
await app.postMessage({clear: true});
var whoami = await ssb.whoami();
var db = await database("ssb");
await Promise.all([
@@ -299,6 +313,7 @@ async function ready() {
app.postMessage({broadcasts: await ssb.getBroadcasts()}),
app.postMessage({connections: await ssb.connections()}),
followingDeep(db, [whoami], 2).then(function(f) {
print(JSON.stringify(f));
getRecentPostIds(db, whoami, [].concat([whoami], f), k_posts_max).then(async function(ids) {
return getPosts(db, ids);
}).then(async function(posts) {
@@ -333,24 +348,6 @@ async function ready() {
]);
}
core.register('onBroadcastsChanged', async function() {
await app.postMessage({broadcasts: await ssb.getBroadcasts()});
});
core.register('onConnectionsChanged', async function() {
var connections = await ssb.connections();
await app.postMessage({connections: connections});
});
async function refresh() {
var db = await database("ssb");
var whoami = await ssb.whoami();
var ids = await followingDeep(db, [whoami], 2);
for (var id of ids) {
await ssb.createHistoryStream(id);
}
}
core.register('message', async function(m) {
if (m.message == 'ready') {
await ready();