From 3abb49331771b96d245a3d2e5c36b365bc3740a8 Mon Sep 17 00:00:00 2001 From: Snowflake Date: Mon, 30 Apr 2018 20:38:55 +0000 Subject: [PATCH 1/2] Fix InviteUser --- client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client.go b/client.go index 90a07c6..7725ac3 100644 --- a/client.go +++ b/client.go @@ -529,7 +529,7 @@ func (cli *Client) ForgetRoom(roomID string) (resp *RespForgetRoom, err error) { // InviteUser invites a user to a room. See http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-invite func (cli *Client) InviteUser(roomID string, req *ReqInviteUser) (resp *RespInviteUser, err error) { u := cli.BuildURL("rooms", roomID, "invite") - _, err = cli.MakeRequest("POST", u, struct{}{}, &resp) + _, err = cli.MakeRequest("POST", u, req, &resp) return } From 2bddc063150f95ccaf6abf0f1f59d8ae5ef7db7c Mon Sep 17 00:00:00 2001 From: Snowflake Date: Tue, 1 May 2018 18:24:47 +0000 Subject: [PATCH 2/2] Function to create a client with a custom HTTP client --- client.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/client.go b/client.go index 7725ac3..b6725c5 100644 --- a/client.go +++ b/client.go @@ -701,3 +701,28 @@ func NewClient(homeserverURL, userID, accessToken string) (*Client, error) { return &cli, nil } + +// NewClientWithHTTPClient creates a new Matrix Client ready for syncing, using +// the supplied HTTP client. +func NewClientWithHTTPClient(homeserverURL, userID, accessToken string, client *http.Client) (*Client, error) { + hsURL, err := url.Parse(homeserverURL) + if err != nil { + return nil, err + } + // By default, use an in-memory store which will never save filter ids / next batch tokens to disk. + // The client will work with this storer: it just won't remember across restarts. + // In practice, a database backend should be used. + store := NewInMemoryStore() + cli := Client{ + AccessToken: accessToken, + HomeserverURL: hsURL, + UserID: userID, + Prefix: "/_matrix/client/r0", + Syncer: NewDefaultSyncer(userID, store), + Store: store, + } + // By default, use the default HTTP client. + cli.Client = client + + return &cli, nil +}