From 22078fcd2ccfe7cee349534c749bb1abfb205124 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Sat, 2 Jan 2021 18:35:12 +0000 Subject: [PATCH] Trying to make refresh more sensible. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3622 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- apps/cory/docs.json | 2 +- apps/cory/docs/todo.md | 6 +++++- apps/cory/index.json | 2 +- apps/cory/index/app.js | 33 +++++++++++++++------------------ apps/cory/index/index.html | 5 +++++ 5 files changed, 27 insertions(+), 21 deletions(-) diff --git a/apps/cory/docs.json b/apps/cory/docs.json index a1e58e20..316f013b 100644 --- a/apps/cory/docs.json +++ b/apps/cory/docs.json @@ -1 +1 @@ -{"type":"tildefriends-app","files":{"app.js":"&WCq6ssQedT5denXPXlz2BswPD6hmt++EmWIMIDUMurA=.sha256","index.md":"&Lr7IXs8osbmWz6SDsGTQCiybbxkbWSK2MrUcXMzgqTs=.sha256","todo.md":"&/vzp5PrF93TPAuS/97fbj6+mzyNOxYFjBGQJmZYe4As=.sha256","structure.md":"&xRhQ4Mpom1Idskum07osbBQYcYWroH0sELQBkQHrOMg=.sha256","purpose.md":"&c0/YqFhXC0X3DqiEo55NqzI5wq0VTw6cVZTf/gAWS3w=.sha256","guide.md":"&SgnGL0+rjetY2o9A2+lVRbNvHIkqKwMnZr9gXWneIlc=.sha256"}} \ No newline at end of file +{"type":"tildefriends-app","files":{"app.js":"&WCq6ssQedT5denXPXlz2BswPD6hmt++EmWIMIDUMurA=.sha256","index.md":"&Lr7IXs8osbmWz6SDsGTQCiybbxkbWSK2MrUcXMzgqTs=.sha256","todo.md":"&XrOJ3D5YMTN+j+0hJgLLy7Y61B6Z14ebv+60ee+N37I=.sha256","structure.md":"&xRhQ4Mpom1Idskum07osbBQYcYWroH0sELQBkQHrOMg=.sha256","purpose.md":"&c0/YqFhXC0X3DqiEo55NqzI5wq0VTw6cVZTf/gAWS3w=.sha256","guide.md":"&SgnGL0+rjetY2o9A2+lVRbNvHIkqKwMnZr9gXWneIlc=.sha256"}} \ No newline at end of file diff --git a/apps/cory/docs/todo.md b/apps/cory/docs/todo.md index b8abf4a5..30301b7f 100644 --- a/apps/cory/docs/todo.md +++ b/apps/cory/docs/todo.md @@ -10,7 +10,10 @@ - audit + document API exposed to apps - ssb core - good refresh + - disconnect all current connections and reset reconnect timers? + - reload the page - live updates + - createHistoryStream for every account followed from local accounts - apps - app messages - installable apps @@ -41,4 +44,5 @@ - tie identities to TF login accounts - tf account timeout why - make some demo apps - - rock paper scissors, somehow \ No newline at end of file + - rock paper scissors, somehow +- don't resave files that didn't change \ No newline at end of file diff --git a/apps/cory/index.json b/apps/cory/index.json index 2c658a1d..cc832a2e 100644 --- a/apps/cory/index.json +++ b/apps/cory/index.json @@ -1 +1 @@ -{"type":"tildefriends-app","files":{"app.js":"&GOWmWDTHuNMz2XpxNxspAqsITn/RwvlB4Um6euxHFbU=.sha256","index.html":"&/noD6q/rH4VgszVb6W0D3mnK9t0GbDYYZtBGM/xs2kY=.sha256","vue-material.js":"&K5cdLqXYCENPak/TCINHQhyJhpS4G9DlZHGwoh/LF2g=.sha256"}} \ No newline at end of file +{"type":"tildefriends-app","files":{"app.js":"&oCXEt7h7lEIL8BXyVDv3Skp44ApY+rExcNKx9//Dj80=.sha256","index.html":"&7/hwWTsmdkNkTLT3gUwaZ+B+Y5EjHGHyE2+zWkHnMac=.sha256","vue-material.js":"&K5cdLqXYCENPak/TCINHQhyJhpS4G9DlZHGwoh/LF2g=.sha256"}} \ No newline at end of file diff --git a/apps/cory/index/app.js b/apps/cory/index/app.js index d9ade996..eb45dc4d 100644 --- a/apps/cory/index/app.js +++ b/apps/cory/index/app.js @@ -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(); diff --git a/apps/cory/index/index.html b/apps/cory/index/index.html index ab5be122..6cc6a17d 100644 --- a/apps/cory/index/index.html +++ b/apps/cory/index/index.html @@ -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]; }