List shared apps in the apps app. App.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4777 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2024-01-17 22:43:32 +00:00
parent 6e57845512
commit 455befc18f
2 changed files with 38 additions and 3 deletions

View File

@ -1,4 +1,5 @@
{
"type": "tildefriends-app",
"emoji": "💻"
"emoji": "💻",
"previous": "&33ngNe0YrH3JScss6krlCwddZcXl8C5szonp7DYy4qA=.sha256"
}

View File

@ -8,9 +8,39 @@ async function fetch_info(apps) {
return result;
}
async function fetch_shared_apps() {
let messages = {};
await ssb.sqlAsync(`
SELECT messages.*
FROM messages_fts('"application/tildefriends"')
JOIN messages ON messages.rowid = messages_fts.rowid
ORDER BY timestamp
`,
[],
function(row) {
let content = JSON.parse(row.content);
for (let mention of content.mentions) {
if (mention?.type === 'application/tildefriends') {
messages[JSON.stringify([row.author, mention.name])] = {
message: row,
blob: mention.link,
name: mention.name,
};
}
}
});
let result = {};
for (let app of Object.values(messages).sort((x, y) => y.message.timestamp - x.message.timestamp)) {
result[app.name] = JSON.parse(utf8Decode(await ssb.blobGet(app.blob)));
result[app.name].blob_id = app.blob;
}
return result;
}
async function main() {
var apps = await fetch_info(await core.apps());
var core_apps = await fetch_info(await core.apps('core'));
let shared_apps = await fetch_shared_apps();
var doc = `<!DOCTYPE html>
<html>
<head>
@ -40,6 +70,8 @@ async function main() {
<body style="background: #888">
<h1 id="apps_title">Apps</h1>
<div id="apps" class="container"></div>
<h1>Shared Apps</h1>
<div id="shared_apps" class="container"></div>
<h1>Core Apps</h1>
<div id="core_apps" class="container"></div>
</body>
@ -50,18 +82,19 @@ async function main() {
let div = list.appendChild(document.createElement('div'));
div.classList.add('app');
let href = name ? '/~' + name + '/' + app + '/' : ('/' + apps[app].blob_id + '/');
let icon_a = document.createElement('a');
let icon = document.createElement('div');
icon.appendChild(document.createTextNode(apps[app].emoji || '📦'));
icon.style.fontSize = 'xxx-large';
icon_a.appendChild(icon);
icon_a.href = '/~' + name + '/' + app + '/';
icon_a.href = href;
icon_a.target = '_top';
div.appendChild(icon_a);
let a = document.createElement('a');
a.appendChild(document.createTextNode(app));
a.href = '/~' + name + '/' + app + '/';
a.href = href;
a.target = '_top';
div.appendChild(a);
}
@ -69,6 +102,7 @@ async function main() {
document.getElementById('apps_title').innerText = "~${escape(core.user.credentials?.session?.name || 'guest')}'s Apps";
populate_apps('apps', '${core.user.credentials?.session?.name}', ${JSON.stringify(apps)});
populate_apps('core_apps', 'core', ${JSON.stringify(core_apps)});
populate_apps('shared_apps', undefined, ${JSON.stringify(shared_apps)});
</script>
</html>`;
app.setDocument(doc);