63 lines
No EOL
1.4 KiB
Go
63 lines
No EOL
1.4 KiB
Go
package adapter
|
|
|
|
import (
|
|
. "forge.lightcrystal.systems/lightcrystal/underbbs/models"
|
|
nostr "github.com/nbd-wtf/go-nostr"
|
|
"strings"
|
|
"context"
|
|
)
|
|
|
|
type Adapter interface {
|
|
Init(Settings, chan Message) error
|
|
Subscribe(string) error
|
|
SendMessage(Message) error
|
|
Follow(Author) error
|
|
Unfollow(Author) error
|
|
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
|
|
} |