about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-09-03 22:56:33 +0100
committerJames Booth <boothj5@gmail.com>2014-09-03 22:56:33 +0100
commitb50b786dcc39cd0eabff6ea0880759291b9b9b0b (patch)
treebf0d60dbc28c08ddf5331dd6c124a6fc09ed9b10 /src
parent64521eb135229c8c6905b6c74668142eaf441a32 (diff)
downloadprofani-tty-b50b786dcc39cd0eabff6ea0880759291b9b9b0b.tar.gz
Validate usage of /room config command, added UI messages
Diffstat (limited to 'src')
-rw-r--r--src/command/command.c2
-rw-r--r--src/command/commands.c49
-rw-r--r--src/muc.c35
-rw-r--r--src/muc.h3
-rw-r--r--src/server_events.c2
-rw-r--r--src/xmpp/iq.c4
-rw-r--r--src/xmpp/xmpp.h2
7 files changed, 84 insertions, 13 deletions
diff --git a/src/command/command.c b/src/command/command.c
index fcb37078..49dc7396 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -309,7 +309,7 @@ static struct cmd_t command_defs[] =
         { "/room config accept|cancel", "Room configuration.",
         { "/room config accept|cncel",
           "-------------------------",
-          "Accept or cancel room creation.",
+          "Accept or cancel default room configuration.",
           NULL } } },
 
     { "/rooms",
diff --git a/src/command/commands.c b/src/command/commands.c
index d18f747c..5e33f823 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -65,6 +65,7 @@
 #include "xmpp/xmpp.h"
 #include "xmpp/bookmark.h"
 #include "ui/ui.h"
+#include "ui/windows.h"
 
 static void _update_presence(const resource_presence_t presence,
     const char * const show, gchar **args);
@@ -1796,19 +1797,49 @@ cmd_room(gchar **args, struct cmd_help_t help)
         return TRUE;
     }
 
-    if (g_strcmp0(args[1], "accept") == 0) {
-        // TODO check that we're in room, we're owner and room requires configuration
-        char *room = ui_current_recipient();
-        iq_create_instant_room(room);
+    win_type_t win_type = ui_current_win_type();
+    if (win_type != WIN_MUC) {
+        cons_show("Command /room only usable in chat rooms.");
+        return TRUE;
+    }
 
-    } else if (g_strcmp0(args[1], "cancel") == 0) {
-        // check that we're in room, we're owner and room requires configuration
-        char *room = ui_current_recipient();
-        iq_destroy_instant_room(room);
+    if (g_strcmp0(args[0], "config") != 0) {
+        cons_show("Usage: %s", help.usage);
+        return TRUE;
+    }
 
-    } else {
+    if ((g_strcmp0(args[1], "accept") != 0) &&
+            (g_strcmp0(args[1], "cancel") != 0)) {
         cons_show("Usage: %s", help.usage);
+        return TRUE;
     }
+
+    char *room = ui_current_recipient();
+    ProfWin *window = wins_get_by_recipient(room);
+    int num = wins_get_num(window);
+    int ui_index = num;
+    if (ui_index == 10) {
+        ui_index = 0;
+    }
+    gboolean requires_config = muc_requires_config(room);
+    if (!requires_config) {
+        win_save_vprint(window, '!', NULL, 0, COLOUR_ROOMINFO, "", "Current room ooes not require configuration.");
+        return TRUE;
+    }
+
+    if (g_strcmp0(args[1], "accept") == 0) {
+        iq_confirm_instant_room(room);
+        muc_set_requires_config(room, FALSE);
+        win_save_vprint(window, '!', NULL, 0, COLOUR_ROOMINFO, "", "Room unlocked.");
+        cons_show("Room unlocked: %s (%d)", room, ui_index);
+        return TRUE;
+    }
+
+    if (g_strcmp0(args[1], "cancel") == 0) {
+        iq_destroy_instant_room(room);
+        return TRUE;
+    }
+
     return TRUE;
 }
 
