From 5fbe9c42bc4d3166f7f095cbc43cbffe54c1c617 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Mon, 27 Dec 2021 20:24:14 +0000 Subject: [PATCH] Show new posts at the top of the list. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3704 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- apps/cory/index.json | 2 +- apps/cory/index/app.js | 8 ++++++++ apps/cory/index/tf.js | 5 ++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/apps/cory/index.json b/apps/cory/index.json index 727fd5a4..38ca7d22 100644 --- a/apps/cory/index.json +++ b/apps/cory/index.json @@ -1 +1 @@ -{"type":"tildefriends-app","files":{"app.js":"&R4Rss5VbuH1lalgy8o5NzzccIC5ofSpK+ywc/u3WTCs=.sha256","index.html":"&V0OKwISmSZZH/9QbJyp9rdCgscD5bO9yw4dpzS5pFCw=.sha256","vue-material.js":"&K5cdLqXYCENPak/TCINHQhyJhpS4G9DlZHGwoh/LF2g=.sha256","tf-user.js":"&V9Ol799hM6i1PZDbAS91CMhgx7aENDTJnT+KrwK4Lh4=.sha256","tf-message.js":"&VNC8ptzGXWAVl9LBBZfrk3YmweA8PQ02d7/wZxWXoAA=.sha256","tf.js":"&Vcdlau6e9yBimrokJzoSPvRIS5BNWXcrVO+cO9TUKBg=.sha256","commonmark.min.js":"&5x6ek3tFrKTZX6hXNNyFsjmhvrjmWpUkwuuaiyVV1Us=.sha256","vue.js":"&g1wvA+yHl1sVC+eufTsg9If7ZeVyMTBU+h0tks7ZNzE=.sha256","vue-material-theme-default-dark.css":"&RP2nr+2CR18BpHHw5ST9a5GJUCOG9n0G2kuGkcQioWE=.sha256","vue-material.min.css":"&kGbUM2QgFSyHZRzqQb0b+0S3EVIlZ0AXpdiAVjIhou8=.sha256","roboto.css":"&jJv43Om673mQO5JK0jj7714s5E+5Yrf82H6LcDx7wUs=.sha256","material-icons.css":"&a28PdcVvgq/DxyIvJAx/e+ZOEtOuHnr3kjLWKyzH11M=.sha256"}} \ No newline at end of file +{"type":"tildefriends-app","files":{"app.js":"&sZTfWDIl4CjCU0ZxbkkwvpR+xlBtrgf6meH5+Vx7AHo=.sha256","index.html":"&V0OKwISmSZZH/9QbJyp9rdCgscD5bO9yw4dpzS5pFCw=.sha256","vue-material.js":"&K5cdLqXYCENPak/TCINHQhyJhpS4G9DlZHGwoh/LF2g=.sha256","tf-user.js":"&V9Ol799hM6i1PZDbAS91CMhgx7aENDTJnT+KrwK4Lh4=.sha256","tf-message.js":"&VNC8ptzGXWAVl9LBBZfrk3YmweA8PQ02d7/wZxWXoAA=.sha256","tf.js":"&kQT5zbrevsHUlxIoHw0gBaIhT4dwuCUSazORCwZOiS4=.sha256","commonmark.min.js":"&5x6ek3tFrKTZX6hXNNyFsjmhvrjmWpUkwuuaiyVV1Us=.sha256","vue.js":"&g1wvA+yHl1sVC+eufTsg9If7ZeVyMTBU+h0tks7ZNzE=.sha256","vue-material-theme-default-dark.css":"&RP2nr+2CR18BpHHw5ST9a5GJUCOG9n0G2kuGkcQioWE=.sha256","vue-material.min.css":"&kGbUM2QgFSyHZRzqQb0b+0S3EVIlZ0AXpdiAVjIhou8=.sha256","roboto.css":"&jJv43Om673mQO5JK0jj7714s5E+5Yrf82H6LcDx7wUs=.sha256","material-icons.css":"&a28PdcVvgq/DxyIvJAx/e+ZOEtOuHnr3kjLWKyzH11M=.sha256"}} \ No newline at end of file diff --git a/apps/cory/index/app.js b/apps/cory/index/app.js index ec41b374..d2bfeaa5 100644 --- a/apps/cory/index/app.js +++ b/apps/cory/index/app.js @@ -291,6 +291,14 @@ async function refresh() { ]); } +ssb.addEventListener('message', async function(id) { + var db = await database("ssb"); + var posts = await getPosts(db, [id]); + for (let post of posts) { + await app.postMessage({message: post}); + } +}); + core.register('message', async function(m) { if (m.message == 'ready') { await ready(); diff --git a/apps/cory/index/tf.js b/apps/cory/index/tf.js index d5c41072..2493b4e4 100644 --- a/apps/cory/index/tf.js +++ b/apps/cory/index/tf.js @@ -18,7 +18,10 @@ var g_data = { var g_data_initial = JSON.parse(JSON.stringify(g_data)); window.addEventListener('message', function(event) { var key = Object.keys(event.data)[0]; - if (key + 's' in g_data && Array.isArray(g_data[key + 's'])) { + if (key == 'message') { + g_data.messages.push(event.data[key]); + g_data.messages.sort((x, y) => y.timestamp - x.timestamp); + } else if (key + 's' in g_data && Array.isArray(g_data[key + 's'])) { g_data[key + 's'].push(event.data[key]); } else if (key == 'user') { Vue.set(g_data.users, event.data.user.user, Object.assign({}, g_data.users[event.data.user.user] || {}, event.data.user.about));