mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Added jid autocompleter for /roster nick command
This commit is contained in:
parent
72b8097465
commit
6c4b81d093
@ -3236,7 +3236,7 @@ static void
|
|||||||
_roster_autocomplete(char *input, int *size)
|
_roster_autocomplete(char *input, int *size)
|
||||||
{
|
{
|
||||||
if ((strncmp(input, "/roster nick ", 13) == 0) && (*size > 13)) {
|
if ((strncmp(input, "/roster nick ", 13) == 0) && (*size > 13)) {
|
||||||
_parameter_autocomplete(input, size, "/roster nick", roster_find_contact);
|
_parameter_autocomplete(input, size, "/roster nick", roster_find_jid);
|
||||||
} else if ((strncmp(input, "/roster ", 8) == 0) && (*size > 8)) {
|
} else if ((strncmp(input, "/roster ", 8) == 0) && (*size > 8)) {
|
||||||
_parameter_autocomplete_with_ac(input, size, "/roster", roster_ac);
|
_parameter_autocomplete_with_ac(input, size, "/roster", roster_ac);
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,8 @@ static int _roster_handle_set(xmpp_conn_t * const conn,
|
|||||||
static int _roster_handle_result(xmpp_conn_t * const conn,
|
static int _roster_handle_result(xmpp_conn_t * const conn,
|
||||||
xmpp_stanza_t * const stanza, void * const userdata);
|
xmpp_stanza_t * const stanza, void * const userdata);
|
||||||
|
|
||||||
static Autocomplete ac;
|
static Autocomplete handle_ac;
|
||||||
|
static Autocomplete jid_ac;
|
||||||
static Autocomplete resource_ac;
|
static Autocomplete resource_ac;
|
||||||
static GHashTable *contacts;
|
static GHashTable *contacts;
|
||||||
static GHashTable *handle_to_jid;
|
static GHashTable *handle_to_jid;
|
||||||
@ -89,7 +90,8 @@ _roster_handle_set(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
|||||||
const char *name = xmpp_stanza_get_attribute(item, STANZA_ATTR_NAME);
|
const char *name = xmpp_stanza_get_attribute(item, STANZA_ATTR_NAME);
|
||||||
const char *sub = xmpp_stanza_get_attribute(item, STANZA_ATTR_SUBSCRIPTION);
|
const char *sub = xmpp_stanza_get_attribute(item, STANZA_ATTR_SUBSCRIPTION);
|
||||||
if (g_strcmp0(sub, "remove") == 0) {
|
if (g_strcmp0(sub, "remove") == 0) {
|
||||||
autocomplete_remove(ac, name);
|
autocomplete_remove(jid_ac, jid);
|
||||||
|
autocomplete_remove(handle_ac, name);
|
||||||
g_hash_table_remove(handle_to_jid, name);
|
g_hash_table_remove(handle_to_jid, name);
|
||||||
g_hash_table_remove(contacts, jid);
|
g_hash_table_remove(contacts, jid);
|
||||||
return 1;
|
return 1;
|
||||||
@ -147,7 +149,8 @@ _roster_handle_result(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
|||||||
void
|
void
|
||||||
roster_init(void)
|
roster_init(void)
|
||||||
{
|
{
|
||||||
ac = autocomplete_new();
|
handle_ac = autocomplete_new();
|
||||||
|
jid_ac = autocomplete_new();
|
||||||
resource_ac = autocomplete_new();
|
resource_ac = autocomplete_new();
|
||||||
contacts = g_hash_table_new_full(g_str_hash, (GEqualFunc)_key_equals, g_free,
|
contacts = g_hash_table_new_full(g_str_hash, (GEqualFunc)_key_equals, g_free,
|
||||||
(GDestroyNotify)p_contact_free);
|
(GDestroyNotify)p_contact_free);
|
||||||
@ -157,7 +160,8 @@ roster_init(void)
|
|||||||
void
|
void
|
||||||
roster_clear(void)
|
roster_clear(void)
|
||||||
{
|
{
|
||||||
autocomplete_clear(ac);
|
autocomplete_clear(handle_ac);
|
||||||
|
autocomplete_clear(jid_ac);
|
||||||
autocomplete_clear(resource_ac);
|
autocomplete_clear(resource_ac);
|
||||||
g_hash_table_destroy(contacts);
|
g_hash_table_destroy(contacts);
|
||||||
contacts = g_hash_table_new_full(g_str_hash, (GEqualFunc)_key_equals, g_free,
|
contacts = g_hash_table_new_full(g_str_hash, (GEqualFunc)_key_equals, g_free,
|
||||||
@ -169,14 +173,16 @@ roster_clear(void)
|
|||||||
void
|
void
|
||||||
roster_free()
|
roster_free()
|
||||||
{
|
{
|
||||||
autocomplete_free(ac);
|
autocomplete_free(handle_ac);
|
||||||
|
autocomplete_free(jid_ac);
|
||||||
autocomplete_free(resource_ac);
|
autocomplete_free(resource_ac);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
roster_reset_search_attempts(void)
|
roster_reset_search_attempts(void)
|
||||||
{
|
{
|
||||||
autocomplete_reset(ac);
|
autocomplete_reset(handle_ac);
|
||||||
|
autocomplete_reset(jid_ac);
|
||||||
autocomplete_reset(resource_ac);
|
autocomplete_reset(resource_ac);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,12 +199,14 @@ roster_add(const char * const barejid, const char * const name,
|
|||||||
pending_out);
|
pending_out);
|
||||||
g_hash_table_insert(contacts, strdup(barejid), contact);
|
g_hash_table_insert(contacts, strdup(barejid), contact);
|
||||||
if (name != NULL) {
|
if (name != NULL) {
|
||||||
autocomplete_add(ac, strdup(name));
|
autocomplete_add(handle_ac, strdup(name));
|
||||||
g_hash_table_insert(handle_to_jid, strdup(name), strdup(barejid));
|
g_hash_table_insert(handle_to_jid, strdup(name), strdup(barejid));
|
||||||
} else {
|
} else {
|
||||||
autocomplete_add(ac, strdup(barejid));
|
autocomplete_add(handle_ac, strdup(barejid));
|
||||||
g_hash_table_insert(handle_to_jid, strdup(barejid), strdup(barejid));
|
g_hash_table_insert(handle_to_jid, strdup(barejid), strdup(barejid));
|
||||||
}
|
}
|
||||||
|
autocomplete_add(jid_ac, strdup(barejid));
|
||||||
|
|
||||||
added = TRUE;
|
added = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,18 +264,18 @@ roster_change_handle(const char * const barejid, const char * const handle)
|
|||||||
PContact contact = g_hash_table_lookup(contacts, barejid);
|
PContact contact = g_hash_table_lookup(contacts, barejid);
|
||||||
|
|
||||||
if (p_contact_name(contact) != NULL) {
|
if (p_contact_name(contact) != NULL) {
|
||||||
autocomplete_remove(ac, p_contact_name(contact));
|
autocomplete_remove(handle_ac, p_contact_name(contact));
|
||||||
g_hash_table_remove(handle_to_jid, p_contact_name(contact));
|
g_hash_table_remove(handle_to_jid, p_contact_name(contact));
|
||||||
} else {
|
} else {
|
||||||
autocomplete_remove(ac, barejid);
|
autocomplete_remove(handle_ac, barejid);
|
||||||
g_hash_table_remove(handle_to_jid, barejid);
|
g_hash_table_remove(handle_to_jid, barejid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (handle != NULL) {
|
if (handle != NULL) {
|
||||||
autocomplete_add(ac, strdup(handle));
|
autocomplete_add(handle_ac, strdup(handle));
|
||||||
g_hash_table_insert(handle_to_jid, strdup(handle), strdup(barejid));
|
g_hash_table_insert(handle_to_jid, strdup(handle), strdup(barejid));
|
||||||
} else {
|
} else {
|
||||||
autocomplete_add(ac, strdup(barejid));
|
autocomplete_add(handle_ac, strdup(barejid));
|
||||||
g_hash_table_insert(handle_to_jid, strdup(barejid), strdup(barejid));
|
g_hash_table_insert(handle_to_jid, strdup(barejid), strdup(barejid));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,7 +298,8 @@ roster_update(const char * const barejid, const char * const name,
|
|||||||
|
|
||||||
if (contact == NULL) {
|
if (contact == NULL) {
|
||||||
contact = p_contact_new(barejid, name, subscription, NULL, pending_out);
|
contact = p_contact_new(barejid, name, subscription, NULL, pending_out);
|
||||||
autocomplete_add(ac, strdup(name));
|
autocomplete_add(jid_ac, strdup(barejid));
|
||||||
|
autocomplete_add(handle_ac, strdup(name));
|
||||||
g_hash_table_insert(handle_to_jid, strdup(name), strdup(barejid));
|
g_hash_table_insert(handle_to_jid, strdup(name), strdup(barejid));
|
||||||
g_hash_table_insert(contacts, strdup(barejid), contact);
|
g_hash_table_insert(contacts, strdup(barejid), contact);
|
||||||
} else {
|
} else {
|
||||||
@ -299,15 +308,15 @@ roster_update(const char * const barejid, const char * const name,
|
|||||||
|
|
||||||
if (p_contact_name(contact) == NULL) {
|
if (p_contact_name(contact) == NULL) {
|
||||||
if (name != NULL) {
|
if (name != NULL) {
|
||||||
autocomplete_add(ac, strdup(name));
|
autocomplete_add(handle_ac, strdup(name));
|
||||||
autocomplete_remove(ac, barejid);
|
autocomplete_remove(handle_ac, barejid);
|
||||||
g_hash_table_remove(handle_to_jid, barejid);
|
g_hash_table_remove(handle_to_jid, barejid);
|
||||||
g_hash_table_insert(handle_to_jid, strdup(name), strdup(barejid));
|
g_hash_table_insert(handle_to_jid, strdup(name), strdup(barejid));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (name != NULL) {
|
if (name != NULL) {
|
||||||
autocomplete_add(ac, strdup(name));
|
autocomplete_add(handle_ac, strdup(name));
|
||||||
autocomplete_remove(ac, p_contact_name(contact));
|
autocomplete_remove(handle_ac, p_contact_name(contact));
|
||||||
g_hash_table_remove(handle_to_jid, p_contact_name(contact));
|
g_hash_table_remove(handle_to_jid, p_contact_name(contact));
|
||||||
g_hash_table_insert(handle_to_jid, strdup(name), strdup(barejid));
|
g_hash_table_insert(handle_to_jid, strdup(name), strdup(barejid));
|
||||||
}
|
}
|
||||||
@ -357,7 +366,13 @@ roster_get_contacts(void)
|
|||||||
char *
|
char *
|
||||||
roster_find_contact(char *search_str)
|
roster_find_contact(char *search_str)
|
||||||
{
|
{
|
||||||
return autocomplete_complete(ac, search_str);
|
return autocomplete_complete(handle_ac, search_str);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
roster_find_jid(char *search_str)
|
||||||
|
{
|
||||||
|
return autocomplete_complete(jid_ac, search_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
|
@ -136,6 +136,7 @@ void roster_free(void);
|
|||||||
gboolean roster_has_pending_subscriptions(void);
|
gboolean roster_has_pending_subscriptions(void);
|
||||||
GSList * roster_get_contacts(void);
|
GSList * roster_get_contacts(void);
|
||||||
char * roster_find_contact(char *search_str);
|
char * roster_find_contact(char *search_str);
|
||||||
|
char * roster_find_jid(char *search_str);
|
||||||
char * roster_find_resource(char *search_str);
|
char * roster_find_resource(char *search_str);
|
||||||
gboolean roster_add(const char * const barejid, const char * const name,
|
gboolean roster_add(const char * const barejid, const char * const name,
|
||||||
const char * const subscription, const char * const offline_message,
|
const char * const subscription, const char * const offline_message,
|
||||||
|
Loading…
Reference in New Issue
Block a user