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

Use room nickname autocompleter on /info and /msg when in chat room

This commit is contained in:
James Booth 2013-01-11 00:48:58 +00:00
parent 89967905db
commit 62c102860c
3 changed files with 65 additions and 22 deletions

View File

@ -41,6 +41,7 @@
#include "preferences.h" #include "preferences.h"
#include "prof_autocomplete.h" #include "prof_autocomplete.h"
#include "profanity.h" #include "profanity.h"
#include "room_chat.h"
#include "theme.h" #include "theme.h"
#include "tinyurl.h" #include "tinyurl.h"
#include "ui.h" #include "ui.h"
@ -768,7 +769,16 @@ cmd_reset_autocomplete()
p_autocomplete_reset(help_ac); p_autocomplete_reset(help_ac);
p_autocomplete_reset(notify_ac); p_autocomplete_reset(notify_ac);
p_autocomplete_reset(sub_ac); p_autocomplete_reset(sub_ac);
p_autocomplete_reset(who_ac);
if (win_current_is_groupchat()) {
PAutocomplete nick_ac = room_get_nick_ac(win_current_get_recipient());
if (nick_ac != NULL) {
p_autocomplete_reset(nick_ac);
}
} else {
p_autocomplete_reset(who_ac);
}
p_autocomplete_reset(prefs_ac); p_autocomplete_reset(prefs_ac);
p_autocomplete_reset(log_ac); p_autocomplete_reset(log_ac);
p_autocomplete_reset(commands_ac); p_autocomplete_reset(commands_ac);
@ -905,10 +915,19 @@ _cmd_complete_parameters(char *input, int *size)
_parameter_autocomplete(input, size, "/vercheck", _parameter_autocomplete(input, size, "/vercheck",
prefs_autocomplete_boolean_choice); prefs_autocomplete_boolean_choice);
_parameter_autocomplete(input, size, "/msg", if (win_current_is_groupchat()) {
contact_list_find_contact); PAutocomplete nick_ac = room_get_nick_ac(win_current_get_recipient());
_parameter_autocomplete(input, size, "/info", if (nick_ac != NULL) {
contact_list_find_contact); _parameter_autocomplete_with_ac(input, size, "/msg", nick_ac);
_parameter_autocomplete_with_ac(input, size, "/info", nick_ac);
}
} else {
_parameter_autocomplete(input, size, "/msg",
contact_list_find_contact);
_parameter_autocomplete(input, size, "/info",
contact_list_find_contact);
}
_parameter_autocomplete(input, size, "/connect", _parameter_autocomplete(input, size, "/connect",
accounts_find_enabled); accounts_find_enabled);
_parameter_autocomplete_with_ac(input, size, "/sub", sub_ac); _parameter_autocomplete_with_ac(input, size, "/sub", sub_ac);
@ -1639,29 +1658,38 @@ _cmd_tiny(gchar **args, struct cmd_help_t help)
static gboolean static gboolean
_cmd_close(gchar **args, struct cmd_help_t help) _cmd_close(gchar **args, struct cmd_help_t help)
{ {
if (win_current_is_groupchat()) { jabber_conn_status_t conn_status = jabber_get_connection_status();
char *room_jid = win_current_get_recipient();
jabber_leave_chat_room(room_jid);
win_current_close();
} else if (win_current_is_chat() || win_current_is_private()) {
if (prefs_get_states()) { // cannot close console window
char *recipient = win_current_get_recipient(); if (!win_current_is_chat() && !win_current_is_groupchat()
&& !win_current_is_private()) {
cons_show("Cannot close console window.");
return TRUE;
}
// send <gone/> chat state before closing // handle leaving rooms, or chat
if (chat_session_get_recipient_supports(recipient)) { if (conn_status == JABBER_CONNECTED) {
chat_session_set_gone(recipient); if (win_current_is_groupchat()) {
jabber_send_gone(recipient); char *room_jid = win_current_get_recipient();
chat_session_end(recipient); jabber_leave_chat_room(room_jid);
} else if (win_current_is_chat() || win_current_is_private()) {
if (prefs_get_states()) {
char *recipient = win_current_get_recipient();
// send <gone/> chat state before closing
if (chat_session_get_recipient_supports(recipient)) {
chat_session_set_gone(recipient);
jabber_send_gone(recipient);
chat_session_end(recipient);
}
} }
} }
win_current_close();
} else {
cons_show("Cannot close console window.");
} }
// close the window
win_current_close();
return TRUE; return TRUE;
} }

View File

@ -286,6 +286,18 @@ room_get_roster(const char * const room)
} }
} }
PAutocomplete
room_get_nick_ac(const char * const room)
{
muc_room *chat_room = g_hash_table_lookup(rooms, room);
if (chat_room != NULL) {
return chat_room->nick_ac;
} else {
return NULL;
}
}
void void
room_set_roster_received(const char * const room) room_set_roster_received(const char * const room)
{ {

View File

@ -25,6 +25,8 @@
#include <glib.h> #include <glib.h>
#include "prof_autocomplete.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_change_nick(const char * const room, const char * const nick);
void room_leave(const char * const room); void room_leave(const char * const room);
@ -42,6 +44,7 @@ char* room_complete_pending_nick_change(const char * const room,
const char * const nick); const char * const nick);
gboolean room_nick_in_roster(const char * const room, const char * const nick); gboolean room_nick_in_roster(const char * const room, const char * const nick);
gboolean room_from_jid_is_room(const char * const room_jid); gboolean room_from_jid_is_room(const char * const room_jid);
PAutocomplete room_get_nick_ac(const char * const room);
GList * room_get_roster(const char * const room); GList * room_get_roster(const char * const room);
void room_set_roster_received(const char * const room); void room_set_roster_received(const char * const room);