start building some DTOs

This commit is contained in:
Iris Lightshard 2024-04-28 12:16:23 -06:00
parent a768261688
commit d7600f28fc
Signed by: nilix
GPG Key ID: 688407174966CAF3
3 changed files with 84 additions and 40 deletions

View File

@ -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 {

View File

@ -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 @@ 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 = "<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;
}
}

47
ts/message.ts Normal file
View File

@ -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 }