mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Implemented /room config submit for saving room configuration
This commit is contained in:
parent
5aa75b1f8b
commit
eba3a7cb30
@ -1798,7 +1798,7 @@ cmd_room(gchar **args, struct cmd_help_t help)
|
||||
}
|
||||
|
||||
win_type_t win_type = ui_current_win_type();
|
||||
if (win_type != WIN_MUC) {
|
||||
if (win_type != WIN_MUC && win_type != WIN_MUC_CONFIG) {
|
||||
cons_show("Command /room only usable in chat rooms.");
|
||||
return TRUE;
|
||||
}
|
||||
@ -1811,6 +1811,7 @@ cmd_room(gchar **args, struct cmd_help_t help)
|
||||
if ((g_strcmp0(args[1], "accept") != 0) &&
|
||||
(g_strcmp0(args[1], "cancel") != 0) &&
|
||||
(g_strcmp0(args[1], "destroy") != 0) &&
|
||||
(g_strcmp0(args[1], "submit") != 0) &&
|
||||
(g_strcmp0(args[1], "edit") != 0)) {
|
||||
cons_show("Usage: %s", help.usage);
|
||||
return TRUE;
|
||||
@ -1857,6 +1858,20 @@ cmd_room(gchar **args, struct cmd_help_t help)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (g_strcmp0(args[1], "submit") == 0) {
|
||||
ProfWin *current = wins_get_current();
|
||||
if (current->type != WIN_MUC_CONFIG) {
|
||||
cons_show("Room configuration can only be submitted when in the room configuration window.");
|
||||
return TRUE;
|
||||
} else {
|
||||
gchar **split_recipient = g_strsplit(room, " ", 2);
|
||||
room = split_recipient[0];
|
||||
iq_submit_room_config(room, current->form);
|
||||
g_strfreev(split_recipient);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (g_strcmp0(args[1], "cancel") == 0) {
|
||||
iq_room_config_cancel(room);
|
||||
return TRUE;
|
||||
|
@ -469,6 +469,12 @@ handle_room_configure(const char * const room, DataForm *form)
|
||||
ui_handle_room_configuration(room, form);
|
||||
}
|
||||
|
||||
void
|
||||
handle_room_config_submit_result(void)
|
||||
{
|
||||
ui_handle_room_config_submit_result();
|
||||
}
|
||||
|
||||
void
|
||||
handle_room_configuration_form_error(const char * const room, const char * const message)
|
||||
{
|
||||
|
@ -98,5 +98,6 @@ void handle_ping_result(const char * const from, int millis);
|
||||
void handle_ping_error_result(const char * const from, const char * const error);
|
||||
void handle_room_configure(const char * const room, DataForm *form);
|
||||
void handle_room_configuration_form_error(const char * const from, const char * const message);
|
||||
void handle_room_config_submit_result(void);
|
||||
|
||||
#endif
|
||||
|
@ -1997,6 +1997,8 @@ _ui_handle_room_configuration(const char * const room, DataForm *form)
|
||||
ProfWin *window = wins_new(title->str, WIN_MUC_CONFIG);
|
||||
g_string_free(title, TRUE);
|
||||
|
||||
window->form = form;
|
||||
|
||||
int num = wins_get_num(window);
|
||||
ui_switch_win(num);
|
||||
|
||||
@ -2041,8 +2043,12 @@ TODO add command to get help for a field
|
||||
|
||||
curr_field = g_slist_next(curr_field);
|
||||
}
|
||||
}
|
||||
|
||||
form_destroy(form);
|
||||
static void
|
||||
_ui_handle_room_config_submit_result(void)
|
||||
{
|
||||
cons_show("GOT ROOM CONFIG SUBMIT RESULT!!!!");
|
||||
}
|
||||
|
||||
static void
|
||||
@ -2283,4 +2289,5 @@ ui_init_module(void)
|
||||
ui_room_requires_config = _ui_room_requires_config;
|
||||
ui_room_destroyed = _ui_room_destroyed;
|
||||
ui_handle_room_configuration = _ui_handle_room_configuration;
|
||||
ui_handle_room_config_submit_result = _ui_handle_room_config_submit_result;
|
||||
}
|
||||
|
@ -161,6 +161,7 @@ void (*ui_handle_error)(const char * const err_msg);
|
||||
void (*ui_clear_win_title)(void);
|
||||
void (*ui_handle_room_join_error)(const char * const room, const char * const err);
|
||||
void (*ui_handle_room_configuration)(const char * const room, DataForm *form);
|
||||
void (*ui_handle_room_config_submit_result)(void);
|
||||
|
||||
// contact status functions
|
||||
void (*ui_status_room)(const char * const contact);
|
||||
|
@ -68,6 +68,7 @@ win_create(const char * const title, int cols, win_type_t type)
|
||||
new_win->type = type;
|
||||
new_win->is_otr = FALSE;
|
||||
new_win->is_trusted = FALSE;
|
||||
new_win->form = NULL;
|
||||
scrollok(new_win->win, TRUE);
|
||||
|
||||
return new_win;
|
||||
@ -79,6 +80,7 @@ win_free(ProfWin* window)
|
||||
buffer_free(window->buffer);
|
||||
delwin(window->win);
|
||||
free(window->from);
|
||||
form_destroy(window->form);
|
||||
free(window);
|
||||
}
|
||||
|
||||
|
@ -45,6 +45,7 @@
|
||||
|
||||
#include "contact.h"
|
||||
#include "ui/buffer.h"
|
||||
#include "xmpp/xmpp.h"
|
||||
|
||||
#define NO_ME 1
|
||||
#define NO_DATE 2
|
||||
@ -75,6 +76,7 @@ typedef struct prof_win_t {
|
||||
int paged;
|
||||
int unread;
|
||||
int history_shown;
|
||||
DataForm *form;
|
||||
} ProfWin;
|
||||
|
||||
ProfWin* win_create(const char * const title, int cols, win_type_t type);
|
||||
|
@ -236,6 +236,86 @@ form_create(xmpp_stanza_t * const form_stanza)
|
||||
return form;
|
||||
}
|
||||
|
||||
xmpp_stanza_t *
|
||||
form_create_submission(DataForm *form)
|
||||
{
|
||||
xmpp_ctx_t *ctx = connection_get_ctx();
|
||||
|
||||
xmpp_stanza_t *x = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(x, STANZA_NAME_X);
|
||||
xmpp_stanza_set_ns(x, STANZA_NS_DATA);
|
||||
xmpp_stanza_set_type(x, "submit");
|
||||
|
||||
GSList *curr_field = form->fields;
|
||||
while (curr_field != NULL) {
|
||||
FormField *field = curr_field->data;
|
||||
|
||||
xmpp_stanza_t *field_stanza = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(field_stanza, "field");
|
||||
xmpp_stanza_set_attribute(field_stanza, "var", field->var);
|
||||
|
||||
xmpp_stanza_t *value_stanza = NULL;
|
||||
GSList *curr_value = NULL;
|
||||
|
||||
switch (field->type_t) {
|
||||
|
||||
case FIELD_HIDDEN:
|
||||
case FIELD_TEXT_SINGLE:
|
||||
case FIELD_TEXT_PRIVATE:
|
||||
case FIELD_BOOLEAN:
|
||||
case FIELD_LIST_SINGLE:
|
||||
case FIELD_JID_SINGLE:
|
||||
case FIELD_FIXED:
|
||||
value_stanza = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(value_stanza, "value");
|
||||
if (field->values != NULL) {
|
||||
if (field->values->data != NULL) {
|
||||
xmpp_stanza_t *text_stanza = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_text(text_stanza, field->values->data);
|
||||
xmpp_stanza_add_child(value_stanza, text_stanza);
|
||||
xmpp_stanza_release(text_stanza);
|
||||
}
|
||||
}
|
||||
xmpp_stanza_add_child(field_stanza, value_stanza);
|
||||
xmpp_stanza_release(value_stanza);
|
||||
|
||||
break;
|
||||
|
||||
case FIELD_TEXT_MULTI:
|
||||
case FIELD_LIST_MUTLI:
|
||||
case FIELD_JID_MULTI:
|
||||
curr_value = field->values;
|
||||
while (curr_value != NULL) {
|
||||
char *value = curr_value->data;
|
||||
|
||||
value_stanza = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(value_stanza, "value");
|
||||
if (value != NULL) {
|
||||
xmpp_stanza_t *text_stanza = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_text(text_stanza, value);
|
||||
xmpp_stanza_add_child(value_stanza, text_stanza);
|
||||
xmpp_stanza_release(text_stanza);
|
||||
}
|
||||
|
||||
xmpp_stanza_add_child(field_stanza, value_stanza);
|
||||
xmpp_stanza_release(value_stanza);
|
||||
|
||||
curr_value = g_slist_next(curr_value);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
xmpp_stanza_add_child(x, field_stanza);
|
||||
xmpp_stanza_release(field_stanza);
|
||||
|
||||
curr_field = g_slist_next(curr_field);
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
static void
|
||||
_free_option(FormOption *option)
|
||||
{
|
||||
|
@ -36,5 +36,6 @@
|
||||
#define FROM_H
|
||||
|
||||
DataForm* form_create(xmpp_stanza_t * const stanza);
|
||||
xmpp_stanza_t* form_create_submission(DataForm *form);
|
||||
|
||||
#endif
|
||||
|
@ -78,6 +78,8 @@ static int _destroy_room_result_handler(xmpp_conn_t * const conn,
|
||||
xmpp_stanza_t * const stanza, void * const userdata);
|
||||
static int _room_config_handler(xmpp_conn_t * const conn,
|
||||
xmpp_stanza_t * const stanza, void * const userdata);
|
||||
static int _room_config_submit_handler(xmpp_conn_t * const conn,
|
||||
xmpp_stanza_t * const stanza, void * const userdata);
|
||||
static int _manual_pong_handler(xmpp_conn_t *const conn,
|
||||
xmpp_stanza_t * const stanza, void * const userdata);
|
||||
static int _ping_timed_handler(xmpp_conn_t * const conn,
|
||||
@ -203,6 +205,20 @@ _iq_request_room_config_form(const char * const room_jid)
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
static void
|
||||
_iq_submit_room_config(const char * const room, DataForm *form)
|
||||
{
|
||||
xmpp_conn_t * const conn = connection_get_conn();
|
||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||
xmpp_stanza_t *iq = stanza_create_room_config_submit_iq(ctx, room, form);
|
||||
|
||||
char *id = xmpp_stanza_get_id(iq);
|
||||
xmpp_id_handler_add(conn, _room_config_submit_handler, id, NULL);
|
||||
|
||||
xmpp_send(conn, iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
static void
|
||||
_iq_room_config_cancel(const char * const room_jid)
|
||||
{
|
||||
@ -645,6 +661,23 @@ _room_config_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
_room_config_submit_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||
void * const userdata)
|
||||
{
|
||||
const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID);
|
||||
|
||||
if (id != NULL) {
|
||||
log_debug("IQ room config handler fired, id: %s.", id);
|
||||
} else {
|
||||
log_debug("IQ room config handler fired.");
|
||||
}
|
||||
|
||||
handle_room_config_submit_result();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
_identity_destroy(DiscoIdentity *identity)
|
||||
{
|
||||
@ -897,4 +930,5 @@ iq_init_module(void)
|
||||
iq_send_ping = _iq_send_ping;
|
||||
iq_request_room_config_form = _iq_request_room_config_form;
|
||||
iq_room_config_cancel = _iq_room_config_cancel;
|
||||
iq_submit_room_config = _iq_submit_room_config;
|
||||
}
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include "xmpp/connection.h"
|
||||
#include "xmpp/stanza.h"
|
||||
#include "xmpp/capabilities.h"
|
||||
#include "xmpp/form.h"
|
||||
|
||||
#include "muc.h"
|
||||
|
||||
@ -616,6 +617,31 @@ stanza_create_disco_items_iq(xmpp_ctx_t *ctx, const char * const id,
|
||||
return iq;
|
||||
}
|
||||
|
||||
xmpp_stanza_t *
|
||||
stanza_create_room_config_submit_iq(xmpp_ctx_t *ctx, const char * const room, DataForm *form)
|
||||
{
|
||||
xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
|
||||
xmpp_stanza_set_type(iq, STANZA_TYPE_SET);
|
||||
xmpp_stanza_set_attribute(iq, STANZA_ATTR_TO, room);
|
||||
char *id = create_unique_id("roomconf_submit");
|
||||
xmpp_stanza_set_id(iq, id);
|
||||
free(id);
|
||||
|
||||
xmpp_stanza_t *query = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
|
||||
xmpp_stanza_set_ns(query, STANZA_NS_MUC_OWNER);
|
||||
|
||||
xmpp_stanza_t *x = form_create_submission(form);
|
||||
xmpp_stanza_add_child(query, x);
|
||||
xmpp_stanza_release(x);
|
||||
|
||||
xmpp_stanza_add_child(iq, query);
|
||||
xmpp_stanza_release(query);
|
||||
|
||||
return iq;
|
||||
}
|
||||
|
||||
gboolean
|
||||
stanza_contains_chat_state(xmpp_stanza_t *stanza)
|
||||
{
|
||||
|
@ -202,6 +202,8 @@ xmpp_stanza_t* stanza_create_room_config_request_iq(xmpp_ctx_t *ctx,
|
||||
const char * const room_jid);
|
||||
xmpp_stanza_t* stanza_create_room_config_cancel_iq(xmpp_ctx_t *ctx,
|
||||
const char * const room_jid);
|
||||
xmpp_stanza_t* stanza_create_room_config_submit_iq(xmpp_ctx_t *ctx,
|
||||
const char * const room, DataForm *form);
|
||||
|
||||
int stanza_get_idle_time(xmpp_stanza_t * const stanza);
|
||||
char * stanza_get_caps_str(xmpp_stanza_t * const stanza);
|
||||
|
@ -180,6 +180,7 @@ void (*iq_set_autoping)(int seconds);
|
||||
void (*iq_confirm_instant_room)(const char * const room_jid);
|
||||
void (*iq_destroy_instant_room)(const char * const room_jid);
|
||||
void (*iq_request_room_config_form)(const char * const room_jid);
|
||||
void (*iq_submit_room_config)(const char * const room, DataForm *form);
|
||||
void (*iq_room_config_cancel)(const char * const room_jid);
|
||||
void (*iq_send_ping)(const char * const target);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user