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:
2022-06-19 22:08:15 +00:00
parent af3e96c7e8
commit ab58f42f0c
8 changed files with 59 additions and 41 deletions

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: {
name: file.name,
type: file.type,
buffer: buffer,
},
context: context,
}, '*');
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,
});
}).catch(function(e) {
console.log('error', e);
});
@ -324,5 +330,5 @@ window.addEventListener('load', function() {
}
}
});
window.parent.postMessage('ready', '*');
tfrpc.rpc.ready();
});