Module-ified the ssb app and started to integrate tfrpc.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3911 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2022-06-19 22:08:15 +00:00
parent af3e96c7e8
commit ab58f42f0c
8 changed files with 59 additions and 41 deletions

View File

@ -1 +1 @@
{"type":"tildefriends-app","files":{"app.js":"&/KEl8MyPA3758dy9OHuLWMsU7PCbrxWm8B2Lp6D6VdA=.sha256","index.html":"&1A20L0gv3iOk6hqTdxrRX3yM1jNnUlSn9+NOC+HMBSk=.sha256","vue-material.js":"&K5cdLqXYCENPak/TCINHQhyJhpS4G9DlZHGwoh/LF2g=.sha256","tf-user.js":"&BwircO1usZwNmgxReG3COtztqg6bVYnVenTKsLhOeLI=.sha256","tf-message.js":"&qYRsJfdVWpS/ZSAQ0+jeP4n61qziThP5GlhCeOtDYhQ=.sha256","tf.js":"&iy81728sf718+imn/XrU+T3zjJKbbuo+tlFU7wubrcw=.sha256","commonmark.min.js":"&EP0OeR9zyLwZannz+0ga4s9AGES2RLvvIIQYHqqV6+k=.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","tf-shared.js":"&g17mCj0bfk0tw0sYk2VMU67Bt8Hdznjl44E01TxQF5Y=.sha256","style.css":"&qegBNCrVUihxffRUxGFuG/6u+0Y6d18zHtfNHBZtZ04=.sha256"}}
{"type":"tildefriends-app","files":{"app.js":"&7v8vYyzZmo/SFkcyrTPnlv/jZc9xt36zv7N9ZTdEt7s=.sha256","index.html":"&TGAqOmpnOigx4XQbFix82ugZEOfR1Gdc2zMWUQMSvwI=.sha256","vue-material.js":"&K5cdLqXYCENPak/TCINHQhyJhpS4G9DlZHGwoh/LF2g=.sha256","tf-user.js":"&smJOHGgIsKwQXeEJD3VbHX4A+vhr1Se54WlSHUP/Km8=.sha256","tf-message.js":"&nf978NOZPz1i97/nYMA2kHOm0HTlF4pm5UgpqE8+JSE=.sha256","tf.js":"&ZXBUsG/ZZWxd1RtrdcPPvpH4Qa2XvUUgL0x9KNqqSe0=.sha256","commonmark.min.js":"&EP0OeR9zyLwZannz+0ga4s9AGES2RLvvIIQYHqqV6+k=.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","tf-shared.js":"&MPINm55jkpz2rrNbwsYl09PKGvbgL3nwgBy6CMQkSnw=.sha256","style.css":"&qegBNCrVUihxffRUxGFuG/6u+0Y6d18zHtfNHBZtZ04=.sha256"}}

View File

