Browse Source

Add an inviter key when joining rooms

pull/47/head
Kegan Dougal 8 years ago
parent
commit
15dc39dedc
  1. 2
      src/github.com/matrix-org/go-neb/clients/clients.go
  2. 13
      src/github.com/matrix-org/go-neb/matrix/matrix.go
  3. 2
      src/github.com/matrix-org/go-neb/services/github/github.go

2
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") 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") logger.WithError(err).Print("Failed to join room")
} else { } else {
logger.Print("Joined room") logger.Print("Joined room")

13
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() 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 var urlPath string
if serverName != "" { if serverName != "" {
urlPath = cli.buildURLWithQuery([]string{"join", roomIDorAlias}, map[string]string{ 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) 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 { if err != nil {
return "", err return "", err
} }

2
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 { func (s *githubService) joinWebhookRooms(client *matrix.Client) error {
for roomID := range s.Rooms { 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? // TODO: Leave the rooms we successfully joined?
return err return err
} }

Loading…
Cancel
Save