Extended version of 1lann/messenger
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
772 B

package messenger
import (
"net/http"
"net/url"
"strings"
)
// SetTypingIndicator sets the typing indicator seen by members of the
// thread.
func (s *Session) SetTypingIndicator(thread Thread, typing bool) error {
form := make(url.Values)
form.Set("source", "mercury-chat")
form.Set("thread", thread.ThreadID)
if typing {
form.Set("typ", "1")
} else {
form.Set("typ", "0")
}
form.Set("to", "")
if !thread.IsGroup {
form.Set("to", thread.ThreadID)
}
form = s.addFormMeta(form)
req, _ := http.NewRequest(http.MethodPost, typingURL,
strings.NewReader(form.Encode()))
req.Header = defaultHeader()
req.Header.Set("Content-Type", formURLEncoded)
resp, err := s.doRequest(req)
if err != nil {
return err
}
resp.Body.Close()
return nil
}