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 {
|
||||
fmt.Println("initializing misskey adapter")
|
||||
|
||||
self.nickname = settings.Nickname
|
||||
self.server = *settings.Server
|
||||
self.apiKey = *settings.ApiKey
|
||||
self.data = data
|
||||
|
||||
fmt.Println("getting ready to initialize internal client")
|
||||
|
||||
client, err := misskey.NewClientWithOptions(
|
||||
misskey.WithAPIToken(self.apiKey),
|
||||
misskey.WithBaseURL("https", self.server, ""),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return err
|
||||
}
|
||||
fmt.Println("misskey client initialized")
|
||||
self.mk = client
|
||||
|
||||
self.cache = make(map[string]time.Time)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -72,37 +81,49 @@ func (self *MisskeyAdapter) Subscribe(filter string) []error {
|
|||
timelineService := notesService.Timeline()
|
||||
|
||||
for {
|
||||
_, moar := <-self.stop
|
||||
if !moar {
|
||||
break
|
||||
select {
|
||||
case _, ok := <-self.stop:
|
||||
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
|
||||
}
|
||||
|
||||
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 {
|
||||
return nil
|
||||
}
|
||||
|
@ -117,3 +160,7 @@ func (self *MisskeyAdapter) Fetch(query string) error {
|
|||
func (self *MisskeyAdapter) Do(action string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *MisskeyAdapter) DefaultSubscriptionFilter() string {
|
||||
return ""
|
||||
}
|
||||
|
|
|
@ -79,6 +79,8 @@ func apiConfigureAdapters(next http.Handler, subscribers map[*Subscriber][]adapt
|
|||
a = &adapter.NostrAdapter{}
|
||||
case "mastodon":
|
||||
a = &adapter.MastoAdapter{}
|
||||
case "misskey":
|
||||
a = &adapter.MisskeyAdapter{}
|
||||
default:
|
||||
break
|
||||
|
||||
|
|
13
ts/index.ts
13
ts/index.ts
|
@ -91,7 +91,7 @@ function addAdapter(): void {
|
|||
if (tabcontent) {
|
||||
// dropdown for protocol
|
||||
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>`;
|
||||
return self;
|
||||
}, "");
|
||||
|
@ -123,6 +123,7 @@ function fillAdapterProtocolOptions(): void {
|
|||
html += " <label>default relays<input id='settings_newadapter_nostr_default_relays'/></label>";
|
||||
break;
|
||||
case "mastodon":
|
||||
case "misskey":
|
||||
html += " <label>nickname<input id='settings_newadapter_nickname'/></label>";
|
||||
html += " <label>server<input id='settings_newadapter_masto_server'/></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()) };
|
||||
break;
|
||||
case "mastodon":
|
||||
case "misskey":
|
||||
const server = ($("settings_newadapter_masto_server") 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;
|
||||
}
|
||||
const settings = _("settings");
|
||||
const adapters = _("adapters");
|
||||
if (settings && adapters) {
|
||||
let adapters = _("adapters");
|
||||
if (settings) {
|
||||
if (!settings.adapters) {
|
||||
settings.adapters = [];
|
||||
}
|
||||
settings.adapters.push(self);
|
||||
if (!adapters) {
|
||||
adapters = []
|
||||
}
|
||||
let a: Adapter = Adapter.create();
|
||||
switch (self.protocol) {
|
||||
case "nostr":
|
||||
|
|
Loading…
Reference in a new issue