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:
parent
af3e96c7e8
commit
ab58f42f0c
@ -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"}}
|
@ -1,4 +1,4 @@
|
|||||||
"use strict";
|
import * as tfrpc from '/tfrpc.js';
|
||||||
|
|
||||||
const k_posts_max = 40;
|
const k_posts_max = 40;
|
||||||
const k_votes_max = 20;
|
const k_votes_max = 20;
|
||||||
@ -393,10 +393,17 @@ async function getPosts(db, ids) {
|
|||||||
return posts;
|
return posts;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function ready() {
|
tfrpc.register(async function ready() {
|
||||||
g_ready = true;
|
g_ready = true;
|
||||||
return refresh(g_selected);
|
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() {
|
ssb.addEventListener('broadcasts', async function() {
|
||||||
await app.postMessage({broadcasts: await ssb.getBroadcasts()});
|
await app.postMessage({broadcasts: await ssb.getBroadcasts()});
|
||||||
@ -568,9 +575,7 @@ async function addAppSources(message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
core.register('message', async function(m) {
|
core.register('message', async function(m) {
|
||||||
if (m.message == 'ready') {
|
if (m.message) {
|
||||||
await ready();
|
|
||||||
} else if (m.message) {
|
|
||||||
if (m.message.connect) {
|
if (m.message.connect) {
|
||||||
await ssb.connect(m.message.connect);
|
await ssb.connect(m.message.connect);
|
||||||
} else if (m.message.appendMessage) {
|
} else if (m.message.appendMessage) {
|
||||||
|
@ -9,10 +9,10 @@
|
|||||||
<script src="vue.js"></script>
|
<script src="vue.js"></script>
|
||||||
<script src="vue-material.js"></script>
|
<script src="vue-material.js"></script>
|
||||||
<script src="commonmark.min.js"></script>
|
<script src="commonmark.min.js"></script>
|
||||||
<script src="tf-shared.js"></script>
|
<script src="tf-shared.js" type="module"></script>
|
||||||
<script src="tf-user.js"></script>
|
<script src="tf-user.js" type="module"></script>
|
||||||
<script src="tf-message.js"></script>
|
<script src="tf-message.js" type="module"></script>
|
||||||
<script src="tf.js"></script>
|
<script src="tf.js" type="module"></script>
|
||||||
<base target="_top">
|
<base target="_top">
|
||||||
</head>
|
</head>
|
||||||
<body style="color: #fff">
|
<body style="color: #fff">
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
"use strict";
|
import * as tfshared from './tf-shared.js';
|
||||||
|
|
||||||
Vue.component('tf-message', {
|
Vue.component('tf-message', {
|
||||||
props: ['message', 'messages', 'votes'],
|
props: ['message', 'messages', 'votes'],
|
||||||
data: function() { return { showRaw: false } },
|
data: function() { return { showRaw: false } },
|
||||||
@ -39,7 +40,7 @@ Vue.component('tf-message', {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
markdown: markdown,
|
markdown: tfshared.markdown,
|
||||||
set_reply: function() {
|
set_reply: function() {
|
||||||
g_data.reply_root = this.content_json.root || this.message.id;
|
g_data.reply_root = this.content_json.root || this.message.id;
|
||||||
g_data.reply_branch = this.message.id;
|
g_data.reply_branch = this.message.id;
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
"use strict";
|
export function markdown(md) {
|
||||||
|
|
||||||
function markdown(md) {
|
|
||||||
var reader = new commonmark.Parser({safe: true});
|
var reader = new commonmark.Parser({safe: true});
|
||||||
var writer = new commonmark.HtmlRenderer();
|
var writer = new commonmark.HtmlRenderer();
|
||||||
var parsed = reader.parse(md || '');
|
var parsed = reader.parse(md || '');
|
||||||
|
@ -1,17 +1,15 @@
|
|||||||
"use strict";
|
import * as tf from './tf.js';
|
||||||
|
|
||||||
Vue.component('tf-user', {
|
Vue.component('tf-user', {
|
||||||
props: ['id'],
|
props: ['id'],
|
||||||
computed: {
|
computed: {
|
||||||
following: {
|
following: {
|
||||||
get: function() {
|
get: function() {
|
||||||
return g_data.users &&
|
return tf.g_data.users?.[tf.g_data.whoami]?.following?.[this.id];
|
||||||
g_data.users[g_data.whoami] &&
|
|
||||||
g_data.users[g_data.whoami].following &&
|
|
||||||
g_data.users[g_data.whoami].following[this.id];
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
whoami: { get: function() { return g_data.whoami; } },
|
whoami: { get: function() { return tf.g_data.whoami; } },
|
||||||
users: { get: function() { return g_data.users; } },
|
users: { get: function() { return tf.g_data.users; } },
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
show_user: function() {
|
show_user: function() {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
"use strict";
|
import * as tfrpc from '/static/tfrpc.js';
|
||||||
var g_data = {
|
import * as tfshared from './tf-shared.js';
|
||||||
|
|
||||||
|
export var g_data = {
|
||||||
whoami: null,
|
whoami: null,
|
||||||
connections: [],
|
connections: [],
|
||||||
messages: [],
|
messages: [],
|
||||||
@ -176,6 +178,9 @@ function processMessages() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener('message', function(event) {
|
window.addEventListener('message', function(event) {
|
||||||
|
if (event.data.message === 'tfrpc') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
g_message_queue.push(event);
|
g_message_queue.push(event);
|
||||||
if (!g_process_pending) {
|
if (!g_process_pending) {
|
||||||
g_process_pending = true;
|
g_process_pending = true;
|
||||||
@ -217,7 +222,7 @@ window.addEventListener('load', function() {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
markdown: markdown,
|
markdown: tfshared.markdown,
|
||||||
refresh: function() {
|
refresh: function() {
|
||||||
window.parent.postMessage({refresh: true}, '*');
|
window.parent.postMessage({refresh: true}, '*');
|
||||||
},
|
},
|
||||||
@ -272,14 +277,15 @@ window.addEventListener('load', function() {
|
|||||||
input.onchange = function(event) {
|
input.onchange = function(event) {
|
||||||
var file = event.target.files[0];
|
var file = event.target.files[0];
|
||||||
file.arrayBuffer().then(function(buffer) {
|
file.arrayBuffer().then(function(buffer) {
|
||||||
window.parent.postMessage({action: 'storeBlob',
|
let bin = Array.from(new Uint8Array(buffer));
|
||||||
blob: {
|
return tfrpc.rpc.store_blob(bin);
|
||||||
name: file.name,
|
}).then(function(id) {
|
||||||
type: file.type,
|
g_data.post_text = `${g_data.post_text || ''}\n![${file.name}](${id})`;
|
||||||
buffer: buffer,
|
Vue.set(g_data.mentions, id, {
|
||||||
},
|
link: id,
|
||||||
context: context,
|
name: file.name,
|
||||||
}, '*');
|
type: file.type,
|
||||||
|
});
|
||||||
}).catch(function(e) {
|
}).catch(function(e) {
|
||||||
console.log('error', e);
|
console.log('error', e);
|
||||||
});
|
});
|
||||||
@ -324,5 +330,5 @@ window.addEventListener('load', function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
window.parent.postMessage('ready', '*');
|
tfrpc.rpc.ready();
|
||||||
});
|
});
|
@ -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) {
|
function call_rpc(message) {
|
||||||
if (message && message.message === 'tfrpc') {
|
if (message && message.message === 'tfrpc') {
|
||||||
if (message.method) {
|
if (message.method) {
|
||||||
@ -33,14 +41,16 @@ function call_rpc(message) {
|
|||||||
if (method) {
|
if (method) {
|
||||||
let response = {message: 'tfrpc', id: message.id};
|
let response = {message: 'tfrpc', id: message.id};
|
||||||
try {
|
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) {
|
} catch (error) {
|
||||||
response.error = error;
|
response.error = error;
|
||||||
}
|
send(response);
|
||||||
if (k_is_browser) {
|
|
||||||
window.parent.postMessage(response, '*');
|
|
||||||
} else {
|
|
||||||
app.postMessage(response);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new Error(message.method + ' not found.');
|
throw new Error(message.method + ' not found.');
|
||||||
|
Loading…
Reference in New Issue
Block a user