1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Add /rooms service autocompletion

This commit is contained in:
James Booth 2018-02-05 21:40:32 +00:00
parent e6d9a243cd
commit cba17faf3d
6 changed files with 79 additions and 7 deletions

View File

@ -940,6 +940,7 @@ cmd_ac_reset(ProfWin *window)
}
muc_invites_reset_ac();
muc_confserver_reset_ac();
accounts_reset_all_search();
accounts_reset_enabled_search();
tlscerts_reset_ac();
@ -3133,17 +3134,21 @@ _rooms_autocomplete(ProfWin *window, const char *const input, gboolean previous)
return found;
}
}
if ((num_args == 1 && g_strcmp0(args[0], "cache") == 0 && space_at_end) ||
(num_args == 2 && g_strcmp0(args[0], "cache") == 0)) {
found = autocomplete_param_with_ac(input, "/rooms cache", rooms_cache_ac, TRUE, previous);
if ((num_args == 1 && g_strcmp0(args[0], "service") == 0 && space_at_end) ||
(num_args == 2 && g_strcmp0(args[0], "service") == 0 && !space_at_end)) {
found = autocomplete_param_with_func(input, "/rooms service", muc_confserver_find, previous);
if (found) {
g_strfreev(args);
return found;
}
}
if ((num_args >= 2) && g_strcmp0(args[0], "cache") == 0) {
g_strfreev(args);
return NULL;
if ((num_args == 1 && g_strcmp0(args[0], "cache") == 0 && space_at_end) ||
(num_args == 2 && g_strcmp0(args[0], "cache") == 0 && !space_at_end)) {
found = autocomplete_param_with_ac(input, "/rooms cache", rooms_cache_ac, TRUE, previous);
if (found) {
g_strfreev(args);
return found;
}
}
if ((num_args == 2 && space_at_end) || (num_args == 3 && !space_at_end)) {
GString *beginning = g_string_new("/rooms");
@ -3155,9 +3160,24 @@ _rooms_autocomplete(ProfWin *window, const char *const input, gboolean previous)
return found;
}
}
if ((num_args == 3 && g_strcmp0(args[2], "service") == 0 && space_at_end) ||
(num_args == 4 && g_strcmp0(args[2], "service") == 0 && !space_at_end)) {
GString *beginning = g_string_new("/rooms");
g_string_append_printf(beginning, " %s %s %s", args[0], args[1], args[2]);
found = autocomplete_param_with_func(input, beginning->str, muc_confserver_find, previous);
g_string_free(beginning, TRUE);
if (found) {
g_strfreev(args);
return found;
}
}
if ((num_args >= 2) && g_strcmp0(args[0], "cache") == 0) {
g_strfreev(args);
return NULL;
}
}
g_strfreev(args);
return NULL;
}
}

View File

@ -88,6 +88,7 @@ cl_ev_disconnect(void)
session_disconnect();
roster_destroy();
muc_invites_clear();
muc_confserver_clear();
chat_sessions_clear();
tlscerts_clear_current();
#ifdef HAVE_LIBGPGME

View File

@ -181,6 +181,7 @@ sv_ev_lost_connection(void)
#endif
muc_invites_clear();
muc_confserver_clear();
chat_sessions_clear();
ui_disconnected();
roster_destroy();
@ -797,6 +798,12 @@ sv_ev_muc_self_online(const char *const room, const char *const nick, gboolean c
ui_room_join(room, TRUE);
}
Jid *jidp = jid_create(room);
if (jidp->domainpart) {
muc_confserver_add(jidp->domainpart);
}
jid_destroy(jidp);
iq_room_info_request(room, FALSE);
if (muc_invites_contain(room)) {

View File

@ -98,6 +98,12 @@ bookmark_add(const char *jid, const char *nick, const char *password, const char
{
assert(jid != NULL);
Jid *jidp = jid_create(jid);
if (jidp->domainpart) {
muc_confserver_add(jidp->domainpart);
}
jid_destroy(jidp);
if (g_hash_table_contains(bookmarks, jid)) {
return FALSE;
}
@ -297,6 +303,12 @@ _bookmark_result_id_handler(xmpp_stanza_t *const stanza, void *const userdata)
sv_ev_bookmark_autojoin(bookmark);
}
Jid *jidp = jid_create(barejid);
if (jidp->domainpart) {
muc_confserver_add(jidp->domainpart);
}
jid_destroy(jidp);
child = xmpp_stanza_get_next(child);
}

View File

@ -69,6 +69,7 @@ typedef struct _muc_room_t {
GHashTable *rooms = NULL;
GHashTable *invite_passwords = NULL;
Autocomplete invite_ac;
Autocomplete confservers_ac;
static void _free_room(ChatRoom *room);
static gint _compare_occupants(Occupant *a, Occupant *b);
@ -84,6 +85,7 @@ void
muc_init(void)
{
invite_ac = autocomplete_new();
confservers_ac = autocomplete_new();
rooms = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)_free_room);
invite_passwords = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
}
@ -92,12 +94,19 @@ void
muc_close(void)
{
autocomplete_free(invite_ac);
autocomplete_free(confservers_ac);
g_hash_table_destroy(rooms);
g_hash_table_destroy(invite_passwords);
rooms = NULL;
invite_passwords = NULL;
}
void
muc_confserver_add(const char *const server)
{
autocomplete_add(confservers_ac, server);
}
void
muc_invites_add(const char *const room, const char *const password)
{
@ -156,12 +165,24 @@ muc_invites_reset_ac(void)
autocomplete_reset(invite_ac);
}
void
muc_confserver_reset_ac(void)
{
autocomplete_reset(confservers_ac);
}
char*
muc_invites_find(const char *const search_str, gboolean previous)
{
return autocomplete_complete(invite_ac, search_str, TRUE, previous);
}
char*
muc_confserver_find(const char *const search_str, gboolean previous)
{
return autocomplete_complete(confservers_ac, search_str, TRUE, previous);
}
void
muc_invites_clear(void)
{
@ -171,6 +192,12 @@ muc_invites_clear(void)
}
}
void
muc_confserver_clear(void)
{
autocomplete_clear(confservers_ac);
}
void
muc_join(const char *const room, const char *const nick, const char *const password, gboolean autojoin)
{

View File

@ -117,6 +117,11 @@ GSList* muc_occupants_by_affiliation(const char *const room, muc_affiliation_t a
void muc_occupant_nick_change_start(const char *const room, const char *const new_nick, const char *const old_nick);
char* muc_roster_nick_change_complete(const char *const room, const char *const nick);
void muc_confserver_add(const char *const server);
void muc_confserver_reset_ac(void);
char* muc_confserver_find(const char *const search_str, gboolean previous);
void muc_confserver_clear(void);
void muc_invites_add(const char *const room, const char *const password);
void muc_invites_remove(const char *const room);
gint muc_invites_count(void);