diff --git a/apps/apps.json b/apps/apps.json index 762ca759..b00f0733 100644 --- a/apps/apps.json +++ b/apps/apps.json @@ -1,4 +1,5 @@ { "type": "tildefriends-app", - "emoji": "💻" + "emoji": "💻", + "previous": "&33ngNe0YrH3JScss6krlCwddZcXl8C5szonp7DYy4qA=.sha256" } \ No newline at end of file diff --git a/apps/apps/app.js b/apps/apps/app.js index d2a19c6e..04b8f9ea 100644 --- a/apps/apps/app.js +++ b/apps/apps/app.js @@ -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 = ` @@ -40,6 +70,8 @@ async function main() {

Apps

+

Shared Apps

+

Core Apps

@@ -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)}); `; app.setDocument(doc);