got mentions from misskey adapter to the client
This commit is contained in:
parent
678e5e6258
commit
c00eb7d9b3
3 changed files with 87 additions and 33 deletions
|
@ -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,37 +81,49 @@ 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
|
||||||
|
tlnotes, tlerr := timelineService.Get(tl.GetRequest{
|
||||||
|
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 {
|
||||||
|
fmt.Println(tlerr.Error())
|
||||||
|
}
|
||||||
|
if merr != nil {
|
||||||
|
fmt.Println(merr.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
// check the cache for everything we just collected
|
||||||
|
// 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
|
||||||
|
for _, n := range tlnotes {
|
||||||
|
msg := self.cacheAndConvert(n)
|
||||||
|
if msg != nil {
|
||||||
|
self.data <- msg
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, n := range mentions {
|
||||||
|
msg := self.cacheAndConvert(n)
|
||||||
|
if msg != nil {
|
||||||
|
self.data <- msg
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: we have to actually decode and pass our filter criteria
|
|
||||||
tlnotes, tlerr := timelineService.Get(tl.GetRequest{})
|
|
||||||
mentions, merr := notesService.Mentions(notes.MentionsRequest{})
|
|
||||||
|
|
||||||
if tlerr != nil {
|
|
||||||
fmt.Println(tlerr.Error())
|
|
||||||
}
|
|
||||||
if merr != nil {
|
|
||||||
fmt.Println(merr.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
// check the cache for everything we just collected
|
|
||||||
// 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
|
|
||||||
for _, n := range tlnotes {
|
|
||||||
fmt.Println(n.ID)
|
|
||||||
// check existence and cache
|
|
||||||
// convert
|
|
||||||
// send
|
|
||||||
}
|
|
||||||
for _, n := range mentions {
|
|
||||||
fmt.Println(n.ID)
|
|
||||||
// check existence and cache
|
|
||||||
// convert
|
|
||||||
// send
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}()
|
}()
|
||||||
|
@ -110,6 +131,28 @@ func (self *MisskeyAdapter) Subscribe(filter string) []error {
|
||||||
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 ""
|
||||||
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
13
ts/index.ts
13
ts/index.ts
|
@ -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":
|
||||||
|
|
Loading…
Reference in a new issue