From d7600f28fcbe1e5d86e33c95195d75513e6e868d Mon Sep 17 00:00:00 2001 From: Iris Lightshard Date: Sun, 28 Apr 2024 12:16:23 -0600 Subject: [PATCH] start building some DTOs --- ts/adapter.ts | 14 +++--------- ts/index.ts | 63 +++++++++++++++++++++++++++------------------------ ts/message.ts | 47 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 40 deletions(-) create mode 100644 ts/message.ts diff --git a/ts/adapter.ts b/ts/adapter.ts index 15c59fd..25f6f2b 100644 --- a/ts/adapter.ts +++ b/ts/adapter.ts @@ -20,20 +20,12 @@ export class Adapter { 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 { diff --git a/ts/index.ts b/ts/index.ts index c06c909..6f2a5b8 100644 --- a/ts/index.ts +++ b/ts/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 = window; @@ -26,10 +27,15 @@ function main():void { 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 @@ function showSettings():void { const adapters = _("adapters") as Adapter[]; if (tabcontent) { - let html = "

this is our settings dialogue

"; - html += ""; - html += adapters.reduce((self: string, a: Adapter) => { - self += `
  • ${a.nickname}
  • ` - return self; - }, ""; - html += ""; - tabcontent.innerHTML = html; + let html = "

    this is our settings dialogue

    "; + html += ""; + html += adapters.reduce((self: string, a: Adapter) => { + self += `
  • ${a.nickname}
  • ` + return self; + }, ""; + html += ""; + tabcontent.innerHTML = html; } } function addAdapter(): void { const tabcontent = $("tabcontent"); if (tabcontent) { - // dropdown for protocol - let html = ""; - // depending on protocol, different fields - // nostr: privkey, initial relays - html += "
    "; - html += " "; - html += " "; - html += " "; - html += "
    "; - // masto/AP: server, username, pw/apikey - // save button, back button - html += ""; - html += ""; + // dropdown for protocol + let html = ""; + + // nostr is the first protocol, so show its options by default + html += "
    "; + html += " "; + html += " "; + html += " "; + html += "
    "; + + html += ""; + html += ""; - tabcontent.innerHTML = html; + tabcontent.innerHTML = html; } } diff --git a/ts/message.ts b/ts/message.ts new file mode 100644 index 0000000..c9d1b02 --- /dev/null +++ b/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 } \ No newline at end of file