mirror of
https://github.com/profanity-im/profanity.git
synced 2025-01-03 14:57:42 -05:00
Validate usage of /room config command, added UI messages
This commit is contained in:
parent
64521eb135
commit
b50b786dcc
@ -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",
|
||||
|
@ -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);
|
||||
|
||||
} 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);
|
||||
|
||||
} else {
|
||||
cons_show("Usage: %s", help.usage);
|
||||
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;
|
||||
}
|
||||
|
||||
if (g_strcmp0(args[0], "config") != 0) {
|
||||
cons_show("Usage: %s", help.usage);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
35
src/muc.c
35
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
|
||||
*/
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user