1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Allow nick change in chat room

This commit is contained in:
James Booth 2012-11-18 18:36:17 +00:00
parent a847ad5603
commit e9d6ba2117
7 changed files with 76 additions and 0 deletions

View File

@ -122,6 +122,7 @@ static gboolean _cmd_chat(gchar **args, struct cmd_help_t help);
static gboolean _cmd_xa(gchar **args, struct cmd_help_t help); static gboolean _cmd_xa(gchar **args, struct cmd_help_t help);
static gboolean _cmd_info(gchar **args, struct cmd_help_t help); static gboolean _cmd_info(gchar **args, struct cmd_help_t help);
static gboolean _cmd_wins(gchar **args, struct cmd_help_t help); static gboolean _cmd_wins(gchar **args, struct cmd_help_t help);
static gboolean _cmd_nick(gchar **args, struct cmd_help_t help);
/* /*
* The commands are broken down into three groups: * The commands are broken down into three groups:
@ -227,6 +228,19 @@ static struct cmd_t main_commands[] =
"Example : /join jdev@conference.jabber.org mynick", "Example : /join jdev@conference.jabber.org mynick",
NULL } } }, NULL } } },
{ "/nick",
_cmd_nick, parse_args_with_freetext, 1, 1,
{ "/nick [nickname]", "Change nickname in chat room.",
{ "/nick [nickname]",
"------------------------",
"Change the name by which other member of a chat room see you.",
"This command is only valid when called within a chat room window.",
"The new nickname may contain spaces.",
"",
"Example : /nick kai hansen",
"Example : /nick bob",
NULL } } },
{ "/wins", { "/wins",
_cmd_wins, parse_args, 0, 0, _cmd_wins, parse_args, 0, 0,
{ "/wins", "List active windows.", { "/wins", "List active windows.",
@ -1237,6 +1251,27 @@ _cmd_join(gchar **args, struct cmd_help_t help)
return TRUE; return TRUE;
} }
static gboolean
_cmd_nick(gchar **args, struct cmd_help_t help)
{
jabber_conn_status_t conn_status = jabber_get_connection_status();
if (conn_status != JABBER_CONNECTED) {
cons_show("You are not currently connected.");
return TRUE;
}
if (!win_in_groupchat()) {
cons_show("You can only change your nickname in a chat room window.");
return TRUE;
}
char *room = win_get_recipient();
char *nick = args[0];
jabber_change_room_nick(room, nick);
return TRUE;
}
static gboolean static gboolean
_cmd_tiny(gchar **args, struct cmd_help_t help) _cmd_tiny(gchar **args, struct cmd_help_t help)
{ {

View File

@ -266,6 +266,20 @@ jabber_join(const char * const room, const char * const nick)
free(full_room_jid); free(full_room_jid);
} }
void
jabber_change_room_nick(const char * const room, const char * const nick)
{
char *full_room_jid = room_create_full_room_jid(room, nick);
xmpp_stanza_t *presence = stanza_create_room_newnick_presence(jabber_conn.ctx,
full_room_jid);
xmpp_send(jabber_conn.conn, presence);
xmpp_stanza_release(presence);
room_change_nick(room, nick);
free(full_room_jid);
}
void void
jabber_leave_chat_room(const char * const room_jid) jabber_leave_chat_room(const char * const room_jid)
{ {

View File

@ -52,6 +52,7 @@ jabber_conn_status_t jabber_connect(const char * const user,
void jabber_disconnect(void); void jabber_disconnect(void);
void jabber_process_events(void); void jabber_process_events(void);
void jabber_join(const char * const room, const char * const nick); void jabber_join(const char * const room, const char * const nick);
void jabber_change_room_nick(const char * const room, const char * const nick);
void jabber_leave_chat_room(const char * const room_jid); void jabber_leave_chat_room(const char * const room_jid);
void jabber_subscription(const char * const jid, jabber_subscr_t action); void jabber_subscription(const char * const jid, jabber_subscr_t action);
void jabber_send(const char * const msg, const char * const recipient); void jabber_send(const char * const msg, const char * const recipient);

View File

@ -56,6 +56,17 @@ room_join(const char * const room, const char * const nick)
g_hash_table_insert(rooms, strdup(room), new_room); g_hash_table_insert(rooms, strdup(room), new_room);
} }
void
room_change_nick(const char * const room, const char * const nick)
{
muc_room *chat_room = g_hash_table_lookup(rooms, room);
if (chat_room != NULL) {
free(chat_room->nick);
chat_room->nick = strdup(nick);
}
}
void void
room_leave(const char * const room) room_leave(const char * const room)
{ {

View File

@ -26,6 +26,7 @@
#include <glib.h> #include <glib.h>
void room_join(const char * const room, const char * const nick); void room_join(const char * const room, const char * const nick);
void room_change_nick(const char * const room, const char * const nick);
void room_leave(const char * const room); void room_leave(const char * const room);
gboolean room_is_active(const char * const full_room_jid); gboolean room_is_active(const char * const full_room_jid);
char * room_get_nick_for_room(const char * const room); char * room_get_nick_for_room(const char * const room);

View File

@ -98,6 +98,17 @@ stanza_create_room_join_presence(xmpp_ctx_t *ctx,
return presence; return presence;
} }
xmpp_stanza_t *
stanza_create_room_newnick_presence(xmpp_ctx_t *ctx,
const char * const full_room_jid)
{
xmpp_stanza_t *presence = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(presence, STANZA_NAME_PRESENCE);
xmpp_stanza_set_attribute(presence, STANZA_ATTR_TO, full_room_jid);
return presence;
}
xmpp_stanza_t * xmpp_stanza_t *
stanza_create_room_leave_presence(xmpp_ctx_t *ctx, const char * const room, stanza_create_room_leave_presence(xmpp_ctx_t *ctx, const char * const room,
const char * const nick) const char * const nick)

View File

@ -85,6 +85,9 @@ xmpp_stanza_t* stanza_create_message(xmpp_ctx_t *ctx,
xmpp_stanza_t* stanza_create_room_join_presence(xmpp_ctx_t *ctx, xmpp_stanza_t* stanza_create_room_join_presence(xmpp_ctx_t *ctx,
const char * const full_room_jid); const char * const full_room_jid);
xmpp_stanza_t* stanza_create_room_newnick_presence(xmpp_ctx_t *ctx,
const char * const full_room_jid);
xmpp_stanza_t* stanza_create_room_leave_presence(xmpp_ctx_t *ctx, xmpp_stanza_t* stanza_create_room_leave_presence(xmpp_ctx_t *ctx,
const char * const room, const char * const nick); const char * const room, const char * const nick);