From d8657866f566a7b0ac5d95b76ca9d2313b17d3cc Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Sat, 9 Jan 2021 22:19:52 +0000 Subject: [PATCH] This lets me post a 'tildefriends-app' message. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3634 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- apps/cory/index.json | 2 +- apps/cory/index/app.js | 15 +++++++++++---- apps/cory/index/index.html | 25 ++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/apps/cory/index.json b/apps/cory/index.json index 24c9c94f..c1e723f2 100644 --- a/apps/cory/index.json +++ b/apps/cory/index.json @@ -1 +1 @@ -{"type":"tildefriends-app","files":{"app.js":"&6uFJG2C0kZar1Aj+7p2/KzYEBXgmK/uJSt7aIJqenN4=.sha256","index.html":"&TFtniuUIVO7XeWCgwmqPAmuBzpGX6slxJQcPMEr+860=.sha256","vue-material.js":"&K5cdLqXYCENPak/TCINHQhyJhpS4G9DlZHGwoh/LF2g=.sha256"}} \ No newline at end of file +{"type":"tildefriends-app","files":{"app.js":"&WiH+BcLge0Imgpcfo/lecF92raEkf2cLyxr+GQKM5DU=.sha256","index.html":"&z528csPu5+I+634DKxY3EBOQYAAVt1hLOQiWj+gW+qM=.sha256","vue-material.js":"&K5cdLqXYCENPak/TCINHQhyJhpS4G9DlZHGwoh/LF2g=.sha256"}} \ No newline at end of file diff --git a/apps/cory/index/app.js b/apps/cory/index/app.js index 532d0645..7e478c9c 100644 --- a/apps/cory/index/app.js +++ b/apps/cory/index/app.js @@ -168,7 +168,7 @@ async function getAbout(db, id) { "UNION SELECT MAX(sequence) as sequence, NULL FROM messages WHERE author = ?2 "+ "ORDER BY sequence", [f.sequence, id], - async function(row) { + function(row) { f.sequence = row.sequence; if (row.content) { var about = {}; @@ -199,7 +199,7 @@ function fnv32a(value) } async function getRecentPostIds(db, id, ids, limit) { - const k_version = 6; + const k_version = 7; var o = await db.get(id + ':recent_posts'); var recent = []; var f = o ? JSON.parse(o) : o; @@ -215,7 +215,7 @@ async function getRecentPostIds(db, id, ids, limit) { "WHERE "+ " rowid > ? AND "+ " author IN (" + ids.map(x => '?').join(", ") + ") AND "+ - " json_extract(content, '$.type') = 'post' "+ + " json_extract(content, '$.type') IN ('post', 'tildefriends-app') "+ "UNION SELECT MAX(rowid) as rowid, NULL FROM messages "+ "ORDER BY rowid DESC LIMIT ?", [].concat([f.rowid], ids, [limit + 1]), @@ -280,7 +280,7 @@ async function getPosts(db, ids) { await ssb.sqlStream( "SELECT rowid, * FROM messages WHERE id IN (" + ids.map(x => "?").join(", ") + ")", ids, - async function(row) { + function(row) { try { posts.push(row); } catch { @@ -312,6 +312,7 @@ async function refresh() { app.postMessage({pubs: await visiblePubs(db, whoami)}), app.postMessage({broadcasts: await ssb.getBroadcasts()}), app.postMessage({connections: await ssb.connections()}), + app.postMessage({apps: await core.apps()}), followingDeep(db, [whoami], 2).then(function(f) { getRecentPostIds(db, whoami, [].concat([whoami], f), k_posts_max).then(async function(ids) { return getPosts(db, ids); @@ -357,6 +358,12 @@ core.register('message', async function(m) { await ssb.post(m.message.post); } else if (m.message.appendMessage) { await ssb.appendMessage(m.message.appendMessage); + } else if (m.message.share_app) { + var app = await ssb.blobGet(m.message.share_app.app); + app = JSON.parse(utf8Decode(app)); + app.type = 'tildefriends-app'; + app.name = m.message.share_app.name; + await ssb.appendMessage(app); } else if (m.message.user) { await sendUser(await database("ssb"), m.message.user); } else if (m.message.refresh) { diff --git a/apps/cory/index/index.html b/apps/cory/index/index.html index 725ed116..1ad2fc49 100644 --- a/apps/cory/index/index.html +++ b/apps/cory/index/index.html @@ -21,6 +21,8 @@ connect: null, pubs: [], votes: [], + apps: {}, + share_app: null, }; var g_data_initial = JSON.parse(JSON.stringify(g_data)); window.addEventListener('message', function(event) { @@ -43,6 +45,8 @@ g_data.broadcasts = event.data.broadcasts; } else if (key == 'pubs') { g_data.pubs = event.data.pubs; + } else if (key == 'apps') { + g_data.apps = event.data.apps; } else if (key == 'clear') { Object.keys(g_data_initial).forEach(function(key) { Vue.set(g_data, key, JSON.parse(JSON.stringify(g_data_initial[key]))); @@ -196,7 +200,15 @@ data: g_data, methods: { post_message: function() { - window.parent.postMessage({post: document.getElementById('post_text').value}, '*'); + if (g_data.share_app) { + window.parent.postMessage({share_app: { + app: g_data.apps[g_data.share_app], + text: document.getElementById('post_text').value, + }}, '*'); + } else { + window.parent.postMessage({post: document.getElementById('post_text').value}, '*'); + } + document.getElementById('post_text').value = ''; }, ssb_connect: function(connection) { window.parent.postMessage({connect: connection}, '*'); @@ -264,12 +276,23 @@
What's up?
+ + {{share_app}}: {{apps[share_app]}} + + + Share App + + + {{app}} + + + Submit Post