@ -1,4 +1,4 @@
"use strict";
import * as tfrpc from '/tfrpc.js';
const k_posts_max = 40;
const k_votes_max = 20;
@ -393,10 +393,17 @@ async function getPosts(db, ids) {
return posts;
}
async function ready() {
tfrpc.register(async function ready() {
g_ready = true;
return refresh(g_selected);
});
tfrpc.register(async function store_blob(blob) {
if (Array.isArray(blob)) {
blob = Uint8Array.from(blob);
}
return await ssb.blobStore(blob);
});
ssb.addEventListener('broadcasts', async function() {
await app.postMessage({broadcasts: await ssb.getBroadcasts()});
@ -568,9 +575,7 @@ async function addAppSources(message) {
}
core.register('message', async function(m) {
if (m.message == 'ready') {
await ready();
} else if (m.message) {
if (m.message) {
if (m.message.connect) {
await ssb.connect(m.message.connect);
} else if (m.message.appendMessage) {

View File

@ -9,10 +9,10 @@
<script src="vue.js"></script>
<script src="vue-material.js"></script>
<script src="commonmark.min.js"></script>
<script src="tf-shared.js"></script>
<script src="tf-user.js"></script>
<script src="tf-message.js"></script>
<script src="tf.js"></script>
<script src="tf-shared.js" type="module"></script>
<script src="tf-user.js" type="module"></script>
<script src="tf-message.js" type="module"></script>
<script src="tf.js" type="module"></script>
<base target="_top">
</head>
<body style="color: #fff">

View File

@ -1,4 +1,5 @@
"use strict";
import * as tfshared from './tf-shared.js';
Vue.component('tf-message', {
props: ['message', 'messages', 'votes'],
data: function() { return { showRaw: false } },
@ -39,7 +40,7 @@ Vue.component('tf-message', {
},
},
methods: {
markdown: markdown,
markdown: tfshared.markdown,
set_reply: function() {
g_data.reply_root = this.content_json.root || this.message.id;
g_data.reply_branch = this.message.id;

View File

@ -1,6 +1,4 @@
"use strict";
function markdown(md) {
export function markdown(md) {
var reader = new commonmark.Parser({safe: true});
var writer = new commonmark.HtmlRenderer();
var parsed = reader.parse(md || '');

View File

@ -1,17 +1,15 @@
"use strict";
import * as tf from './tf.js';
Vue.component('tf-user', {
props: ['id'],
computed: {
following: {
get: function() {
return g_data.users &&
g_data.users[g_data.whoami] &&
g_data.users[g_data.whoami].following &&
g_data.users[g_data.whoami].following[this.id];
return tf.g_data.users?.[tf.g_data.whoami]?.following?.[this.id];
},
},
whoami: { get: function() { return g_data.whoami; } },
users: { get: function() { return g_data.users; } },
whoami: { get: function() { return tf.g_data.whoami; } },
users: { get: function() { return tf.g_data.users; } },
},
methods: {
show_user: function() {

View File

@ -1,5 +1,7 @@
"use strict";
var g_data = {
import * as tfrpc from '/static/tfrpc.js';
import * as tfshared from './tf-shared.js';
export var g_data = {
whoami: null,
connections: [],
messages: [],
@ -176,6 +178,9 @@ function processMessages() {
}
window.addEventListener('message', function(event) {
if (event.data.message === 'tfrpc') {
return;
}
g_message_queue.push(event);
if (!g_process_pending) {
g_process_pending = true;
@ -217,7 +222,7 @@ window.addEventListener('load', function() {
return undefined;
}
},
markdown: markdown,
markdown: tfshared.markdown,
refresh: function() {
window.parent.postMessage({refresh: true}, '*');
},
@ -272,14 +277,15 @@ window.addEventListener('load', function() {
input.onchange = function(event) {
var file = event.target.files[0];
file.arrayBuffer().then(function(buffer) {
window.parent.postMessage({action: 'storeBlob',
blob: {
let bin = Array.from(new Uint8Array(buffer));
return tfrpc.rpc.store_blob(bin);
}).then(function(id) {
g_data.post_text = `${g_data.post_text || ''}\n![${file.name}](${id})`;
Vue.set(g_data.mentions, id, {
link: id,
name: file.name,
type: file.type,
buffer: buffer,
},
context: context,
}, '*');
});
}).catch(function(e) {
console.log('error', e);
});
@ -324,5 +330,5 @@ window.addEventListener('load', function() {
}
}
});
window.parent.postMessage('ready', '*');
tfrpc.rpc.ready();
});

View File

@ -26,6 +26,14 @@ function make_rpc(target, prop, receiver) {
}
}
function send(response) {
if (k_is_browser) {
window.parent.postMessage(response, '*');
} else {
app.postMessage(response);
}
}
function call_rpc(message) {
if (message && message.message === 'tfrpc') {
if (message.method) {
@ -33,14 +41,16 @@ function call_rpc(message) {
if (method) {
let response = {message: 'tfrpc', id: message.id};
try {
response.result = method(...message.params);
Promise.resolve(method(...message.params)).then(function(result) {
response.result = result;
send(response);
}).catch(function(error) {
response.error = error;
send(response);
});
} catch (error) {
response.error = error;
}
if (k_is_browser) {
window.parent.postMessage(response, '*');
} else {
app.postMessage(response);
send(response);
}
} else {
throw new Error(message.method + ' not found.');