start building some DTOs
This commit is contained in:
parent
a768261688
commit
d7600f28fc
3 changed files with 84 additions and 40 deletions
|
@ -20,20 +20,12 @@ export class Adapter {
|
||||||
public updateMetadata(): void {};
|
public updateMetadata(): void {};
|
||||||
public getMetadata(): any { return {} };
|
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;
|
private static ndk: NDK | null = null;
|
||||||
|
|
||||||
public static create(): Adapter {
|
public static create(): Adapter {
|
||||||
let adapter = new Adapter();
|
return new Adapter();
|
||||||
|
|
||||||
adapter.init = ()=>{};
|
|
||||||
adapter.getInbox = async ()=>{};
|
|
||||||
adapter.getFollowers = ()=>[];
|
|
||||||
adapter.getFollowing = ()=>[];
|
|
||||||
adapter.publish = ()=>{};
|
|
||||||
adapter.updateMetadata = ()=>{};
|
|
||||||
adapter.getMetadata = ()=>{return {}};
|
|
||||||
|
|
||||||
return adapter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static toNostr(adapter: Adapter, settings: any): Adapter {
|
public static toNostr(adapter: Adapter, settings: any): Adapter {
|
||||||
|
|
63
ts/index.ts
63
ts/index.ts
|
@ -1,4 +1,5 @@
|
||||||
import {Adapter} from "./adapter";
|
import {Adapter} from "./adapter";
|
||||||
|
import {Message, Attachment} from "./message"
|
||||||
|
|
||||||
function _(key: string, value: any | null | undefined = undefined): any | null {
|
function _(key: string, value: any | null | undefined = undefined): any | null {
|
||||||
const x = <any>window;
|
const x = <any>window;
|
||||||
|
@ -26,10 +27,15 @@ function main():void {
|
||||||
case "mastodon":
|
case "mastodon":
|
||||||
adapters.push(Adapter.toMasto(a, s));
|
adapters.push(Adapter.toMasto(a, s));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (adapters.length > 0) {
|
||||||
|
_("currentAdapter", 0);
|
||||||
|
// update tabbar and tabcontent with first adapter
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log("no settings exist for this client");
|
console.log("no settings exist for this client");
|
||||||
_("settings", { adapters: [] });
|
_("settings", { adapters: [] });
|
||||||
|
showSettings();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -45,41 +51,40 @@ function showSettings():void {
|
||||||
const adapters = _("adapters") as Adapter[];
|
const adapters = _("adapters") as Adapter[];
|
||||||
|
|
||||||
if (tabcontent) {
|
if (tabcontent) {
|
||||||
let html = "<p>this is our settings dialogue</p>";
|
let html = "<p>this is our settings dialogue</p>";
|
||||||
html += "<button onclick='addAdapter()'>New</button>";
|
html += "<button onclick='addAdapter()'>New</button>";
|
||||||
html += adapters.reduce((self: string, a: Adapter) => {
|
html += adapters.reduce((self: string, a: Adapter) => {
|
||||||
self += `<li><a href='#' onclick='editAdapter(${a.nickname})'>${a.nickname}</a></li>`
|
self += `<li><a href='#' onclick='editAdapter(${a.nickname})'>${a.nickname}</a></li>`
|
||||||
return self;
|
return self;
|
||||||
}, "<ul id='settings_adapterlist'>");
|
}, "<ul id='settings_adapterlist'>");
|
||||||
html += "</ul>";
|
html += "</ul>";
|
||||||
html += "<button onclick='saveSettings()'>save</button>";
|
html += "<button onclick='saveSettings()'>save</button>";
|
||||||
tabcontent.innerHTML = html;
|
tabcontent.innerHTML = html;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function addAdapter(): void {
|
function addAdapter(): void {
|
||||||
const tabcontent = $("tabcontent");
|
const tabcontent = $("tabcontent");
|
||||||
if (tabcontent) {
|
if (tabcontent) {
|
||||||
// dropdown for protocol
|
// dropdown for protocol
|
||||||
let html = "<select id='settings_newadapter_protocolselect' onchange='fillAdapterProtocolOptions()'>";
|
let html = "<select id='settings_newadapter_protocolselect' onchange='fillAdapterProtocolOptions()'>";
|
||||||
html += [ "nostr", "mastodon" ].reduce((self, p)=>{
|
html += [ "nostr", "mastodon" ].reduce((self, p)=>{
|
||||||
self += `<option value='${p}'>${p}</option>`;
|
self += `<option value='${p}'>${p}</option>`;
|
||||||
return self;
|
return self;
|
||||||
}, "");
|
}, "");
|
||||||
html += "</select>";
|
html += "</select>";
|
||||||
// depending on protocol, different fields
|
|
||||||
// nostr: privkey, initial relays
|
// nostr is the first protocol, so show its options by default
|
||||||
html += "<div id='settings_newadapter_protocoloptions'>";
|
html += "<div id='settings_newadapter_protocoloptions'>";
|
||||||
html += " <label>nickname<input id='settings_newadapter_nickname'/></label>";
|
html += " <label>nickname<input id='settings_newadapter_nickname'/></label>";
|
||||||
html += " <label>privkey<input id='settings_newadapter_nostr_privkey'/></label>";
|
html += " <label>privkey<input id='settings_newadapter_nostr_privkey'/></label>";
|
||||||
html += " <label>default relays<input id='settings_newadapter_nostr_default_relays'/></label>";
|
html += " <label>default relays<input id='settings_newadapter_nostr_default_relays'/></label>";
|
||||||
html += "</div>";
|
html += "</div>";
|
||||||
// masto/AP: server, username, pw/apikey
|
|
||||||
// save button, back button
|
html += "<button onclick='saveAdapter()'>Add</button>";
|
||||||
html += "<button onclick='saveAdapter()'>Add</button>";
|
html += "<button onclick='showSettings()'>Back</button>";
|
||||||
html += "<button onclick='showSettings()'>Back</button>";
|
|
||||||
|
|
||||||
tabcontent.innerHTML = html;
|
tabcontent.innerHTML = html;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
47
ts/message.ts
Normal file
47
ts/message.ts
Normal 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 }
|
Loading…
Reference in a new issue