fix misskey author fetch, fmt
This commit is contained in:
parent
44bdad2e50
commit
fead16168a
6 changed files with 162 additions and 151 deletions
|
@ -25,7 +25,6 @@ func (self *MastoAdapter) Name() string {
|
|||
return self.nickname
|
||||
}
|
||||
|
||||
|
||||
func (self *MastoAdapter) Init(settings Settings, data chan SocketData) error {
|
||||
self.nickname = settings.Nickname
|
||||
self.server = *settings.Server
|
||||
|
|
|
@ -7,9 +7,10 @@ import (
|
|||
mkcore "github.com/yitsushi/go-misskey/core"
|
||||
mkm "github.com/yitsushi/go-misskey/models"
|
||||
n "github.com/yitsushi/go-misskey/services/notes"
|
||||
users "github.com/yitsushi/go-misskey/services/users"
|
||||
tl "github.com/yitsushi/go-misskey/services/notes/timeline"
|
||||
users "github.com/yitsushi/go-misskey/services/users"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -25,6 +26,7 @@ type MisskeyAdapter struct {
|
|||
// from different API calls instead of streaming them in a single channel
|
||||
|
||||
cache map[string]time.Time
|
||||
mtx sync.RWMutex
|
||||
|
||||
stop chan bool
|
||||
}
|
||||
|
@ -99,8 +101,8 @@ func (self *MisskeyAdapter) poll() {
|
|||
default:
|
||||
|
||||
// TODO: we have to actually decode and pass our filter criteria
|
||||
// probe for new notes
|
||||
|
||||
// probe for new notes
|
||||
probenote, err := timelineService.Get(tl.GetRequest{
|
||||
Limit: 1,
|
||||
})
|
||||
|
@ -166,22 +168,24 @@ func (self *MisskeyAdapter) poll() {
|
|||
|
||||
time.Sleep(5 * time.Second)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (self *MisskeyAdapter) isNew(n mkm.Note) bool {
|
||||
self.mtx.RLock()
|
||||
timestamp, exists := self.cache[n.ID]
|
||||
self.mtx.RUnlock()
|
||||
return !exists || timestamp.Before(n.CreatedAt)
|
||||
}
|
||||
|
||||
func (self *MisskeyAdapter) toMessageIfNew(n mkm.Note) *Message {
|
||||
return self.toMessage(n, false);
|
||||
return self.toMessage(n, false)
|
||||
}
|
||||
|
||||
func (self *MisskeyAdapter) toMessage(n mkm.Note, bustCache bool) *Message {
|
||||
self.mtx.RLock()
|
||||
timestamp, exists := self.cache[n.ID]
|
||||
self.mtx.RUnlock()
|
||||
if bustCache || !exists || timestamp.Before(n.CreatedAt) {
|
||||
host := mkcore.StringValue(n.User.Host)
|
||||
authorId := ""
|
||||
|
@ -191,7 +195,9 @@ func (self *MisskeyAdapter) toMessage(n mkm.Note, bustCache bool) *Message {
|
|||
authorId = fmt.Sprintf("@%s", n.User.Username)
|
||||
}
|
||||
|
||||
self.mtx.Lock()
|
||||
self.cache[n.ID] = n.CreatedAt
|
||||
self.mtx.Unlock()
|
||||
msg := Message{
|
||||
Datagram: Datagram{
|
||||
Id: n.ID,
|
||||
|
@ -237,7 +243,7 @@ func (self *MisskeyAdapter) toAuthor(usr mkm.User) *Author {
|
|||
}
|
||||
|
||||
author := Author{
|
||||
Datagram: Datagram {
|
||||
Datagram: Datagram{
|
||||
Id: authorId,
|
||||
Uri: mkcore.StringValue(usr.URL),
|
||||
Protocol: "misskey",
|
||||
|
@ -253,7 +259,7 @@ func (self *MisskeyAdapter) toAuthor(usr mkm.User) *Author {
|
|||
}
|
||||
|
||||
func (self *MisskeyAdapter) Fetch(etype, id string) error {
|
||||
switch (etype) {
|
||||
switch etype {
|
||||
case "message":
|
||||
data, err := self.mk.Notes().Show(id)
|
||||
if err != nil {
|
||||
|
@ -289,7 +295,7 @@ func (self *MisskeyAdapter) Fetch(etype, id string) error {
|
|||
} else {
|
||||
for _, n := range data {
|
||||
msg := self.toMessage(n, true)
|
||||
if msg != nil{
|
||||
if msg != nil {
|
||||
self.data <- msg
|
||||
}
|
||||
}
|
||||
|
@ -297,10 +303,11 @@ func (self *MisskeyAdapter) Fetch(etype, id string) error {
|
|||
case "author":
|
||||
user := ""
|
||||
host := ""
|
||||
fmt.Printf("fetch author: %s\n", id)
|
||||
idParts := strings.Split(id, "@")
|
||||
user = idParts[0]
|
||||
if len(idParts) == 2 {
|
||||
host = idParts[1]
|
||||
user = idParts[1]
|
||||
if len(idParts) == 3 {
|
||||
host = idParts[2]
|
||||
}
|
||||
|
||||
var hostPtr *string = nil
|
||||
|
@ -308,6 +315,12 @@ func (self *MisskeyAdapter) Fetch(etype, id string) error {
|
|||
hostPtr = &host
|
||||
}
|
||||
|
||||
if hostPtr == nil {
|
||||
fmt.Printf("looking up user: @%s\n", user)
|
||||
} else {
|
||||
fmt.Printf("looking up remote user: @%s@%s\n", user, host)
|
||||
}
|
||||
|
||||
// fmt.Printf("attempting user resolution: @%s@%s\n", user, host)
|
||||
data, err := self.mk.Users().Show(users.ShowRequest{
|
||||
Username: &user,
|
||||
|
|
4
build.sh
4
build.sh
|
@ -1,7 +1,7 @@
|
|||
#!/bin/sh
|
||||
|
||||
case "$1" in
|
||||
client)
|
||||
front)
|
||||
if [ ! -e ./frontend/.js ]; then
|
||||
mkdir ./frontend/.js
|
||||
fi
|
||||
|
@ -13,10 +13,10 @@ case "$1" in
|
|||
fi
|
||||
if [ -s ${buildlog} ]; then
|
||||
cat ${buildlog} | head
|
||||
rm ${buildlog}
|
||||
else
|
||||
npx webpack --config webpack.config.js
|
||||
fi
|
||||
rm ${buildlog}
|
||||
;;
|
||||
server)
|
||||
go mod tidy
|
||||
|
|
|
@ -148,7 +148,7 @@ func ProtectWithSubscriberKey(next http.Handler, subscribers map[*Subscriber][]a
|
|||
if strings.HasPrefix(authHeader, "Bearer ") {
|
||||
subscriberKey := strings.Split(authHeader, "Bearer ")[1]
|
||||
if getSubscriberByKey(subscriberKey, subscribers) != nil {
|
||||
next.ServeHTTP(w, req);
|
||||
next.ServeHTTP(w, req)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -184,7 +184,6 @@ func apiAdapterFetch(next http.Handler, subscribers map[*Subscriber][]adapter.Ad
|
|||
})
|
||||
}
|
||||
|
||||
|
||||
func (self *BBSServer) apiMux() http.Handler {
|
||||
errTemplate, err := template.New("err").Parse("{{ $params := (.Context).Value \"params\" }}<html><body><h1>ERROR {{ $params.ErrorCode }}</h1><p class='error'>{{ $params.ErrorMessage }}</p></body></html>")
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue