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:
2022-08-14 19:14:13 +00:00
parent 0518c5dd21
commit 69991abbb4
3 changed files with 35 additions and 23 deletions

View File

@ -575,6 +575,11 @@ tfrpc.register(async function createIdentity() {
return ssb.createIdentity();
});
tfrpc.register(async function appendMessage(message) {
await addAppSources(message);
return ssb.appendMessageWithIdentity(g_whoami, message);
});
async function addAppSources(message) {
if (message.mentions) {
for (let mention of message.mentions) {
@ -596,9 +601,6 @@ core.register('message', async function(m) {
if (m.message) {
if (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') {
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) {
message.mentions = Object.values(g_data.mentions);
}
window.parent.postMessage({appendMessage: message}, '*');
g_data.post_text = null;
Vue.set(g_data, 'mentions', {});
g_data.reply_root = null;
g_data.reply_branch = null;
tfrpc.rpc.appendMessage(message).then(function() {
g_data.post_text = null;
Vue.set(g_data, 'mentions', {});
g_data.reply_root = null;
g_data.reply_branch = null;
}).catch(function(error) {
alert(error?.message);
});
},
ssb_connect: function(connection) {
window.parent.postMessage({connect: connection}, '*');
@ -229,35 +232,42 @@ window.addEventListener('load', function() {
Vue.delete(g_data.mentions, link);
},
save_profile: function() {
var message = {
appendMessage: {
type: 'about',
about: g_data.selected,
name: g_data.edit_profile_name,
description: g_data.edit_profile_description,
image: g_data.edit_profile_image,
}
};
window.parent.postMessage(message, '*');
tfrpc.rpc.appendMessage({
type: 'about',
about: g_data.selected,
name: g_data.edit_profile_name,
description: g_data.edit_profile_description,
image: g_data.edit_profile_image,
}).catch(function(error) {
alert(error?.message);
});
},
follow: function(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) {
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) {
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) {
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() {