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:
parent
6e57845512
commit
455befc18f
@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
"type": "tildefriends-app",
|
"type": "tildefriends-app",
|
||||||
"emoji": "💻"
|
"emoji": "💻",
|
||||||
|
"previous": "&33ngNe0YrH3JScss6krlCwddZcXl8C5szonp7DYy4qA=.sha256"
|
||||||
}
|
}
|
@ -8,9 +8,39 @@ async function fetch_info(apps) {
|
|||||||
return result;
|
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() {
|
async function main() {
|
||||||
var apps = await fetch_info(await core.apps());
|
var apps = await fetch_info(await core.apps());
|
||||||
var core_apps = await fetch_info(await core.apps('core'));
|
var core_apps = await fetch_info(await core.apps('core'));
|
||||||
|
let shared_apps = await fetch_shared_apps();
|
||||||
var doc = `<!DOCTYPE html>
|
var doc = `<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
@ -40,6 +70,8 @@ async function main() {
|
|||||||
<body style="background: #888">
|
<body style="background: #888">
|
||||||
<h1 id="apps_title">Apps</h1>
|
<h1 id="apps_title">Apps</h1>
|
||||||
<div id="apps" class="container"></div>
|
<div id="apps" class="container"></div>
|
||||||
|
<h1>Shared Apps</h1>
|
||||||
|
<div id="shared_apps" class="container"></div>
|
||||||
<h1>Core Apps</h1>
|
<h1>Core Apps</h1>
|
||||||
<div id="core_apps" class="container"></div>
|
<div id="core_apps" class="container"></div>
|
||||||
</body>
|
</body>
|
||||||
@ -50,18 +82,19 @@ async function main() {
|
|||||||
let div = list.appendChild(document.createElement('div'));
|
let div = list.appendChild(document.createElement('div'));
|
||||||
div.classList.add('app');
|
div.classList.add('app');
|
||||||
|
|
||||||
|
let href = name ? '/~' + name + '/' + app + '/' : ('/' + apps[app].blob_id + '/');
|
||||||
let icon_a = document.createElement('a');
|
let icon_a = document.createElement('a');
|
||||||
let icon = document.createElement('div');
|
let icon = document.createElement('div');
|
||||||
icon.appendChild(document.createTextNode(apps[app].emoji || '📦'));
|
icon.appendChild(document.createTextNode(apps[app].emoji || '📦'));
|
||||||
icon.style.fontSize = 'xxx-large';
|
icon.style.fontSize = 'xxx-large';
|
||||||
icon_a.appendChild(icon);
|
icon_a.appendChild(icon);
|
||||||
icon_a.href = '/~' + name + '/' + app + '/';
|
icon_a.href = href;
|
||||||
icon_a.target = '_top';
|
icon_a.target = '_top';
|
||||||
div.appendChild(icon_a);
|
div.appendChild(icon_a);
|
||||||
|
|
||||||
let a = document.createElement('a');
|
let a = document.createElement('a');
|
||||||
a.appendChild(document.createTextNode(app));
|
a.appendChild(document.createTextNode(app));
|
||||||
a.href = '/~' + name + '/' + app + '/';
|
a.href = href;
|
||||||
a.target = '_top';
|
a.target = '_top';
|
||||||
div.appendChild(a);
|
div.appendChild(a);
|
||||||
}
|
}
|
||||||
@ -69,6 +102,7 @@ async function main() {
|
|||||||
document.getElementById('apps_title').innerText = "~${escape(core.user.credentials?.session?.name || 'guest')}'s Apps";
|
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('apps', '${core.user.credentials?.session?.name}', ${JSON.stringify(apps)});
|
||||||
populate_apps('core_apps', 'core', ${JSON.stringify(core_apps)});
|
populate_apps('core_apps', 'core', ${JSON.stringify(core_apps)});
|
||||||
|
populate_apps('shared_apps', undefined, ${JSON.stringify(shared_apps)});
|
||||||
</script>
|
</script>
|
||||||
</html>`;
|
</html>`;
|
||||||
app.setDocument(doc);
|
app.setDocument(doc);
|
||||||
|
Loading…
Reference in New Issue
Block a user