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();

View File

@ -22,6 +22,7 @@
pubs: [],
votes: [],
};
var g_data_initial = JSON.parse(JSON.stringify(g_data));
window.addEventListener('message', function(event) {
var key = Object.keys(event.data)[0];
if (key + 's' in g_data && Array.isArray(g_data[key + 's'])) {
@ -42,6 +43,10 @@
g_data.broadcasts = event.data.broadcasts;
} else if (key == 'pubs') {
g_data.pubs = event.data.pubs;
} else if (key == 'clear') {
Object.keys(g_data_initial).forEach(function(key) {
Vue.set(g_data, key, JSON.parse(JSON.stringify(g_data_initial[key])));
});
} else {
g_data[key] = event.data[key];
}