forked from cory/tildefriends
62 lines
1.5 KiB
JavaScript
62 lines
1.5 KiB
JavaScript
|
import * as tfrpc from '/tfrpc.js';
|
||
|
|
||
|
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) {
|
||
|
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));
|
||
|
});
|
||
|
|
||
|
async function get_collections(kind) {
|
||
|
let me = await ssb.getIdentities();
|
||
|
let them = await ssb.following(me, 2);
|
||
|
let collections = {};
|
||
|
print('querying');
|
||
|
for (let row of await query(`
|
||
|
SELECT author, content, timestamp
|
||
|
FROM messages JOIN json_each(?) AS id ON messages.author = id.value
|
||
|
WHERE json_extract(content, '$.type') = 'collection' AND json_extract(content, '$.kind') = ?
|
||
|
`, [JSON.stringify(them), kind])) {
|
||
|
print(row);
|
||
|
}
|
||
|
print('done');
|
||
|
return collections;
|
||
|
}
|
||
|
|
||
|
async function main() {
|
||
|
await app.setDocument(utf8Decode(await getFile('index.html')));
|
||
|
}
|
||
|
|
||
|
main();
|