added channel typing events.
This commit is contained in:
parent
02e22d0196
commit
8e9cf13cc3
28
client.go
28
client.go
@ -22,14 +22,16 @@ type Client struct {
|
||||
Cache *Cache
|
||||
|
||||
// Event Functions
|
||||
OnReadyFunctions []func()
|
||||
OnMessageFunctions []func(message *Message)
|
||||
OnMessageUpdateFunctions []func(channel_id, message_id string, payload map[string]interface{})
|
||||
OnMessageDeleteFunctions []func(channel_id, message_id string)
|
||||
OnChannelCreateFunctions []func(channel *Channel)
|
||||
OnChannelUpdateFunctions []func(channel_id, clear string, payload map[string]interface{})
|
||||
OnChannelDeleteFunctions []func(channel_id string)
|
||||
OnUnknownEventFunctions []func(message string)
|
||||
OnReadyFunctions []func()
|
||||
OnMessageFunctions []func(message *Message)
|
||||
OnMessageUpdateFunctions []func(channel_id, message_id string, payload map[string]interface{})
|
||||
OnMessageDeleteFunctions []func(channel_id, message_id string)
|
||||
OnChannelCreateFunctions []func(channel *Channel)
|
||||
OnChannelUpdateFunctions []func(channel_id, clear string, payload map[string]interface{})
|
||||
OnChannelDeleteFunctions []func(channel_id string)
|
||||
OnUnknownEventFunctions []func(message string)
|
||||
OnChannelStartTypingFunctions []func(channel_id, user_id string)
|
||||
OnChannelStopTypingFunctions []func(channel_id, user_id string)
|
||||
}
|
||||
|
||||
// Client cache struct.
|
||||
@ -89,6 +91,16 @@ func (c *Client) OnUnknownEvent(fn func(message string)) {
|
||||
c.OnUnknownEventFunctions = append(c.OnUnknownEventFunctions, fn)
|
||||
}
|
||||
|
||||
// On channel start typing will run when someone starts to type a message.
|
||||
func (c *Client) OnChannelStartTyping(fn func(channel_id, user_id string)) {
|
||||
c.OnChannelStartTypingFunctions = append(c.OnChannelStartTypingFunctions, fn)
|
||||
}
|
||||
|
||||
// On channel stıp typing will run when someone stops the typing status.
|
||||
func (c *Client) OnChannelStopTyping(fn func(channel_id, user_id string)) {
|
||||
c.OnChannelStopTypingFunctions = append(c.OnChannelStopTypingFunctions, fn)
|
||||
}
|
||||
|
||||
// Fetch a channel by Id.
|
||||
func (c *Client) FetchChannel(id string) (*Channel, error) {
|
||||
channel := &Channel{}
|
||||
|
34
websocket.go
34
websocket.go
@ -179,8 +179,40 @@ func (c *Client) handleEvents(rawData *struct {
|
||||
for _, i := range c.OnChannelDeleteFunctions {
|
||||
i(data.ChannelId)
|
||||
}
|
||||
} else if rawData.Type == "ChannelStartTyping" && c.OnChannelStartTypingFunctions != nil {
|
||||
// Channel start typing event.
|
||||
data := &struct {
|
||||
ChannelId string `json:"id"`
|
||||
UserId string `json:"user"`
|
||||
}{}
|
||||
|
||||
err := json.Unmarshal([]byte(message), data)
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("Unexcepted Error: %s", err)
|
||||
}
|
||||
|
||||
for _, i := range c.OnChannelStartTypingFunctions {
|
||||
i(data.ChannelId, data.UserId)
|
||||
}
|
||||
} else if rawData.Type == "ChannelStopTyping" && c.OnChannelStopTypingFunctions != nil {
|
||||
// Channel stop typing event.
|
||||
data := &struct {
|
||||
ChannelId string `json:"id"`
|
||||
UserId string `json:"user"`
|
||||
}{}
|
||||
|
||||
err := json.Unmarshal([]byte(message), data)
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("Unexcepted Error: %s", err)
|
||||
}
|
||||
|
||||
for _, i := range c.OnChannelStopTypingFunctions {
|
||||
i(data.ChannelId, data.UserId)
|
||||
}
|
||||
} else {
|
||||
// Unknown Event
|
||||
// Unknown event.
|
||||
if c.OnUnknownEventFunctions != nil {
|
||||
for _, i := range c.OnUnknownEventFunctions {
|
||||
i(message)
|
||||
|
Loading…
x
Reference in New Issue
Block a user