matrix-org / gomatrix

A Golang Matrix client
Apache License 2.0
284 stars 53 forks source link

Receipt client function #51

Open seanenck opened 6 years ago

seanenck commented 6 years ago

Any interest in adding a receipt client function to send receipts using the API endpoints

e.g.

diff --git a/client.go b/client.go
index 7725ac3..2819d8d 100644
--- a/client.go
+++ b/client.go
@@ -449,6 +449,13 @@ func (cli *Client) SendMessageEvent(roomID string, eventType string, contentJSON
        return
 }

+func (cli *Client) Receipt(roomID, receiptType, eventID string, req *ReqReceipt) (resp *RespReceipt, err error) {
+       urlPath := cli.BuildURL("rooms", roomID, "receipt", receiptType, eventID)
+       _, err = cli.MakeRequest("POST", urlPath, req, nil)
+       return
+}
+
+
 // SendStateEvent sends a state event into a room. See http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-state-eventtype-statekey
 // contentJSON should be a pointer to something that can be encoded as JSON using json.Marshal.
 func (cli *Client) SendStateEvent(roomID, eventType, stateKey string, contentJSON interface{}) (resp *RespSendEvent, err error) {
diff --git a/requests.go b/requests.go
index af99a22..f044fff 100644
--- a/requests.go
+++ b/requests.go
@@ -76,3 +76,6 @@ type ReqTyping struct {
        Typing  bool  `json:"typing"`
        Timeout int64 `json:"timeout"`
 }
+
+type ReqReceipt struct {
+}
diff --git a/responses.go b/responses.go
index fe0eeb3..8539969 100644
--- a/responses.go
+++ b/responses.go
@@ -174,3 +174,6 @@ type RespTurnServer struct {
        TTL      int      `json:"ttl"`
        URIs     []string `json:"uris"`
 }
+
+type RespReceipt struct {
+}

Happy to cleanup and submit this as a PR if it seems reasonable

kegsay commented 4 years ago

Very much so. However, longer term it's likely that I will end up doing what so many others do and autogen the structs using something like go-swagger. This means this client will be focussed on the core Matrix logic rather than tedious creation of req/res structs.