about summary refs log tree commit diff stats
path: root/src/command
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2013-05-30 22:48:56 +0100
committerJames Booth <boothj5@gmail.com>2013-05-30 22:48:56 +0100
commit1eba4f5ab1e4148efdbcef22fb16d7c1bf0ed9d5 (patch)
treeae04ef6d7c10708b0428d9b61043255fc711568e /src/command
parentf164c12368594316bfce07c5c1876fa57ea3bcde (diff)
downloadprofani-tty-1eba4f5ab1e4148efdbcef22fb16d7c1bf0ed9d5.tar.gz
Added /leave command
Diffstat (limited to 'src/command')
-rw-r--r--src/command/command.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/command/command.c b/src/command/command.c
index d181f48a..d5919496 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -102,6 +102,7 @@ static gboolean _cmd_tiny(gchar **args, struct cmd_help_t help);
 static gboolean _cmd_close(gchar **args, struct cmd_help_t help);
 static gboolean _cmd_clear(gchar **args, struct cmd_help_t help);
 static gboolean _cmd_join(gchar **args, struct cmd_help_t help);
+static gboolean _cmd_leave(gchar **args, struct cmd_help_t help);
 static gboolean _cmd_invite(gchar **args, struct cmd_help_t help);
 static gboolean _cmd_invites(gchar **args, struct cmd_help_t help);
 static gboolean _cmd_decline(gchar **args, struct cmd_help_t help);
@@ -358,6 +359,14 @@ static struct cmd_t main_commands[] =
           "Example : /join jdev (as user@jabber.org will join jdev@conference.jabber.org)",
           NULL } } },
 
+    { "/leave",
+        _cmd_leave, parse_args, 0, 0,
+        { "/leave", "Leave a chat room.",
+        { "/leave",
+          "------",
+          "Leave the current chat room.",
+          NULL } } },
+
     { "/invite",
         _cmd_invite, parse_args_with_freetext, 1, 2,
         { "/invite jid [message]", "Invite contact to chat room.",
@@ -2664,6 +2673,30 @@ _cmd_close(gchar **args, struct cmd_help_t help)
 }
 
 static gboolean
+_cmd_leave(gchar **args, struct cmd_help_t help)
+{
+    jabber_conn_status_t conn_status = jabber_get_connection_status();
+    win_type_t win_type = ui_current_win_type();
+    int index = ui_current_win_index();
+
+    if (win_type != WIN_MUC) {
+        cons_show("You can only use the /leave command in a chat room.");
+        cons_alert();
+        return TRUE;
+    }
+
+    // handle leaving rooms, or chat
+    if (conn_status == JABBER_CONNECTED) {
+        ui_close_connected_win(index);
+    }
+
+    // close the window
+    ui_close_win(index);
+
+    return TRUE;
+}
+
+static gboolean
 _cmd_set_beep(gchar **args, struct cmd_help_t help)
 {
     return _cmd_set_boolean_preference(args[0], help, "Sound", PREF_BEEP);