Append SSB messages by RPC so that we know if it succeeded.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3963 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2022-08-14 19:14:13 +00:00
parent 0518c5dd21
commit 69991abbb4
3 changed files with 35 additions and 23 deletions

View File

@ -1 +1 @@
{"type":"tildefriends-app","files":{"app.js":"&W/og3+Bmi2YJJ9PudClLLIhK5ZgplUMpsOowSF5o05s=.sha256","index.html":"&ye2GeqCrDi3Dbl3UVIfE8H5GzCxN8O46FWj5zhLnZAw=.sha256","vue-material.js":"&K5cdLqXYCENPak/TCINHQhyJhpS4G9DlZHGwoh/LF2g=.sha256","tf-user.js":"&cI/JLy83mOngcqYCEP8Vej8urDvAQAV1WxFsL67/K3M=.sha256","tf-message.js":"&JVARtJEQkq3XjjL0Jv/NUDkO2WZnXGIqkWsqYvTPXBI=.sha256","tf.js":"&WVJ7+D8VMeU7+yRnD3hDsmm2nIKZtO8WKIdB0v+GU14=.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":"&LXyUSm6zSakN/ghJlZ1Qg2VJfV5alhN0gl8F7txIIOU=.sha256","style.css":"&qegBNCrVUihxffRUxGFuG/6u+0Y6d18zHtfNHBZtZ04=.sha256"}} {"type":"tildefriends-app","files":{"app.js":"&5Pyy6krf0jbECZ9Qp+S4FwmW4bka5aqdxQ8Qjjocyqg=.sha256","index.html":"&ye2GeqCrDi3Dbl3UVIfE8H5GzCxN8O46FWj5zhLnZAw=.sha256","vue-material.js":"&K5cdLqXYCENPak/TCINHQhyJhpS4G9DlZHGwoh/LF2g=.sha256","tf-user.js":"&cI/JLy83mOngcqYCEP8Vej8urDvAQAV1WxFsL67/K3M=.sha256","tf-message.js":"&JVARtJEQkq3XjjL0Jv/NUDkO2WZnXGIqkWsqYvTPXBI=.sha256","tf.js":"&54CRUokNTNobXHZ5vHyrz3ToCnyhWV72K7zOS3Rip9w=.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":"&LXyUSm6zSakN/ghJlZ1Qg2VJfV5alhN0gl8F7txIIOU=.sha256","style.css":"&qegBNCrVUihxffRUxGFuG/6u+0Y6d18zHtfNHBZtZ04=.sha256"}}

View File

@ -575,6 +575,11 @@ tfrpc.register(async function createIdentity() {
return ssb.createIdentity(); return ssb.createIdentity();
}); });
tfrpc.register(async function appendMessage(message) {
await addAppSources(message);
return ssb.appendMessageWithIdentity(g_whoami, message);
});
async function addAppSources(message) { async function addAppSources(message) {
if (message.mentions) { if (message.mentions) {
for (let mention of message.mentions) { for (let mention of message.mentions) {
@ -596,9 +601,6 @@ core.register('message', async function(m) {
if (m.message) { 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) {
await addAppSources(m.message.appendMessage);
await ssb.appendMessageWithIdentity(g_whoami, m.message.appendMessage);
} }
} else if (m.event == 'hashChange') { } else if (m.event == 'hashChange') {
let hash = m.hash.length > 1 ? m.hash.substring(1) : null; let hash = m.hash.length > 1 ? m.hash.substring(1) : null;

View File

@ -198,11 +198,14 @@ window.addEventListener('load', function() {
if (Object.keys(g_data.mentions).length) { if (Object.keys(g_data.mentions).length) {
message.mentions = Object.values(g_data.mentions); message.mentions = Object.values(g_data.mentions);
} }
window.parent.postMessage({appendMessage: message}, '*'); tfrpc.rpc.appendMessage(message).then(function() {
g_data.post_text = null; g_data.post_text = null;
Vue.set(g_data, 'mentions', {}); Vue.set(g_data, 'mentions', {});
g_data.reply_root = null; g_data.reply_root = null;
g_data.reply_branch = null; g_data.reply_branch = null;
}).catch(function(error) {
alert(error?.message);
});
}, },
ssb_connect: function(connection) { ssb_connect: function(connection) {
window.parent.postMessage({connect: connection}, '*'); window.parent.postMessage({connect: connection}, '*');
@ -229,35 +232,42 @@ window.addEventListener('load', function() {
Vue.delete(g_data.mentions, link); Vue.delete(g_data.mentions, link);
}, },
save_profile: function() { save_profile: function() {
var message = { tfrpc.rpc.appendMessage({
appendMessage: {
type: 'about', type: 'about',
about: g_data.selected, about: g_data.selected,
name: g_data.edit_profile_name, name: g_data.edit_profile_name,
description: g_data.edit_profile_description, description: g_data.edit_profile_description,
image: g_data.edit_profile_image, image: g_data.edit_profile_image,
} }).catch(function(error) {
}; alert(error?.message);
window.parent.postMessage(message, '*'); });
}, },
follow: function(id) { follow: function(id) {
if (confirm('Are you sure you want to follow ' + id + '?')) { if (confirm('Are you sure you want to follow ' + id + '?')) {
window.parent.postMessage({appendMessage: {type: "contact", following: true, contact: id}}, '*'); tfrpc.rpc.appendMessage({type: "contact", following: true, contact: id}).catch(function(error) {
alert(error?.message);
});
} }
}, },
unfollow: function(id) { unfollow: function(id) {
if (confirm('Are you sure you want to unfollow ' + id + '?')) { if (confirm('Are you sure you want to unfollow ' + id + '?')) {
window.parent.postMessage({appendMessage: {type: "contact", following: false, contact: id}}, '*'); tfrpc.rpc.appendMessage({type: "contact", following: false, contact: id}).catch(function(error) {
alert(error?.message);
});
} }
}, },
block: function(id) { block: function(id) {
if (confirm('Are you sure you want to block ' + id + '?')) { if (confirm('Are you sure you want to block ' + id + '?')) {
window.parent.postMessage({appendMessage: {type: "contact", blocking: true, contact: id}}, '*'); tfrpc.rpc.appendMessage({type: "contact", blocking: true, contact: id}).catch(function(error) {
alert(error?.message);
});
} }
}, },
unblock: function(id) { unblock: function(id) {
if (confirm('Are you sure you want to unblock ' + id + '?')) { if (confirm('Are you sure you want to unblock ' + id + '?')) {
window.parent.postMessage({appendMessage: {type: "contact", blocking: false, contact: id}}, '*'); tfrpc.rpc.appendMessage({type: "contact", blocking: false, contact: id}).catch(function(error) {
alert(error?.message);
});
} }
}, },
set_hash() { set_hash() {