2 Commits

Author SHA1 Message Date
738bf5caf5 added begin, end typing functions. 2022-01-28 22:06:20 +03:00
3b6caba1dd fixes #7? 2022-01-28 21:56:10 +03:00
2 changed files with 13 additions and 1 deletions

View File

@ -220,3 +220,13 @@ func (c Channel) DeleteGroupRecipient(user_id string) error {
_, err := c.Client.Request("DELETE", "/channels/"+c.Id+"/recipients/"+user_id, []byte{})
return err
}
// Send a typing start event to the channel.
func (c *Channel) BeginTyping() {
c.Client.Socket.SendText(fmt.Sprintf("{\"type\":\"BeginTyping\",\"channel\":\"%s\"}", c.Id))
}
// End the typing event in the channel.
func (c *Channel) EndTyping() {
c.Client.Socket.SendText(fmt.Sprintf("{\"type\":\"EndTyping\",\"channel\":\"%s\"}", c.Id))
}

View File

@ -25,6 +25,8 @@ func (c *Client) Start() {
}
c.Socket.OnTextMessage = func(message string, _ gowebsocket.Socket) {
fmt.Println(message)
// Parse data
rawData := &struct {
Type string `json:"type"`
@ -67,7 +69,7 @@ func (c *Client) Destroy() {
func (c *Client) ping() {
for {
time.Sleep(30 * time.Second)
c.Socket.SendText(fmt.Sprintf("{\"type\":\"Ping\",\"time\":%d}", time.Now().Unix()))
c.Socket.SendText("{\"type\":\"Ping\",\"data\":0}")
}
}