From 15dc39dedcf403b8ae026b868b409ec6df983f3e Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Wed, 24 Aug 2016 14:23:45 +0100 Subject: [PATCH] Add an inviter key when joining rooms --- src/github.com/matrix-org/go-neb/clients/clients.go | 2 +- src/github.com/matrix-org/go-neb/matrix/matrix.go | 13 ++++++++++--- .../matrix-org/go-neb/services/github/github.go | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/github.com/matrix-org/go-neb/clients/clients.go b/src/github.com/matrix-org/go-neb/clients/clients.go index be64037..aca2fa3 100644 --- a/src/github.com/matrix-org/go-neb/clients/clients.go +++ b/src/github.com/matrix-org/go-neb/clients/clients.go @@ -173,7 +173,7 @@ func (c *Clients) newClient(config types.ClientConfig) (*matrix.Client, error) { }) logger.Print("Accepting invite from user") - if _, err := client.JoinRoom(event.RoomID, ""); err != nil { + if _, err := client.JoinRoom(event.RoomID, "", event.Sender); err != nil { logger.WithError(err).Print("Failed to join room") } else { logger.Print("Joined room") diff --git a/src/github.com/matrix-org/go-neb/matrix/matrix.go b/src/github.com/matrix-org/go-neb/matrix/matrix.go index 16c0499..ccf8544 100644 --- a/src/github.com/matrix-org/go-neb/matrix/matrix.go +++ b/src/github.com/matrix-org/go-neb/matrix/matrix.go @@ -65,8 +65,10 @@ func (cli *Client) buildURLWithQuery(urlPath []string, urlQuery map[string]strin return u.String() } -// JoinRoom joins the client to a room ID or alias. Returns a room ID. -func (cli *Client) JoinRoom(roomIDorAlias, serverName string) (string, error) { +// JoinRoom joins the client to a room ID or alias. If serverName is specified, this will be added as a query param +// to instruct the homeserver to join via that server. If invitingUserID is specified, the inviting user ID will be +// inserted into the content of the join request. Returns a room ID. +func (cli *Client) JoinRoom(roomIDorAlias, serverName, invitingUserID string) (string, error) { var urlPath string if serverName != "" { urlPath = cli.buildURLWithQuery([]string{"join", roomIDorAlias}, map[string]string{ @@ -76,7 +78,12 @@ func (cli *Client) JoinRoom(roomIDorAlias, serverName string) (string, error) { urlPath = cli.buildURL("join", roomIDorAlias) } - resBytes, err := cli.sendJSON("POST", urlPath, `{}`) + content := struct { + Inviter string `json:"inviter,omitempty"` + }{} + content.Inviter = invitingUserID + + resBytes, err := cli.sendJSON("POST", urlPath, content) if err != nil { return "", err } diff --git a/src/github.com/matrix-org/go-neb/services/github/github.go b/src/github.com/matrix-org/go-neb/services/github/github.go index 4973859..6bbac29 100644 --- a/src/github.com/matrix-org/go-neb/services/github/github.go +++ b/src/github.com/matrix-org/go-neb/services/github/github.go @@ -287,7 +287,7 @@ func (s *githubService) Register(oldService types.Service, client *matrix.Client func (s *githubService) joinWebhookRooms(client *matrix.Client) error { for roomID := range s.Rooms { - if _, err := client.JoinRoom(roomID, ""); err != nil { + if _, err := client.JoinRoom(roomID, "", ""); err != nil { // TODO: Leave the rooms we successfully joined? return err }