From 7c39729ada794aa2bfe91028ae3f3cfd3020de6f Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Fri, 14 Jun 2019 20:56:41 +0300 Subject: [PATCH] Remove room alias argument and switch to room after creating --- interface/matrix.go | 1 + ui/commands.go | 32 +++++++++----------------------- 2 files changed, 10 insertions(+), 23 deletions(-) diff --git a/interface/matrix.go b/interface/matrix.go index 8c80c6d..f312df1 100644 --- a/interface/matrix.go +++ b/interface/matrix.go @@ -40,6 +40,7 @@ type MatrixContainer interface { MarkRead(roomID, eventID string) JoinRoom(roomID, server string) (*rooms.Room, error) LeaveRoom(roomID string) error + CreateRoom(req *mautrix.ReqCreateRoom) (*rooms.Room, error) GetHistory(room *rooms.Room, limit int) ([]*mautrix.Event, error) GetEvent(room *rooms.Room, eventID string) (*mautrix.Event, error) diff --git a/ui/commands.go b/ui/commands.go index c2102fd..b418e84 100644 --- a/ui/commands.go +++ b/ui/commands.go @@ -121,7 +121,7 @@ func cmdHelp(cmd *Command) { /me - Send an emote message. /rainbow - Send a rainbow message (markdown not supported). -/create - Create a room with associated alias. (Alias must not contain spaces.) +/create [room name] - Create a room. /join - Join a room. /leave - Leave the current room. @@ -205,30 +205,16 @@ func cmdKick(cmd *Command) { } func cmdCreateRoom(cmd *Command) { - if len(cmd.Args) < 2 { - cmd.Reply("Usage: /create (Alias must not contain spaces.)") + req := &mautrix.ReqCreateRoom{} + if len(cmd.Args) > 0 { + req.Name = strings.Join(cmd.Args, " ") + } + room, err := cmd.Matrix.CreateRoom(req) + if err != nil { + cmd.Reply("Failed to create room:", err) return } - // Get room name as one string from cmd.Args - roomName := "" - for i, v := range cmd.Args { - if i == len(cmd.Args)-1 { - break - } - roomName += fmt.Sprintf("%s ", v) - } - last := len(cmd.Args) - 1 // last arg for room alias - // Build the ReqCreateRoom Struct - // https://godoc.org/maunium.net/go/mautrix#ReqCreateRoom - req := &mautrix.ReqCreateRoom{ - Name: strings.TrimSpace(roomName), - RoomAliasName: cmd.Args[last], - } - _, err := cmd.Matrix.Client().CreateRoom(req) - debug.Print("Create room error:", err) - if err == nil { - cmd.Reply("The room has been created.") - } + cmd.MainView.SwitchRoom("", room) } func cmdJoin(cmd *Command) {