Slightly simplifying refresh().

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3732 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2022-01-03 01:44:14 +00:00
parent e1448a1c3a
commit 3eabe72299
2 changed files with 30 additions and 33 deletions

View File

@ -257,39 +257,36 @@ async function refresh() {
app.postMessage({apps: await core.apps()}),
followingDeep(db, [whoami], 2).then(function(f) {
return getRecentPostIds(db, whoami, [].concat([whoami], f), k_posts_max).then(async function(ids) {
return getPosts(db, ids);
}).then(async function(posts) {
var roots = posts.map(function(x) {
try {
return JSON.parse(x.content).root;
} catch {
return null;
}
});
roots = roots.filter(function(root) {
return root && posts.every(post => post.id != root);
});
return [].concat(posts, await getPosts(db, roots));
}).then(function(posts) {
return Promise.all(posts.map(x => app.postMessage({message: x})));
}).then(function() {
return Promise.all(f.map(function(id) {
return Promise.all([
getVotes(db, id).then(function(votes) {
return app.postMessage({votes: votes});
}),
getAbout(db, id).then(function(user) {
return app.postMessage({user: {user: id, about: user}});
}),
following(db, id).then(function(following) {
return app.postMessage({following: {id: id, users: following}});
}),
followers(db, id).then(function(followers) {
return app.postMessage({followers: {id: id, users: followers}});
}),
]);
}));
var posts = await getPosts(db, ids);
var roots = posts.map(function(x) {
try {
return JSON.parse(x.content).root;
} catch {
return null;
}
});
roots = roots.filter(function(root) {
return root && posts.every(post => post.id != root);
});
var all_posts = [].concat(posts, await getPosts(db, roots));
await Promise.all(all_posts.map(x => app.postMessage({message: x})));
return Promise.all([].concat(f.map(function(id) {
return [
getVotes(db, id).then(function(votes) {
return app.postMessage({votes: votes});
}),
getAbout(db, id).then(function(user) {
return app.postMessage({user: {user: id, about: user}});
}),
following(db, id).then(function(following) {
return app.postMessage({following: {id: id, users: following}});
}),
followers(db, id).then(function(followers) {
return app.postMessage({followers: {id: id, users: followers}});
}),
];
})));
});
}),
]);
}