all repos — underbbs @ d7600f28fcbe1e5d86e33c95195d75513e6e868d

decentralized social media client

start building some DTOs
Iris Lightshard nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE-----

iHUEABYKAB0WIQT/foVVmI9pK13hPWFohAcXSWbK8wUCZi6SdwAKCRBohAcXSWbK
87KgAP9zTiAFtWzuE6E2lSfIYdsuVH7NMg7atyHmrvKOLbdUtAD/YXnQSo+xtg97
A3FanV4OohIUDrXXvHbNwXcISDRF1QA=
=SVwV
-----END PGP SIGNATURE-----
commit

d7600f28fcbe1e5d86e33c95195d75513e6e868d

parent

a7682616885d9a1f64b6aee846a80d92e50319e0

3 files changed, 84 insertions(+), 40 deletions(-)

jump to
M ts/adapter.tsts/adapter.ts

@@ -20,20 +20,12 @@ public getFollowing(): any[] { return [] };

public updateMetadata(): void {}; public getMetadata(): any { return {} }; + // according to the docs NDK must be a singleton... + // this probalby will make having more than one nostr adapter at once problematic private static ndk: NDK | null = null; public static create(): Adapter { - let adapter = new Adapter(); - - adapter.init = ()=>{}; - adapter.getInbox = async ()=>{}; - adapter.getFollowers = ()=>[]; - adapter.getFollowing = ()=>[]; - adapter.publish = ()=>{}; - adapter.updateMetadata = ()=>{}; - adapter.getMetadata = ()=>{return {}}; - - return adapter; + return new Adapter(); } public static toNostr(adapter: Adapter, settings: any): Adapter {
M ts/index.tsts/index.ts

@@ -1,4 +1,5 @@

import {Adapter} from "./adapter"; +import {Message, Attachment} from "./message" function _(key: string, value: any | null | undefined = undefined): any | null { const x = <any>window;

@@ -26,10 +27,15 @@ break;

case "mastodon": adapters.push(Adapter.toMasto(a, s)); } - } + } + if (adapters.length > 0) { + _("currentAdapter", 0); + // update tabbar and tabcontent with first adapter + } } else { console.log("no settings exist for this client"); _("settings", { adapters: [] }); + showSettings(); } };

@@ -45,41 +51,40 @@ const tabcontent = $("tabcontent");

const adapters = _("adapters") as Adapter[]; if (tabcontent) { - let html = "<p>this is our settings dialogue</p>"; - html += "<button onclick='addAdapter()'>New</button>"; - html += adapters.reduce((self: string, a: Adapter) => { - self += `<li><a href='#' onclick='editAdapter(${a.nickname})'>${a.nickname}</a></li>` - return self; - }, "<ul id='settings_adapterlist'>"); - html += "</ul>"; - html += "<button onclick='saveSettings()'>save</button>"; - tabcontent.innerHTML = html; + let html = "<p>this is our settings dialogue</p>"; + html += "<button onclick='addAdapter()'>New</button>"; + html += adapters.reduce((self: string, a: Adapter) => { + self += `<li><a href='#' onclick='editAdapter(${a.nickname})'>${a.nickname}</a></li>` + return self; + }, "<ul id='settings_adapterlist'>"); + html += "</ul>"; + html += "<button onclick='saveSettings()'>save</button>"; + tabcontent.innerHTML = html; } } function addAdapter(): void { const tabcontent = $("tabcontent"); if (tabcontent) { - // dropdown for protocol - let html = "<select id='settings_newadapter_protocolselect' onchange='fillAdapterProtocolOptions()'>"; - html += [ "nostr", "mastodon" ].reduce((self, p)=>{ - self += `<option value='${p}'>${p}</option>`; - return self; - }, ""); - html += "</select>"; - // depending on protocol, different fields - // nostr: privkey, initial relays - html += "<div id='settings_newadapter_protocoloptions'>"; - html += " <label>nickname<input id='settings_newadapter_nickname'/></label>"; - html += " <label>privkey<input id='settings_newadapter_nostr_privkey'/></label>"; - html += " <label>default relays<input id='settings_newadapter_nostr_default_relays'/></label>"; - html += "</div>"; - // masto/AP: server, username, pw/apikey - // save button, back button - html += "<button onclick='saveAdapter()'>Add</button>"; - html += "<button onclick='showSettings()'>Back</button>"; + // dropdown for protocol + let html = "<select id='settings_newadapter_protocolselect' onchange='fillAdapterProtocolOptions()'>"; + html += [ "nostr", "mastodon" ].reduce((self, p)=>{ + self += `<option value='${p}'>${p}</option>`; + return self; + }, ""); + html += "</select>"; + + // nostr is the first protocol, so show its options by default + html += "<div id='settings_newadapter_protocoloptions'>"; + html += " <label>nickname<input id='settings_newadapter_nickname'/></label>"; + html += " <label>privkey<input id='settings_newadapter_nostr_privkey'/></label>"; + html += " <label>default relays<input id='settings_newadapter_nostr_default_relays'/></label>"; + html += "</div>"; + + html += "<button onclick='saveAdapter()'>Add</button>"; + html += "<button onclick='showSettings()'>Back</button>"; - tabcontent.innerHTML = html; + tabcontent.innerHTML = html; } }
A ts/message.ts

@@ -0,0 +1,47 @@

+import {NDKEvent} from "@nostr-dev-kit/ndk" +import * as masto from "masto"; + +type APStatus = masto.mastodon.v1.Status; + +export class Message { + public author: Author = new Author(); + public protocol: string = ""; + public content: string = ""; + public attachments: Attachment[] = []; + public replyTo: Message | null = null; + public replies: Message[] = []; + public mentions: Author[] = []; + public created: Date = new Date(); + public edited: Date = new Date(); + public visibility: string = "public"; + + // this will contain additional data about what kind of message it is + public aux: any | null = null; + + public static fromNostr(event: NDKEvent): Message { + let self = new Message(); + // build out the message based on the contents of event + return self; + } + + public static fromMasto(status: APStatus): Message { + let self = new Message(); + // build out the message based on the contents of status + return self; + } +} + +export class Author { + public id: string = ""; + public name: string = ""; + public profileData: string = ""; + public messages: Message[] = []; +} + +export class Attachment { + public file: Uint8Array = new Uint8Array(); + public altText: string = ""; + public filename: string = ""; +} + +export default { Message, Attachment, Author }