Changed struct name to be clearer

This commit is contained in:
tyler 2024-01-19 14:19:22 -05:00
parent 3cb463e99a
commit 9e821689cf

20
chat.go
View file

@ -232,16 +232,16 @@ type ChatEvent struct {
Type string `json:"type"` Type string `json:"type"`
} }
type ChatEventDataFix struct { type ChatEventDataNoChannels struct {
Channels [][]string `json:"channels"` Channels [][]string `json:"channels"`
Messages []ChatEventMessage `json:"messages"` Messages []ChatEventMessage `json:"messages"`
Users []ChatEventUser `json:"users"` Users []ChatEventUser `json:"users"`
} }
type ChatEventFix struct { type ChatEventNoChannels struct {
Data ChatEventDataFix `json:"data"` Data ChatEventDataNoChannels `json:"data"`
RequestID string `json:"request_id"` RequestID string `json:"request_id"`
Type string `json:"type"` Type string `json:"type"`
} }
func (c *Client) StartChatStream(handle func(cv ChatView), handleError func(err error)) error { func (c *Client) StartChatStream(handle func(cv ChatView), handleError func(err error)) error {
@ -317,14 +317,14 @@ func parseEvent(event []byte) ([]ChatView, error) {
var ce ChatEvent var ce ChatEvent
err := json.Unmarshal(event, &ce) err := json.Unmarshal(event, &ce)
if err != nil { if err != nil {
var cef ChatEventFix var cenc ChatEventNoChannels
errFix := json.Unmarshal(event, &cef) errNC := json.Unmarshal(event, &cenc)
if errFix != nil { if errNC != nil {
return nil, fmt.Errorf("error un-marshaling event: %v", err) return nil, fmt.Errorf("error un-marshaling event: %v", err)
} }
ce.Data.Messages = cef.Data.Messages ce.Data.Messages = cenc.Data.Messages
ce.Data.Users = cef.Data.Users ce.Data.Users = cenc.Data.Users
} }
users := chatUsers(ce.Data.Users) users := chatUsers(ce.Data.Users)