forked from cory/tildefriends
Cory McWilliams
461e7b7d5a
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4634 ed5197a5-7fde-0310-b194-c3ffbd925b24
100 lines
2.2 KiB
JavaScript
100 lines
2.2 KiB
JavaScript
import * as tfrpc from '/tfrpc.js';
|
|
import * as utils from './utils.js';
|
|
|
|
let g_hash;
|
|
let g_collection_notifies = {};
|
|
|
|
tfrpc.register(async function getOwnerIdentities() {
|
|
return ssb.getOwnerIdentities();
|
|
});
|
|
|
|
tfrpc.register(async function getIdentities() {
|
|
return ssb.getIdentities();
|
|
});
|
|
|
|
tfrpc.register(async function query(sql, args) {
|
|
let result = [];
|
|
await ssb.sqlAsync(sql, args, function callback(row) {
|
|
result.push(row);
|
|
});
|
|
return result;
|
|
});
|
|
|
|
tfrpc.register(async function localStorageGet(key) {
|
|
return app.localStorageGet(key);
|
|
});
|
|
|
|
tfrpc.register(async function localStorageSet(key, value) {
|
|
return app.localStorageSet(key, value);
|
|
});
|
|
|
|
tfrpc.register(async function following(ids, depth) {
|
|
return ssb.following(ids, depth);
|
|
});
|
|
|
|
tfrpc.register(async function appendMessage(id, message) {
|
|
print('APPENDING', message);
|
|
return ssb.appendMessageWithIdentity(id, message);
|
|
});
|
|
|
|
tfrpc.register(async function store_blob(blob) {
|
|
if (Array.isArray(blob)) {
|
|
blob = Uint8Array.from(blob);
|
|
}
|
|
return await ssb.blobStore(blob);
|
|
});
|
|
|
|
tfrpc.register(async function get_blob(id) {
|
|
return utf8Decode(await ssb.blobGet(id));
|
|
});
|
|
|
|
let g_new_message_resolve;
|
|
let g_new_message_promise = new Promise(function(resolve, reject) {
|
|
g_new_message_resolve = resolve;
|
|
});
|
|
|
|
function new_message() {
|
|
return g_new_message_promise;
|
|
}
|
|
|
|
ssb.addEventListener('message', function(id) {
|
|
let resolve = g_new_message_resolve;
|
|
g_new_message_promise = new Promise(function(resolve, reject) {
|
|
g_new_message_resolve = resolve;
|
|
});
|
|
if (resolve) {
|
|
resolve();
|
|
}
|
|
});
|
|
|
|
core.register('message', async function message_handler(message) {
|
|
if (message.event == 'hashChange') {
|
|
g_hash = message.hash;
|
|
await tfrpc.rpc.hash_changed(message.hash);
|
|
}
|
|
});
|
|
|
|
tfrpc.register(function set_hash(hash) {
|
|
if (g_hash != hash) {
|
|
return app.setHash(hash);
|
|
}
|
|
});
|
|
|
|
tfrpc.register(function get_hash(id, message) {
|
|
return g_hash;
|
|
});
|
|
|
|
tfrpc.register(async function try_decrypt(id, content) {
|
|
return await ssb.privateMessageDecrypt(id, content);
|
|
});
|
|
tfrpc.register(async function encrypt(id, recipients, content) {
|
|
return await ssb.privateMessageEncrypt(id, recipients, content);
|
|
});
|
|
|
|
tfrpc.register(utils.collection);
|
|
|
|
async function main() {
|
|
await app.setDocument(utf8Decode(await getFile('index.html')));
|
|
}
|
|
|
|
main(); |