got mentions from misskey adapter to the client

This commit is contained in:
Iris Lightshard 2024-06-22 22:02:15 -06:00
parent 678e5e6258
commit c00eb7d9b3
Signed by: Iris Lightshard
GPG key ID: 688407174966CAF3
3 changed files with 87 additions and 33 deletions

View file

@ -32,20 +32,29 @@ type MisskeyAdapter struct {
} }
func (self *MisskeyAdapter) Init(settings Settings, data chan SocketData) error { func (self *MisskeyAdapter) Init(settings Settings, data chan SocketData) error {
fmt.Println("initializing misskey adapter")
self.nickname = settings.Nickname self.nickname = settings.Nickname
self.server = *settings.Server self.server = *settings.Server
self.apiKey = *settings.ApiKey self.apiKey = *settings.ApiKey
self.data = data self.data = data
fmt.Println("getting ready to initialize internal client")
client, err := misskey.NewClientWithOptions( client, err := misskey.NewClientWithOptions(
misskey.WithAPIToken(self.apiKey), misskey.WithAPIToken(self.apiKey),
misskey.WithBaseURL("https", self.server, ""), misskey.WithBaseURL("https", self.server, ""),
) )
if err != nil { if err != nil {
fmt.Println(err.Error())
return err return err
} }
fmt.Println("misskey client initialized")
self.mk = client self.mk = client
self.cache = make(map[string]time.Time)
return nil return nil
} }
@ -72,14 +81,24 @@ func (self *MisskeyAdapter) Subscribe(filter string) []error {
timelineService := notesService.Timeline() timelineService := notesService.Timeline()
for { for {
_, moar := <-self.stop select {
if !moar { case _, ok := <-self.stop:
break if !ok {
return
} }
default:
// TODO: we have to actually decode and pass our filter criteria // TODO: we have to actually decode and pass our filter criteria
tlnotes, tlerr := timelineService.Get(tl.GetRequest{}) tlnotes, tlerr := timelineService.Get(tl.GetRequest{
mentions, merr := notesService.Mentions(notes.MentionsRequest{}) Limit: 50,
// how are you supposed to bootstrap these??
SinceID: "xxxxxxxxxx",
UntilID: "xxxxxxxxxx",
SinceDate: 0,
})
mentions, merr := notesService.Mentions(notes.MentionsRequest{
Limit: 50,
})
if tlerr != nil { if tlerr != nil {
fmt.Println(tlerr.Error()) fmt.Println(tlerr.Error())
@ -92,24 +111,48 @@ func (self *MisskeyAdapter) Subscribe(filter string) []error {
// if anything is newer or as of yet not in the cache, add it // if anything is newer or as of yet not in the cache, add it
// and convert it to a SocketData implementation before sending on data channel // and convert it to a SocketData implementation before sending on data channel
for _, n := range tlnotes { for _, n := range tlnotes {
fmt.Println(n.ID) msg := self.cacheAndConvert(n)
// check existence and cache if msg != nil {
// convert self.data <- msg
// send }
} }
for _, n := range mentions { for _, n := range mentions {
fmt.Println(n.ID) msg := self.cacheAndConvert(n)
// check existence and cache if msg != nil {
// convert self.data <- msg
// send
} }
} }
}
}
}() }()
return nil return nil
} }
func (self *MisskeyAdapter) cacheAndConvert(n mkm.Note) *Message {
timestamp, exists := self.cache[n.ID]
if !exists || timestamp.Before(n.CreatedAt) {
self.cache[n.ID] = n.CreatedAt
msg := Message{
Uri: n.URI,
Author: Author{
Id: n.User.ID,
Name: n.User.Name,
// ProfileUri: *n.User.URL,
ProfilePic: n.User.AvatarURL,
},
Protocol: "misskey",
Adapter: self.nickname,
Created: n.CreatedAt,
Content: n.Text,
}
return &msg
}
return nil
}
func (self *MisskeyAdapter) Fetch(query string) error { func (self *MisskeyAdapter) Fetch(query string) error {
return nil return nil
} }
@ -117,3 +160,7 @@ func (self *MisskeyAdapter) Fetch(query string) error {
func (self *MisskeyAdapter) Do(action string) error { func (self *MisskeyAdapter) Do(action string) error {
return nil return nil
} }
func (self *MisskeyAdapter) DefaultSubscriptionFilter() string {
return ""
}

View file

@ -79,6 +79,8 @@ func apiConfigureAdapters(next http.Handler, subscribers map[*Subscriber][]adapt
a = &adapter.NostrAdapter{} a = &adapter.NostrAdapter{}
case "mastodon": case "mastodon":
a = &adapter.MastoAdapter{} a = &adapter.MastoAdapter{}
case "misskey":
a = &adapter.MisskeyAdapter{}
default: default:
break break

View file

@ -91,7 +91,7 @@ function addAdapter(): void {
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", "misskey" ].reduce((self, p)=>{
self += `<option value='${p}'>${p}</option>`; self += `<option value='${p}'>${p}</option>`;
return self; return self;
}, ""); }, "");
@ -123,6 +123,7 @@ function fillAdapterProtocolOptions(): void {
html += " <label>default relays<input id='settings_newadapter_nostr_default_relays'/></label>"; html += " <label>default relays<input id='settings_newadapter_nostr_default_relays'/></label>";
break; break;
case "mastodon": case "mastodon":
case "misskey":
html += " <label>nickname<input id='settings_newadapter_nickname'/></label>"; html += " <label>nickname<input id='settings_newadapter_nickname'/></label>";
html += " <label>server<input id='settings_newadapter_masto_server'/></label>"; html += " <label>server<input id='settings_newadapter_masto_server'/></label>";
html += " <label>API key<input id='settings_newadapter_masto_apikey'/></label>"; html += " <label>API key<input id='settings_newadapter_masto_apikey'/></label>";
@ -171,18 +172,22 @@ function saveAdapter(): void {
self = { nickname: nickname, protocol: "nostr", privkey: privkey, relays: relays.split(",").map(r=>r.trim()) }; self = { nickname: nickname, protocol: "nostr", privkey: privkey, relays: relays.split(",").map(r=>r.trim()) };
break; break;
case "mastodon": case "mastodon":
case "misskey":
const server = ($("settings_newadapter_masto_server") as HTMLInputElement)?.value ?? ""; const server = ($("settings_newadapter_masto_server") as HTMLInputElement)?.value ?? "";
const apiKey = ($("settings_newadapter_masto_apikey") as HTMLInputElement)?.value ?? ""; const apiKey = ($("settings_newadapter_masto_apikey") as HTMLInputElement)?.value ?? "";
self = { nickname: nickname, protocol: "mastodon", server: server, apiKey: apiKey }; self = { nickname: nickname, protocol: proto.options[proto.selectedIndex].value, server: server, apiKey: apiKey };
break; break;
} }
const settings = _("settings"); const settings = _("settings");
const adapters = _("adapters"); let adapters = _("adapters");
if (settings && adapters) { if (settings) {
if (!settings.adapters) { if (!settings.adapters) {
settings.adapters = []; settings.adapters = [];
} }
settings.adapters.push(self); settings.adapters.push(self);
if (!adapters) {
adapters = []
}
let a: Adapter = Adapter.create(); let a: Adapter = Adapter.create();
switch (self.protocol) { switch (self.protocol) {
case "nostr": case "nostr":