Handled issue when chat message is sent by user not channel

This commit is contained in:
tyler 2024-01-19 14:04:00 -05:00
parent 67e67e59be
commit 3cb463e99a

19
chat.go
View file

@ -232,6 +232,18 @@ type ChatEvent struct {
Type string `json:"type"` Type string `json:"type"`
} }
type ChatEventDataFix struct {
Channels [][]string `json:"channels"`
Messages []ChatEventMessage `json:"messages"`
Users []ChatEventUser `json:"users"`
}
type ChatEventFix struct {
Data ChatEventDataFix `json:"data"`
RequestID string `json:"request_id"`
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 {
c.chatStreamMu.Lock() c.chatStreamMu.Lock()
defer c.chatStreamMu.Unlock() defer c.chatStreamMu.Unlock()
@ -305,9 +317,16 @@ 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
errFix := json.Unmarshal(event, &cef)
if errFix != 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.Users = cef.Data.Users
}
users := chatUsers(ce.Data.Users) users := chatUsers(ce.Data.Users)
channels := chatChannels(ce.Data.Channels) channels := chatChannels(ce.Data.Channels)