diff --git a/src/muc.c b/src/muc.c
index 053eb38b..3aef0220 100644
--- a/src/muc.c
+++ b/src/muc.c
@@ -49,6 +49,7 @@ typedef struct _muc_room_t {
     char *password;
     char *subject;
     char *autocomplete_prefix;
+    gboolean pending_config;
     GList *pending_broadcasts;
     gboolean autojoin;
     gboolean pending_nick_change;
@@ -162,6 +163,7 @@ muc_join_room(const char * const room, const char * const nick,
     }
     new_room->subject = NULL;
     new_room->pending_broadcasts = NULL;
+    new_room->pending_config = FALSE;
     new_room->roster = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
         (GDestroyNotify)p_contact_free);
     new_room->nick_ac = autocomplete_new();
@@ -185,6 +187,39 @@ muc_leave_room(const char * const room)
     }
 }
 
+gboolean
+muc_requires_config(const char * const room)
+{
+    if (rooms == NULL) {
+        return FALSE;
+    }
+
+    ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
+
+    if (chat_room == NULL) {
+        return FALSE;
+    }
+
+    return chat_room->pending_config;
+}
+
+void
+muc_set_requires_config(const char * const room, gboolean val)
+{
+    if (rooms == NULL) {
+        return;
+    }
+
+    ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
+
+    if (chat_room == NULL) {
+        return;
+    }
+
+    chat_room->pending_config = val;
+    return;
+}
+
 /*
  * Returns TRUE if the user is currently in the room
  */
diff --git a/src/muc.h b/src/muc.h
index 63e92163..540740d2 100644
--- a/src/muc.h
+++ b/src/muc.h
@@ -91,4 +91,7 @@ GList * muc_get_pending_broadcasts(const char * const room);
 void muc_autocomplete(char *input, int *size);
 void muc_reset_autocomplete(const char * const room);
 
+gboolean muc_requires_config(const char * const room);
+void muc_set_requires_config(const char * const room, gboolean val);
+
 #endif
diff --git a/src/server_events.c b/src/server_events.c
index 47fc2153..0ec07576 100644
--- a/src/server_events.c
+++ b/src/server_events.c
@@ -452,12 +452,14 @@ handle_room_nick_change(const char * const room,
 void
 handle_room_requires_config(const char * const room)
 {
+    muc_set_requires_config(room, TRUE);
     ui_room_requires_config(room);
 }
 
 void
 handle_room_destroy(const char * const room)
 {
+    muc_leave_room(room);
     ui_room_destroyed(room);
 }
 
diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c
index dc7e6de7..b4fc8176 100644
--- a/src/xmpp/iq.c
+++ b/src/xmpp/iq.c
@@ -163,7 +163,7 @@ _iq_send_software_version(const char * const fulljid)
 }
 
 static void
-_iq_create_instant_room(const char * const room_jid)
+_iq_confirm_instant_room(const char * const room_jid)
 {
     xmpp_conn_t * const conn = connection_get_conn();
     xmpp_ctx_t * const ctx = connection_get_ctx();
@@ -760,6 +760,6 @@ iq_init_module(void)
     iq_disco_items_request = _iq_disco_items_request;
     iq_send_software_version = _iq_send_software_version;
     iq_set_autoping = _iq_set_autoping;
-    iq_create_instant_room = _iq_create_instant_room;
+    iq_confirm_instant_room = _iq_confirm_instant_room;
     iq_destroy_instant_room = _iq_destroy_instant_room;
 }
diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h
index cc587872..fb15e7af 100644
--- a/src/xmpp/xmpp.h
+++ b/src/xmpp/xmpp.h
@@ -139,7 +139,7 @@ void (*iq_room_list_request)(gchar *conferencejid);
 void (*iq_disco_info_request)(gchar *jid);
 void (*iq_disco_items_request)(gchar *jid);
 void (*iq_set_autoping)(int seconds);
-void (*iq_create_instant_room)(const char * const room_jid);
+void (*iq_confirm_instant_room)(const char * const room_jid);
 void (*iq_destroy_instant_room)(const char * const room_jid);
 
 // caps functions