bug fix for conversation/direct

This commit is contained in:
Rasmus Lindroth 2022-12-30 10:45:58 +01:00
parent 9faaa4f0dc
commit aa9c1859b5
4 changed files with 45 additions and 4 deletions

View file

@ -56,6 +56,11 @@ func (c *WSClient) StreamingWSList(ctx context.Context, id ID) (chan Event, erro
return c.streamingWS(ctx, "list", string(id))
}
// StreamingWSDirect return channel to read events on a direct messages using WebSocket.
func (c *WSClient) StreamingWSDirect(ctx context.Context) (chan Event, error) {
return c.streamingWS(ctx, "direct", "")
}
func (c *WSClient) streamingWS(ctx context.Context, stream, tag string) (chan Event, error) {
params := url.Values{}
params.Set("access_token", c.client.Config.AccessToken)
@ -139,6 +144,12 @@ func (c *WSClient) handleWS(ctx context.Context, rawurl string, q chan Event) er
if err == nil {
q <- &NotificationEvent{Notification: &notification}
}
case "conversation":
var conversation Conversation
err = json.Unmarshal([]byte(s.Payload.(string)), &conversation)
if err == nil {
q <- &ConversationEvent{Conversation: &conversation}
}
case "delete":
if f, ok := s.Payload.(float64); ok {
q <- &DeleteEvent{ID: ID(fmt.Sprint(int64(f)))}