| 
									
										
										
										
											2023-10-30 00:22:30 +00:00
										 |  |  | import * as tfrpc from '/tfrpc.js'; | 
					
						
							| 
									
										
										
										
											2023-11-16 01:33:00 +00:00
										 |  |  | import * as utils from './utils.js'; | 
					
						
							| 
									
										
										
										
											2023-10-30 00:22:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-01 22:21:42 +00:00
										 |  |  | let g_hash; | 
					
						
							| 
									
										
										
										
											2023-11-04 02:00:35 +00:00
										 |  |  | let g_collection_notifies = {}; | 
					
						
							| 
									
										
										
										
											2023-11-01 22:21:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-14 13:53:51 +01:00
										 |  |  | tfrpc.register(async function getActiveIdentity() { | 
					
						
							|  |  |  | 	return ssb.getActiveIdentity(); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2023-11-01 23:39:34 +00:00
										 |  |  | tfrpc.register(async function getOwnerIdentities() { | 
					
						
							|  |  |  | 	return ssb.getOwnerIdentities(); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-30 00:22:30 +00:00
										 |  |  | 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) { | 
					
						
							| 
									
										
										
										
											2023-11-11 13:44:20 +00:00
										 |  |  | 	print('APPENDING', message); | 
					
						
							| 
									
										
										
										
											2023-10-30 00:22:30 +00:00
										 |  |  | 	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)); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-01 22:21:42 +00:00
										 |  |  | core.register('message', async function message_handler(message) { | 
					
						
							|  |  |  | 	if (message.event == 'hashChange') { | 
					
						
							|  |  |  | 		g_hash = message.hash; | 
					
						
							|  |  |  | 		await tfrpc.rpc.hash_changed(message.hash); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2024-04-14 13:53:51 +01:00
										 |  |  | core.register('setActiveIdentity', async function setActiveIdentityHandler(id) { | 
					
						
							|  |  |  | 	await tfrpc.rpc.setActiveIdentity(id); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2023-11-01 22:21:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | tfrpc.register(function set_hash(hash) { | 
					
						
							|  |  |  | 	if (g_hash != hash) { | 
					
						
							|  |  |  | 		return app.setHash(hash); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | tfrpc.register(function get_hash(id, message) { | 
					
						
							|  |  |  | 	return g_hash; | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-02 00:45:20 +00:00
										 |  |  | 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); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-16 01:33:00 +00:00
										 |  |  | tfrpc.register(utils.collection); | 
					
						
							| 
									
										
										
										
											2023-11-04 02:00:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-30 00:22:30 +00:00
										 |  |  | async function main() { | 
					
						
							|  |  |  | 	await app.setDocument(utf8Decode(await getFile('index.html'))); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-24 11:09:34 -05:00
										 |  |  | main(); |