aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaron Swab <jrswab@gmail.com>2019-06-13 21:14:32 -0400
committerJaron Swab <jrswab@gmail.com>2019-06-13 21:14:32 -0400
commitfcd44fe63fe0cedc038db92ae39507237cc5589a (patch)
treeee3b13cbf99dc8ccdadbd20c22c62e8f7fcdcfb0
parent4bcdcd1ccd1d616d29614e5eaf8bfb1df679aa6d (diff)
Users can now create a new room directly in Gomuks
Added the ability to create a room from within gomuks using the now `/create` command. This comman takes the room name followed by the alias. Room name may contain spaces but the alias may not as per the Matrix alias conventions. Also update `/help` to include the new command.
-rw-r--r--matrix/matrix.go10
-rw-r--r--ui/command-processor.go1
-rw-r--r--ui/commands.go28
3 files changed, 39 insertions, 0 deletions
diff --git a/matrix/matrix.go b/matrix/matrix.go
index b87042e..ef272b0 100644
--- a/matrix/matrix.go
+++ b/matrix/matrix.go
@@ -538,6 +538,16 @@ func (c *Container) SendTyping(roomID string, typing bool) {
}
}
+// CreateRoom attempts to create a new room and join the user.
+func (c *Container) CreateRoom(req *mautrix.ReqCreateRoom) (*rooms.Room, error) {
+ resp, err := c.client.CreateRoom(req)
+ if err != nil {
+ return nil, err
+ }
+ room := c.GetRoom(resp.RoomID)
+ return room, nil
+}
+
// JoinRoom makes the current user try to join the given room.
func (c *Container) JoinRoom(roomID, server string) (*rooms.Room, error) {
resp, err := c.client.JoinRoom(roomID, server, nil)
diff --git a/ui/command-processor.go b/ui/command-processor.go
index 7a4c2c1..0692ae3 100644
--- a/ui/command-processor.go
+++ b/ui/command-processor.go
@@ -90,6 +90,7 @@ func NewCommandProcessor(parent *MainView) *CommandProcessor {
"quit": cmdQuit,
"clearcache": cmdClearCache,
"leave": cmdLeave,
+ "create": cmdCreateRoom,
"join": cmdJoin,
"kick": cmdKick,
"ban": cmdBan,
diff --git a/ui/commands.go b/ui/commands.go
index 3847c10..c2102fd 100644
--- a/ui/commands.go
+++ b/ui/commands.go
@@ -121,6 +121,7 @@ func cmdHelp(cmd *Command) {
/me <message> - Send an emote message.
/rainbow <message> - Send a rainbow message (markdown not supported).
+/create <Room Name> <RoomAlias> - Create a room with associated alias. (Alias must not contain spaces.)
/join <room address> - Join a room.
/leave - Leave the current room.
@@ -203,6 +204,33 @@ func cmdKick(cmd *Command) {
}
+func cmdCreateRoom(cmd *Command) {
+ if len(cmd.Args) < 2 {
+ cmd.Reply("Usage: /create <Room Name> <RoomAlias> (Alias must not contain spaces.)")
+ 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.")
+ }
+}
+
func cmdJoin(cmd *Command) {
if len(cmd.Args) == 0 {
cmd.Reply("Usage: /join <room>")