diff --git a/adapter/adapter.go b/adapter/adapter.go index bd661be..6e0346b 100644 --- a/adapter/adapter.go +++ b/adapter/adapter.go @@ -7,7 +7,7 @@ import ( type Adapter interface { Init(Settings, *chan SocketData) error Name() string - Subscribe(string) []error + Subscribe(string, *string) []error Fetch(string, []string) error Do(string, map[string]string) error DefaultSubscriptionFilter() string diff --git a/adapter/anonAp.go b/adapter/anonAp.go index 08dd5b8..eea2e23 100644 --- a/adapter/anonAp.go +++ b/adapter/anonAp.go @@ -137,10 +137,11 @@ func getBodyJson(res *http.Response) []byte { l := res.ContentLength // 4k is a reasonable max size if we get unknown length right? if l < 0 { - l = 4096 + l = 9999999 } jsonData := make([]byte, l) res.Body.Read(jsonData) + return jsonData } diff --git a/adapter/honk.go b/adapter/honk.go index ff4ee74..d2d731a 100644 --- a/adapter/honk.go +++ b/adapter/honk.go @@ -22,8 +22,8 @@ type donk struct { type honk struct { ID int Honker string - Handles []string - Oonker *string + Handles string + Oonker string XID string RID *string Noise string @@ -33,6 +33,12 @@ type honk struct { Date string } +type honkResponse struct { + Honks []honk `json:"honks"` + ChatCount int `json:"chatcount"` + MeCount int `json:"mecount"` +} + type HonkAdapter struct { data *chan SocketData nickname string @@ -98,19 +104,19 @@ func (self *HonkAdapter) Init(settings Settings, data *chan SocketData) error { return nil } -func (self *HonkAdapter) Subscribe(filter string) []error { +func (self *HonkAdapter) Subscribe(filter string, target *string) []error { if self.stop != nil { close(self.stop) self.maxId = 0 } self.stop = make(chan bool) - go self.gethonks(filter) + go self.gethonks(filter, target) return nil } -func (self *HonkAdapter) gethonks(filter string) { +func (self *HonkAdapter) gethonks(filter string, target *string) { for { select { @@ -119,6 +125,7 @@ func (self *HonkAdapter) gethonks(filter string) { return } default: + fmt.Println("bout to get honks") honkForm := url.Values{ "action": []string{"gethonks"}, "token": []string{self.token}, @@ -129,24 +136,32 @@ func (self *HonkAdapter) gethonks(filter string) { } res, err := http.PostForm(self.server+"/api", honkForm) if err != nil { - // return? + fmt.Println("fucked up: " + err.Error()) + self.stop <- true + return } - honksData := getBodyJson(res) - honks := []honk{} - json.Unmarshal(honksData, &honks) - for _, h := range honks { + fmt.Println("we got some honks") + hr := honkResponse{} + err = json.NewDecoder(res.Body).Decode(&hr) + if err != nil { + fmt.Println("malformed honks: " + err.Error()) + self.stop <- true + return + } + for _, h := range hr.Honks { if h.ID > self.maxId { self.maxId = h.ID - msg := self.toMsg(h) - self.send(msg) } + msg := self.toMsg(h, target) + fmt.Println("gonna send a honk on the channel dawg") + self.send(msg) } time.Sleep(5 * time.Second) } } } -func (self *HonkAdapter) toMsg(h honk) Message { +func (self *HonkAdapter) toMsg(h honk, target *string) Message { t, err := time.Parse(time.RFC3339, h.Date) if err != nil { t = time.Now() @@ -154,8 +169,8 @@ func (self *HonkAdapter) toMsg(h honk) Message { tt := t.UnixMilli() a := h.Honker - if h.Oonker != nil { - a = *h.Oonker + if h.Oonker != "" { + a = h.Oonker } msg := Message{ @@ -175,9 +190,9 @@ func (self *HonkAdapter) toMsg(h honk) Message { if h.Public { msg.Visibility = "Public" } - if h.Oonker != nil { + if h.Oonker != "" { r := fmt.Sprintf("%s/bonk/%d", h.Honker, h.ID) - msg.Renoter = h.Oonker + msg.Renoter = &h.Oonker msg.RenoteId = &r msg.RenoteTime = &tt } @@ -188,6 +203,9 @@ func (self *HonkAdapter) toMsg(h honk) Message { } msg.Attachments = append(msg.Attachments, a) } + if target != nil { + msg.Target = target + } return msg } diff --git a/adapter/mastodon.go b/adapter/mastodon.go index a7efd1d..4aacd9f 100644 --- a/adapter/mastodon.go +++ b/adapter/mastodon.go @@ -50,7 +50,7 @@ func (self *MastoAdapter) Init(settings Settings, data *chan SocketData) error { return err } -func (self *MastoAdapter) Subscribe(filter string) []error { +func (self *MastoAdapter) Subscribe(filter string, target *string) []error { // TODO: decode separate timelines and hashtags // for now, the filter is just the timeline diff --git a/adapter/misskey.go b/adapter/misskey.go index eba427c..fa14206 100644 --- a/adapter/misskey.go +++ b/adapter/misskey.go @@ -72,7 +72,7 @@ func (self *MisskeyAdapter) Init(settings Settings, data *chan SocketData) error return nil } -func (self *MisskeyAdapter) Subscribe(filter string) []error { +func (self *MisskeyAdapter) Subscribe(filter string, target *string) []error { // misskey streaming API is undocumented.... // we could try to reverse engineer it by directly connecting to the websocket??? // alternatively, we can poll timelines, mentions, etc with a cancellation channel, diff --git a/adapter/nostr.go b/adapter/nostr.go index 04e805e..7d4abad 100644 --- a/adapter/nostr.go +++ b/adapter/nostr.go @@ -48,7 +48,7 @@ func (self *NostrAdapter) Init(settings Settings, data *chan SocketData) error { return nil } -func (self *NostrAdapter) Subscribe(filter string) []error { +func (self *NostrAdapter) Subscribe(filter string, target *string) []error { var filters nostr.Filters err := json.Unmarshal([]byte(filter), &filters) if err != nil { diff --git a/frontend/dist/index.html b/frontend/dist/index.html index c5e39f8..bbe4d0a 100644 --- a/frontend/dist/index.html +++ b/frontend/dist/index.html @@ -14,9 +14,14 @@