Merge pull request #24 from Dhole/master

Add /messages API
This commit is contained in:
Kegsay 2017-05-08 13:18:39 +01:00 committed by GitHub
commit 80113e0369
2 changed files with 27 additions and 0 deletions

View File

@ -603,6 +603,26 @@ func (cli *Client) JoinedRooms() (resp *RespJoinedRooms, err error) {
return return
} }
// Messages returns a list of message and state events for a room. It uses
// pagination query parameters to paginate history in the room.
// See https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-messages
func (cli *Client) Messages(roomID, from, to string, dir rune, limit int) (resp *RespMessages, err error) {
query := map[string]string{
"from": from,
"dir": string(dir),
}
if to != "" {
query["to"] = to
}
if limit != 0 {
query["limit"] = string(limit)
}
urlPath := cli.BuildURLWithQuery([]string{"rooms", roomID, "messages"}, query)
_, err = cli.MakeRequest("GET", urlPath, nil, &resp)
return
}
func txnID() string { func txnID() string {
return "go" + strconv.FormatInt(time.Now().UnixNano(), 10) return "go" + strconv.FormatInt(time.Now().UnixNano(), 10)
} }

View File

@ -61,6 +61,13 @@ type RespJoinedMembers struct {
} `json:"joined"` } `json:"joined"`
} }
// RespMessages is the JSON response for https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-messages
type RespMessages struct {
Start string `json:"start"`
Chunk []Event `json:"chunk"`
End string `json:"end"`
}
// RespSendEvent is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-send-eventtype-txnid // RespSendEvent is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-send-eventtype-txnid
type RespSendEvent struct { type RespSendEvent struct {
EventID string `json:"event_id"` EventID string `json:"event_id"`