mattn/go-mastodon

I got an error when I use websocket.

toyo opened this issue · 2 comments

toyo commented

I got an error below when I use StreamingWSUser().


panic: interface conversion: interface {} is string, not float64

goroutine 18 [running]:
github.com/mattn/go-mastodon.(*WSClient).handleWS(0xc4204261c0, 0x7d4cc0, 0xc420016058, 0xc42008a780, 0x7d, 0xc42001a7e0, 0x0, 0xc420280240)
/go/src/github.com/mattn/go-mastodon/streaming_ws.go:131 +0x93d
github.com/mattn/go-mastodon.(*WSClient).streamingWS.func1(0xc42001a7e0, 0xc4204261c0, 0x7d4cc0, 0xc420016058, 0xc4200dc280)
/go/src/github.com/mattn/go-mastodon/streaming_ws.go:72 +0x95
created by github.com/mattn/go-mastodon.(*WSClient).streamingWS
/go/src/github.com/mattn/go-mastodon/streaming_ws.go:69 +0x339

mattn commented

Could you please try this?

diff --git a/streaming.go b/streaming.go
index 4689ece..b3242a4 100644
--- a/streaming.go
+++ b/streaming.go
@@ -69,7 +69,7 @@ func handleReader(q chan Event, r io.Reader) error {
 					q <- &NotificationEvent{&notification}
 				}
 			case "delete":
-				q <- &DeleteEvent{ID(strings.TrimSpace(token[1]))}
+				q <- &DeleteEvent{ID: ID(strings.TrimSpace(token[1]))}
 			}
 			if err != nil {
 				q <- &ErrorEvent{err}
diff --git a/streaming_ws.go b/streaming_ws.go
index 80e357b..d027f89 100644
--- a/streaming_ws.go
+++ b/streaming_ws.go
@@ -3,9 +3,9 @@ package mastodon
 import (
 	"context"
 	"encoding/json"
-	"fmt"
 	"net/url"
 	"path"
+	"strings"
 
 	"github.com/gorilla/websocket"
 )
@@ -128,7 +128,7 @@ func (c *WSClient) handleWS(ctx context.Context, rawurl string, q chan Event) er
 				q <- &NotificationEvent{Notification: &notification}
 			}
 		case "delete":
-			q <- &DeleteEvent{ID: ID(fmt.Sprint(int64(s.Payload.(float64))))}
+			q <- &DeleteEvent{ID: ID(strings.TrimSpace(s.Payload.(string)))}
 		}
 		if err != nil {
 			q <- &ErrorEvent{err}
toyo commented

I try this.
I got no errors with delete notification.
Thanks.