mirror of
https://github.com/profanity-im/profanity.git
synced 2024-09-01 19:24:15 -04:00
Make _get_groups_from_item and roster _compare_* public
In order to avoid duplication with xep 0133 support in command execution
This commit is contained in:
parent
01428eb858
commit
2e0bc27bf0
@ -1191,17 +1191,7 @@ _command_exec_response_handler(xmpp_stanza_t *const stanza, void *const userdata
|
||||
const char *ask = xmpp_stanza_get_attribute(child, STANZA_ATTR_ASK);
|
||||
|
||||
GSList *groups = NULL;
|
||||
xmpp_stanza_t *group_element = xmpp_stanza_get_children(child);
|
||||
|
||||
while (group_element) {
|
||||
if (strcmp(xmpp_stanza_get_name(group_element), STANZA_NAME_GROUP) == 0) {
|
||||
char *groupname = xmpp_stanza_get_text(group_element);
|
||||
if (groupname) {
|
||||
groups = g_slist_append(groups, groupname);
|
||||
}
|
||||
}
|
||||
group_element = xmpp_stanza_get_next(group_element);
|
||||
}
|
||||
groups = roster_get_groups_from_item(child);
|
||||
|
||||
gboolean pending_out = FALSE;
|
||||
if (ask && (strcmp(ask, "subscribe") == 0)) {
|
||||
@ -1209,7 +1199,7 @@ _command_exec_response_handler(xmpp_stanza_t *const stanza, void *const userdata
|
||||
}
|
||||
|
||||
PContact contact = p_contact_new(barejid_lower, name, groups, sub, NULL, pending_out);
|
||||
list = g_slist_append(list, contact);
|
||||
list = g_slist_insert_sorted(list, contact, (GCompareFunc)roster_compare_name);
|
||||
child = xmpp_stanza_get_next(child);
|
||||
}
|
||||
|
||||
|
@ -75,9 +75,6 @@ static int _group_add_id_handler(xmpp_stanza_t *const stanza, void *const userda
|
||||
static int _group_remove_id_handler(xmpp_stanza_t *const stanza, void *const userdata);
|
||||
static void _free_group_data(GroupData *data);
|
||||
|
||||
// helper functions
|
||||
GSList* _get_groups_from_item(xmpp_stanza_t *item);
|
||||
|
||||
void
|
||||
roster_request(void)
|
||||
{
|
||||
@ -254,7 +251,7 @@ roster_set_handler(xmpp_stanza_t *const stanza)
|
||||
pending_out = TRUE;
|
||||
}
|
||||
|
||||
GSList *groups = _get_groups_from_item(item);
|
||||
GSList *groups = roster_get_groups_from_item(item);
|
||||
|
||||
// update the local roster
|
||||
PContact contact = roster_get_contact(barejid_lower);
|
||||
@ -301,7 +298,7 @@ roster_result_handler(xmpp_stanza_t *const stanza)
|
||||
pending_out = TRUE;
|
||||
}
|
||||
|
||||
GSList *groups = _get_groups_from_item(item);
|
||||
GSList *groups = roster_get_groups_from_item(item);
|
||||
|
||||
gboolean added = roster_add(barejid_lower, name, groups, sub, pending_out);
|
||||
if (!added) {
|
||||
@ -318,7 +315,7 @@ roster_result_handler(xmpp_stanza_t *const stanza)
|
||||
}
|
||||
|
||||
GSList*
|
||||
_get_groups_from_item(xmpp_stanza_t *item)
|
||||
roster_get_groups_from_item(xmpp_stanza_t *item)
|
||||
{
|
||||
GSList *groups = NULL;
|
||||
xmpp_stanza_t *group_element = xmpp_stanza_get_children(item);
|
||||
|
@ -38,5 +38,6 @@
|
||||
void roster_request(void);
|
||||
void roster_set_handler(xmpp_stanza_t *const stanza);
|
||||
void roster_result_handler(xmpp_stanza_t *const stanza);
|
||||
GSList* roster_get_groups_from_item(xmpp_stanza_t *const item);
|
||||
|
||||
#endif
|
||||
|
@ -73,8 +73,6 @@ static gboolean _key_equals(void *key1, void *key2);
|
||||
static gboolean _datetimes_equal(GDateTime *dt1, GDateTime *dt2);
|
||||
static void _replace_name(const char *const current_name, const char *const new_name, const char *const barejid);
|
||||
static void _add_name_and_barejid(const char *const name, const char *const barejid);
|
||||
static gint _compare_name(PContact a, PContact b);
|
||||
static gint _compare_presence(PContact a, PContact b);
|
||||
|
||||
void
|
||||
roster_create(void)
|
||||
@ -397,7 +395,7 @@ roster_get_contacts_by_presence(const char *const presence)
|
||||
while (g_hash_table_iter_next(&iter, &key, &value)) {
|
||||
PContact contact = (PContact)value;
|
||||
if (g_strcmp0(p_contact_presence(contact), presence) == 0) {
|
||||
result = g_slist_insert_sorted(result, value, (GCompareFunc)_compare_name);
|
||||
result = g_slist_insert_sorted(result, value, (GCompareFunc)roster_compare_name);
|
||||
}
|
||||
}
|
||||
|
||||
@ -417,9 +415,9 @@ roster_get_contacts(roster_ord_t order)
|
||||
|
||||
GCompareFunc cmp_func;
|
||||
if (order == ROSTER_ORD_PRESENCE) {
|
||||
cmp_func = (GCompareFunc) _compare_presence;
|
||||
cmp_func = (GCompareFunc) roster_compare_presence;
|
||||
} else {
|
||||
cmp_func = (GCompareFunc) _compare_name;
|
||||
cmp_func = (GCompareFunc) roster_compare_name;
|
||||
}
|
||||
|
||||
g_hash_table_iter_init(&iter, roster->contacts);
|
||||
@ -444,7 +442,7 @@ roster_get_contacts_online(void)
|
||||
g_hash_table_iter_init(&iter, roster->contacts);
|
||||
while (g_hash_table_iter_next(&iter, &key, &value)) {
|
||||
if(strcmp(p_contact_presence(value), "offline"))
|
||||
result = g_slist_insert_sorted(result, value, (GCompareFunc)_compare_name);
|
||||
result = g_slist_insert_sorted(result, value, (GCompareFunc)roster_compare_name);
|
||||
}
|
||||
|
||||
// return all contact structs
|
||||
@ -499,9 +497,9 @@ roster_get_group(const char *const group, roster_ord_t order)
|
||||
|
||||
GCompareFunc cmp_func;
|
||||
if (order == ROSTER_ORD_PRESENCE) {
|
||||
cmp_func = (GCompareFunc) _compare_presence;
|
||||
cmp_func = (GCompareFunc) roster_compare_presence;
|
||||
} else {
|
||||
cmp_func = (GCompareFunc) _compare_name;
|
||||
cmp_func = (GCompareFunc) roster_compare_name;
|
||||
}
|
||||
|
||||
g_hash_table_iter_init(&iter, roster->contacts);
|
||||
@ -605,8 +603,8 @@ _add_name_and_barejid(const char *const name, const char *const barejid)
|
||||
}
|
||||
}
|
||||
|
||||
static gint
|
||||
_compare_name(PContact a, PContact b)
|
||||
gint
|
||||
roster_compare_name(PContact a, PContact b)
|
||||
{
|
||||
const char * utf8_str_a = NULL;
|
||||
const char * utf8_str_b = NULL;
|
||||
@ -645,8 +643,8 @@ _get_presence_weight(const char *presence)
|
||||
}
|
||||
}
|
||||
|
||||
static gint
|
||||
_compare_presence(PContact a, PContact b)
|
||||
gint
|
||||
roster_compare_presence(PContact a, PContact b)
|
||||
{
|
||||
const char *presence_a = p_contact_presence(a);
|
||||
const char *presence_b = p_contact_presence(b);
|
||||
@ -663,6 +661,6 @@ _compare_presence(PContact a, PContact b)
|
||||
|
||||
// otherwise order by name
|
||||
} else {
|
||||
return _compare_name(a, b);
|
||||
return roster_compare_name(a, b);
|
||||
}
|
||||
}
|
||||
|
@ -70,5 +70,7 @@ char* roster_group_autocomplete(const char *const search_str, gboolean previous)
|
||||
char* roster_barejid_autocomplete(const char *const search_str, gboolean previous);
|
||||
GSList* roster_get_contacts_by_presence(const char *const presence);
|
||||
char* roster_get_msg_display_name(const char *const barejid, const char *const resource);
|
||||
gint roster_compare_name(PContact a, PContact b);
|
||||
gint roster_compare_presence(PContact a, PContact b);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user