-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtyping.go
43 lines (37 loc) · 1.14 KB
/
typing.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package api
import (
"fmt"
"time"
"github.com/chanbakjsd/gotrix/api/httputil"
"github.com/chanbakjsd/gotrix/matrix"
)
// TypingStart notifies the server that the user is typing in a specific room.
// It should be repeated while the user is typing with preferably a few seconds of safety margin from timeout.
func (c *Client) TypingStart(roomID matrix.RoomID, timeout time.Duration) error {
req := map[string]interface{}{
"typing": true,
"timeout": timeout / time.Millisecond,
}
err := c.Request(
"PUT", c.Endpoints.RoomTyping(roomID, c.UserID), nil,
httputil.WithToken(), httputil.WithJSONBody(req),
)
if err != nil {
return fmt.Errorf("error sending typing start notification: %w", err)
}
return nil
}
// TypingStop notifies the server that the user has stopped typing in a specific room.
func (c *Client) TypingStop(roomID matrix.RoomID) error {
req := map[string]interface{}{
"typing": false,
}
err := c.Request(
"PUT", c.Endpoints.RoomTyping(roomID, c.UserID), nil,
httputil.WithToken(), httputil.WithJSONBody(req),
)
if err != nil {
return fmt.Errorf("error sending typing stop notification: %w", err)
}
return nil
}