diff --git a/apps/apps.json b/apps/apps.json index b00f0733..7b0370a0 100644 --- a/apps/apps.json +++ b/apps/apps.json @@ -1,5 +1,5 @@ { "type": "tildefriends-app", "emoji": "💻", - "previous": "&33ngNe0YrH3JScss6krlCwddZcXl8C5szonp7DYy4qA=.sha256" + "previous": "&RdVEsVscZm3aWzcMrEZS8mskO5tUmvaEUihex2MMfZQ=.sha256" } \ No newline at end of file diff --git a/apps/apps/app.js b/apps/apps/app.js index 4300353d..d31f1ab7 100644 --- a/apps/apps/app.js +++ b/apps/apps/app.js @@ -1,15 +1,31 @@ +/** + * Fetches information about the applications + * @param apps Record + * @returns an object including the apps' name, emoji, and blobs ids + */ async function fetch_info(apps) { let result = {}; + + // For each app for (let [key, value] of Object.entries(apps)) { + // Get it's blob and parse it let blob = await ssb.blobGet(value); blob = blob ? utf8Decode(blob) : '{}'; + + // Add it to the result object result[key] = JSON.parse(blob); } + return result; } +/** + * + * + */ async function fetch_shared_apps() { let messages = {}; + await ssb.sqlAsync(` SELECT messages.* FROM messages_fts('"application/tildefriends"') @@ -29,6 +45,7 @@ async function fetch_shared_apps() { } } }); + let result = {}; for (let app of Object.values(messages).sort((x, y) => y.message.timestamp - x.message.timestamp)) { let app_object = JSON.parse(utf8Decode(await ssb.blobGet(app.blob))); @@ -41,18 +58,26 @@ async function fetch_shared_apps() { } 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 = ` - - - - - -

Apps

-
-

Shared Apps

-
-

Core Apps

-
- - -`; - app.setDocument(doc); + + 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)}); + `; + + // Build the document + const document = ` + + + + + + + + ${body} + + + + `; + + // Send it to the browser + app.setDocument(document); } main();