added update, delete server events.
This commit is contained in:
parent
8e9cf13cc3
commit
dc094ceb03
14
client.go
14
client.go
@ -32,6 +32,8 @@ type Client struct {
|
|||||||
OnUnknownEventFunctions []func(message string)
|
OnUnknownEventFunctions []func(message string)
|
||||||
OnChannelStartTypingFunctions []func(channel_id, user_id string)
|
OnChannelStartTypingFunctions []func(channel_id, user_id string)
|
||||||
OnChannelStopTypingFunctions []func(channel_id, user_id string)
|
OnChannelStopTypingFunctions []func(channel_id, user_id string)
|
||||||
|
OnServerUpdateFunctions []func(server_id, clear string, payload map[string]interface{})
|
||||||
|
OnServerDeleteFunctions []func(server_id string)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Client cache struct.
|
// Client cache struct.
|
||||||
@ -96,11 +98,21 @@ func (c *Client) OnChannelStartTyping(fn func(channel_id, user_id string)) {
|
|||||||
c.OnChannelStartTypingFunctions = append(c.OnChannelStartTypingFunctions, fn)
|
c.OnChannelStartTypingFunctions = append(c.OnChannelStartTypingFunctions, fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
// On channel stıp typing will run when someone stops the typing status.
|
// On channel stop typing will run when someone stops the typing status.
|
||||||
func (c *Client) OnChannelStopTyping(fn func(channel_id, user_id string)) {
|
func (c *Client) OnChannelStopTyping(fn func(channel_id, user_id string)) {
|
||||||
c.OnChannelStopTypingFunctions = append(c.OnChannelStopTypingFunctions, fn)
|
c.OnChannelStopTypingFunctions = append(c.OnChannelStopTypingFunctions, fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// On server update will run when someone updates a server.
|
||||||
|
func (c *Client) OnServerUpdate(fn func(server_id, clear string, payload map[string]interface{})) {
|
||||||
|
c.OnServerUpdateFunctions = append(c.OnServerUpdateFunctions, fn)
|
||||||
|
}
|
||||||
|
|
||||||
|
// On server delete will run when someone deletes a server.
|
||||||
|
func (c *Client) OnServerDelete(fn func(server_id string)) {
|
||||||
|
c.OnServerDeleteFunctions = append(c.OnServerDeleteFunctions, fn)
|
||||||
|
}
|
||||||
|
|
||||||
// Fetch a channel by Id.
|
// Fetch a channel by Id.
|
||||||
func (c *Client) FetchChannel(id string) (*Channel, error) {
|
func (c *Client) FetchChannel(id string) (*Channel, error) {
|
||||||
channel := &Channel{}
|
channel := &Channel{}
|
||||||
|
32
websocket.go
32
websocket.go
@ -211,6 +211,38 @@ func (c *Client) handleEvents(rawData *struct {
|
|||||||
for _, i := range c.OnChannelStopTypingFunctions {
|
for _, i := range c.OnChannelStopTypingFunctions {
|
||||||
i(data.ChannelId, data.UserId)
|
i(data.ChannelId, data.UserId)
|
||||||
}
|
}
|
||||||
|
} else if rawData.Type == "ServerUpdate" && c.OnServerUpdateFunctions != nil {
|
||||||
|
// Server update event.
|
||||||
|
data := &struct {
|
||||||
|
ServerId string `json:"id"`
|
||||||
|
Clear string `json:"clear"`
|
||||||
|
Payload map[string]interface{} `json:"data"`
|
||||||
|
}{}
|
||||||
|
|
||||||
|
err := json.Unmarshal([]byte(message), data)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Unexcepted Error: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, i := range c.OnServerUpdateFunctions {
|
||||||
|
i(data.ServerId, data.Clear, data.Payload)
|
||||||
|
}
|
||||||
|
} else if rawData.Type == "ServerDelete" && c.OnServerDeleteFunctions != nil {
|
||||||
|
// Server delete event.
|
||||||
|
data := &struct {
|
||||||
|
ServerId string `json:"id"`
|
||||||
|
}{}
|
||||||
|
|
||||||
|
err := json.Unmarshal([]byte(message), data)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Unexcepted Error: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, i := range c.OnServerDeleteFunctions {
|
||||||
|
i(data.ServerId)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Unknown event.
|
// Unknown event.
|
||||||
if c.OnUnknownEventFunctions != nil {
|
if c.OnUnknownEventFunctions != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user