diff --git a/adapter/adapter.go b/adapter/adapter.go
index 3140a66..e77caf1 100644
--- a/adapter/adapter.go
+++ b/adapter/adapter.go
@@ -2,10 +2,13 @@ package adapter
import (
. "forge.lightcrystal.systems/lightcrystal/underbbs/models"
+ nostr "github.com/nbd-wtf/go-nostr"
+ "strings"
+ "context"
)
type Adapter interface {
- Init(map[string]string, chan Message) error
+ Init(Settings, chan Message) error
Subscribe(string) error
SendMessage(Message) error
Follow(Author) error
@@ -13,3 +16,48 @@ type Adapter interface {
GetFollowers() error
UpdateMetadata(interface{}) error
}
+
+type NostrAdapter struct {
+ msgChan chan Message
+ nickname string
+ privkey string
+ relays []*nostr.Relay
+}
+
+func (self *NostrAdapter) Init(settings Settings, msgChan chan Message) error {
+ self.nickname = settings.Nickname
+ self.privkey = *settings.PrivKey
+ self.msgChan = msgChan
+
+ ctx := context.Background()
+
+ relays := strings.Split(*settings.Relays, ",")
+
+ for _, r := range relays {
+ pr := nostr.RelayConnect(ctx, strings.Trim(r)
+ if pr == nil {
+ return errors.New("Relay connection could not be completed")
+ }
+ self.relays = append(self.relays, pr)
+ }
+ return nil
+}
+
+func (self *NostrAdapter) Subscribe(filter string) error {
+ return nil
+}
+func (self *NostrAdapter) SendMessage(msg Message) error {
+ return nil
+}
+func (self *NostrAdapter) Follow(author Author) error {
+ return nil
+}
+func (self *NostrAdapter) Unfollow(author Author) error {
+ return nil
+}
+func (self *NostrAdapter) GetFollowers() error {
+ return nil
+}
+func (self *NostrAdapter) UpdateMetadata(data interface{}) error {
+ return nil
+}
\ No newline at end of file
diff --git a/dist/index.html b/dist/index.html
index 74331a4..60057ab 100644
--- a/dist/index.html
+++ b/dist/index.html
@@ -22,6 +22,7 @@
this is our settings dialogue
"; @@ -156,6 +179,9 @@ function saveAdapter(): void { const settings = _("settings"); const adapters = _("adapters"); if (settings && adapters) { + if (!settings.adapters) { + settings.adapters = []; + } settings.adapters.push(self); let a: Adapter = Adapter.create(); switch (self.protocol) { @@ -171,10 +197,32 @@ function saveAdapter(): void { } } + +let _conn: WebSocket | null = null; + +function connect() { + // import the data from the settings + const settings = _("settings"); + if (settings) { + + // base64 encode the settings data + let subprotocol: string = "["; + for (let a of settings.adapters) { + subprotocol += JSON.stringify(a) + ","; + } + subprotocol += "]"; + subprotocol = btoa(subprotocol); + // open the websocket connection with settings as subprotocol + + _conn = new WebSocket("/subscribe", subprotocol); + _("websocket", _conn); + } +} + _("addAdapter", addAdapter); _("saveAdapter", saveAdapter); _("fillAdapterProtocolOptions", fillAdapterProtocolOptions); _("showSettings", showSettings); _("saveSettings", saveSettings); - +_("connect", connect); main(); diff --git a/underbbs.go b/underbbs.go index f9233bf..713b7e6 100644 --- a/underbbs.go +++ b/underbbs.go @@ -2,12 +2,6 @@ package main import ( "context" - "hacklab.nilfm.cc/felt/cmd" - "hacklab.nilfm.cc/felt/config" - "hacklab.nilfm.cc/felt/gametable" - "hacklab.nilfm.cc/felt/mongodb" - "hacklab.nilfm.cc/felt/register" - "hacklab.nilfm.cc/quartzgun/indentalUserDB" "log" "net" "net/http"