mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Pass offline filter to roster_get_contacts
This commit is contained in:
parent
b373cbcfc0
commit
4efe456e74
@ -1326,7 +1326,7 @@ _who_roster(ProfWin *window, const char *const command, gchar **args)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
list = roster_get_contacts(ROSTER_ORD_NAME);
|
list = roster_get_contacts(ROSTER_ORD_NAME, TRUE);
|
||||||
if (list == NULL) {
|
if (list == NULL) {
|
||||||
cons_show("No contacts in roster.");
|
cons_show("No contacts in roster.");
|
||||||
return;
|
return;
|
||||||
@ -1711,7 +1711,7 @@ cmd_roster(ProfWin *window, const char *const command, gchar **args)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
GSList *list = roster_get_contacts(ROSTER_ORD_NAME);
|
GSList *list = roster_get_contacts(ROSTER_ORD_NAME, TRUE);
|
||||||
cons_show_roster(list);
|
cons_show_roster(list);
|
||||||
g_slist_free(list);
|
g_slist_free(list);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -1931,7 +1931,7 @@ cmd_roster(ProfWin *window, const char *const command, gchar **args)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
GSList *all = roster_get_contacts(ROSTER_ORD_NAME);
|
GSList *all = roster_get_contacts(ROSTER_ORD_NAME, TRUE);
|
||||||
GSList *curr = all;
|
GSList *curr = all;
|
||||||
while (curr) {
|
while (curr) {
|
||||||
PContact contact = curr->data;
|
PContact contact = curr->data;
|
||||||
|
@ -865,7 +865,7 @@ _get_default_string(preference_t pref)
|
|||||||
case PREF_ROSTER_BY:
|
case PREF_ROSTER_BY:
|
||||||
return "presence";
|
return "presence";
|
||||||
case PREF_ROSTER_ORDER:
|
case PREF_ROSTER_ORDER:
|
||||||
return "name";
|
return "presence";
|
||||||
case PREF_TIME_CONSOLE:
|
case PREF_TIME_CONSOLE:
|
||||||
return "%H:%M:%S";
|
return "%H:%M:%S";
|
||||||
case PREF_TIME_CHAT:
|
case PREF_TIME_CHAT:
|
||||||
|
@ -383,7 +383,7 @@ roster_get_contacts_by_presence(const char *const presence)
|
|||||||
}
|
}
|
||||||
|
|
||||||
GSList*
|
GSList*
|
||||||
roster_get_contacts(roster_ord_t order)
|
roster_get_contacts(roster_ord_t order, gboolean include_offline)
|
||||||
{
|
{
|
||||||
GSList *result = NULL;
|
GSList *result = NULL;
|
||||||
GHashTableIter iter;
|
GHashTableIter iter;
|
||||||
@ -399,6 +399,12 @@ roster_get_contacts(roster_ord_t order)
|
|||||||
|
|
||||||
g_hash_table_iter_init(&iter, contacts);
|
g_hash_table_iter_init(&iter, contacts);
|
||||||
while (g_hash_table_iter_next(&iter, &key, &value)) {
|
while (g_hash_table_iter_next(&iter, &key, &value)) {
|
||||||
|
PContact contact = value;
|
||||||
|
const char *presence = p_contact_presence(contact);
|
||||||
|
if (!include_offline && (g_strcmp0(presence, "offline") == 0)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
result = g_slist_insert_sorted(result, value, cmp_func);
|
result = g_slist_insert_sorted(result, value, cmp_func);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ void roster_update(const char *const barejid, const char *const name, GSList *gr
|
|||||||
gboolean roster_add(const char *const barejid, const char *const name, GSList *groups, const char *const subscription,
|
gboolean roster_add(const char *const barejid, const char *const name, GSList *groups, const char *const subscription,
|
||||||
gboolean pending_out);
|
gboolean pending_out);
|
||||||
char* roster_barejid_from_name(const char *const name);
|
char* roster_barejid_from_name(const char *const name);
|
||||||
GSList* roster_get_contacts(roster_ord_t order);
|
GSList* roster_get_contacts(roster_ord_t order, gboolean include_offline);
|
||||||
GSList* roster_get_contacts_online(void);
|
GSList* roster_get_contacts_online(void);
|
||||||
gboolean roster_has_pending_subscriptions(void);
|
gboolean roster_has_pending_subscriptions(void);
|
||||||
char* roster_contact_autocomplete(const char *const search_str);
|
char* roster_contact_autocomplete(const char *const search_str);
|
||||||
|
@ -527,7 +527,7 @@ void
|
|||||||
cons_show_sent_subs(void)
|
cons_show_sent_subs(void)
|
||||||
{
|
{
|
||||||
if (roster_has_pending_subscriptions()) {
|
if (roster_has_pending_subscriptions()) {
|
||||||
GSList *contacts = roster_get_contacts(ROSTER_ORD_NAME);
|
GSList *contacts = roster_get_contacts(ROSTER_ORD_NAME, TRUE);
|
||||||
PContact contact = NULL;
|
PContact contact = NULL;
|
||||||
cons_show("Awaiting subscription responses from:");
|
cons_show("Awaiting subscription responses from:");
|
||||||
GSList *curr = contacts;
|
GSList *curr = contacts;
|
||||||
|
@ -115,22 +115,19 @@ _rosterwin_contact(ProfLayoutSplit *layout, PContact contact)
|
|||||||
const char *presence = p_contact_presence(contact);
|
const char *presence = p_contact_presence(contact);
|
||||||
const char *status = p_contact_status(contact);
|
const char *status = p_contact_status(contact);
|
||||||
|
|
||||||
if ((g_strcmp0(presence, "offline") != 0) || ((g_strcmp0(presence, "offline") == 0) &&
|
theme_item_t presence_colour = theme_main_presence_attrs(presence);
|
||||||
(prefs_get_boolean(PREF_ROSTER_OFFLINE)))) {
|
|
||||||
theme_item_t presence_colour = theme_main_presence_attrs(presence);
|
|
||||||
|
|
||||||
wattron(layout->subwin, theme_attrs(presence_colour));
|
wattron(layout->subwin, theme_attrs(presence_colour));
|
||||||
GString *msg = g_string_new(" ");
|
GString *msg = g_string_new(" ");
|
||||||
g_string_append(msg, name);
|
g_string_append(msg, name);
|
||||||
win_printline_nowrap(layout->subwin, msg->str);
|
win_printline_nowrap(layout->subwin, msg->str);
|
||||||
g_string_free(msg, TRUE);
|
g_string_free(msg, TRUE);
|
||||||
wattroff(layout->subwin, theme_attrs(presence_colour));
|
wattroff(layout->subwin, theme_attrs(presence_colour));
|
||||||
|
|
||||||
if (prefs_get_boolean(PREF_ROSTER_RESOURCE)) {
|
if (prefs_get_boolean(PREF_ROSTER_RESOURCE)) {
|
||||||
_rosterwin_resource(layout, contact);
|
_rosterwin_resource(layout, contact);
|
||||||
} else if (prefs_get_boolean(PREF_ROSTER_PRESENCE)) {
|
} else if (prefs_get_boolean(PREF_ROSTER_PRESENCE)) {
|
||||||
_rosterwin_presence(layout, 4, presence_colour, presence, status);
|
_rosterwin_presence(layout, 4, presence_colour, presence, status);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,7 +167,7 @@ _rosterwin_contacts_by_group(ProfLayoutSplit *layout, char *group)
|
|||||||
contacts = roster_get_group(group, ROSTER_ORD_NAME, offline);
|
contacts = roster_get_group(group, ROSTER_ORD_NAME, offline);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (contacts) {
|
if (contacts || prefs_get_boolean(PREF_ROSTER_EMPTY)) {
|
||||||
wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
|
wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
|
||||||
GString *title = g_string_new(" -");
|
GString *title = g_string_new(" -");
|
||||||
g_string_append(title, group);
|
g_string_append(title, group);
|
||||||
@ -201,7 +198,7 @@ _rosterwin_contacts_by_no_group(ProfLayoutSplit *layout)
|
|||||||
contacts = roster_get_nogroup(ROSTER_ORD_NAME, offline);
|
contacts = roster_get_nogroup(ROSTER_ORD_NAME, offline);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (contacts) {
|
if (contacts || prefs_get_boolean(PREF_ROSTER_EMPTY)) {
|
||||||
wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
|
wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
|
||||||
win_printline_nowrap(layout->subwin, " -no group");
|
win_printline_nowrap(layout->subwin, " -no group");
|
||||||
wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
|
wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
|
||||||
@ -249,19 +246,20 @@ rosterwin_roster(void)
|
|||||||
GSList *contacts = NULL;
|
GSList *contacts = NULL;
|
||||||
|
|
||||||
char *order = prefs_get_string(PREF_ROSTER_ORDER);
|
char *order = prefs_get_string(PREF_ROSTER_ORDER);
|
||||||
|
gboolean offline = prefs_get_boolean(PREF_ROSTER_OFFLINE);
|
||||||
if (g_strcmp0(order, "presence") == 0) {
|
if (g_strcmp0(order, "presence") == 0) {
|
||||||
contacts = roster_get_contacts(ROSTER_ORD_PRESENCE);
|
contacts = roster_get_contacts(ROSTER_ORD_PRESENCE, offline);
|
||||||
} else {
|
} else {
|
||||||
contacts = roster_get_contacts(ROSTER_ORD_NAME);
|
contacts = roster_get_contacts(ROSTER_ORD_NAME, offline);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
werase(layout->subwin);
|
||||||
|
|
||||||
|
wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
|
||||||
|
win_printline_nowrap(layout->subwin, " -Roster");
|
||||||
|
wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
|
||||||
|
|
||||||
if (contacts) {
|
if (contacts) {
|
||||||
werase(layout->subwin);
|
|
||||||
|
|
||||||
wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
|
|
||||||
win_printline_nowrap(layout->subwin, " -Roster");
|
|
||||||
wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
|
|
||||||
|
|
||||||
GSList *curr_contact = contacts;
|
GSList *curr_contact = contacts;
|
||||||
while (curr_contact) {
|
while (curr_contact) {
|
||||||
PContact contact = curr_contact->data;
|
PContact contact = curr_contact->data;
|
||||||
|
@ -55,7 +55,7 @@ void cmd_roster_shows_roster_when_no_args(void **state)
|
|||||||
|
|
||||||
roster_init();
|
roster_init();
|
||||||
roster_add("bob@server.org", "bob", NULL, "both", FALSE);
|
roster_add("bob@server.org", "bob", NULL, "both", FALSE);
|
||||||
GSList *roster = roster_get_contacts(ROSTER_ORD_NAME);
|
GSList *roster = roster_get_contacts(ROSTER_ORD_NAME, TRUE);
|
||||||
|
|
||||||
expect_memory(cons_show_roster, list, roster, sizeof(roster));
|
expect_memory(cons_show_roster, list, roster, sizeof(roster));
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
void empty_list_when_none_added(void **state)
|
void empty_list_when_none_added(void **state)
|
||||||
{
|
{
|
||||||
roster_init();
|
roster_init();
|
||||||
GSList *list = roster_get_contacts(ROSTER_ORD_NAME);
|
GSList *list = roster_get_contacts(ROSTER_ORD_NAME, TRUE);
|
||||||
assert_null(list);
|
assert_null(list);
|
||||||
roster_clear();
|
roster_clear();
|
||||||
roster_free();
|
roster_free();
|
||||||
@ -22,7 +22,7 @@ void contains_one_element(void **state)
|
|||||||
{
|
{
|
||||||
roster_init();
|
roster_init();
|
||||||
roster_add("James", NULL, NULL, NULL, FALSE);
|
roster_add("James", NULL, NULL, NULL, FALSE);
|
||||||
GSList *list = roster_get_contacts(ROSTER_ORD_NAME);
|
GSList *list = roster_get_contacts(ROSTER_ORD_NAME, TRUE);
|
||||||
assert_int_equal(1, g_slist_length(list));
|
assert_int_equal(1, g_slist_length(list));
|
||||||
roster_clear();
|
roster_clear();
|
||||||
roster_free();
|
roster_free();
|
||||||
@ -32,7 +32,7 @@ void first_element_correct(void **state)
|
|||||||
{
|
{
|
||||||
roster_init();
|
roster_init();
|
||||||
roster_add("James", NULL, NULL, NULL, FALSE);
|
roster_add("James", NULL, NULL, NULL, FALSE);
|
||||||
GSList *list = roster_get_contacts(ROSTER_ORD_NAME);
|
GSList *list = roster_get_contacts(ROSTER_ORD_NAME, TRUE);
|
||||||
PContact james = list->data;
|
PContact james = list->data;
|
||||||
|
|
||||||
assert_string_equal("James", p_contact_barejid(james));
|
assert_string_equal("James", p_contact_barejid(james));
|
||||||
@ -45,7 +45,7 @@ void contains_two_elements(void **state)
|
|||||||
roster_init();
|
roster_init();
|
||||||
roster_add("James", NULL, NULL, NULL, FALSE);
|
roster_add("James", NULL, NULL, NULL, FALSE);
|
||||||
roster_add("Dave", NULL, NULL, NULL, FALSE);
|
roster_add("Dave", NULL, NULL, NULL, FALSE);
|
||||||
GSList *list = roster_get_contacts(ROSTER_ORD_NAME);
|
GSList *list = roster_get_contacts(ROSTER_ORD_NAME, TRUE);
|
||||||
|
|
||||||
assert_int_equal(2, g_slist_length(list));
|
assert_int_equal(2, g_slist_length(list));
|
||||||
roster_clear();
|
roster_clear();
|
||||||
@ -57,7 +57,7 @@ void first_and_second_elements_correct(void **state)
|
|||||||
roster_init();
|
roster_init();
|
||||||
roster_add("James", NULL, NULL, NULL, FALSE);
|
roster_add("James", NULL, NULL, NULL, FALSE);
|
||||||
roster_add("Dave", NULL, NULL, NULL, FALSE);
|
roster_add("Dave", NULL, NULL, NULL, FALSE);
|
||||||
GSList *list = roster_get_contacts(ROSTER_ORD_NAME);
|
GSList *list = roster_get_contacts(ROSTER_ORD_NAME, TRUE);
|
||||||
|
|
||||||
PContact first = list->data;
|
PContact first = list->data;
|
||||||
PContact second = (g_slist_next(list))->data;
|
PContact second = (g_slist_next(list))->data;
|
||||||
@ -74,7 +74,7 @@ void contains_three_elements(void **state)
|
|||||||
roster_add("James", NULL, NULL, NULL, FALSE);
|
roster_add("James", NULL, NULL, NULL, FALSE);
|
||||||
roster_add("Bob", NULL, NULL, NULL, FALSE);
|
roster_add("Bob", NULL, NULL, NULL, FALSE);
|
||||||
roster_add("Dave", NULL, NULL, NULL, FALSE);
|
roster_add("Dave", NULL, NULL, NULL, FALSE);
|
||||||
GSList *list = roster_get_contacts(ROSTER_ORD_NAME);
|
GSList *list = roster_get_contacts(ROSTER_ORD_NAME, TRUE);
|
||||||
|
|
||||||
assert_int_equal(3, g_slist_length(list));
|
assert_int_equal(3, g_slist_length(list));
|
||||||
roster_clear();
|
roster_clear();
|
||||||
@ -87,7 +87,7 @@ void first_three_elements_correct(void **state)
|
|||||||
roster_add("Bob", NULL, NULL, NULL, FALSE);
|
roster_add("Bob", NULL, NULL, NULL, FALSE);
|
||||||
roster_add("Dave", NULL, NULL, NULL, FALSE);
|
roster_add("Dave", NULL, NULL, NULL, FALSE);
|
||||||
roster_add("James", NULL, NULL, NULL, FALSE);
|
roster_add("James", NULL, NULL, NULL, FALSE);
|
||||||
GSList *list = roster_get_contacts(ROSTER_ORD_NAME);
|
GSList *list = roster_get_contacts(ROSTER_ORD_NAME, TRUE);
|
||||||
PContact bob = list->data;
|
PContact bob = list->data;
|
||||||
PContact dave = (g_slist_next(list))->data;
|
PContact dave = (g_slist_next(list))->data;
|
||||||
PContact james = (g_slist_next(g_slist_next(list)))->data;
|
PContact james = (g_slist_next(g_slist_next(list)))->data;
|
||||||
@ -106,7 +106,7 @@ void add_twice_at_beginning_adds_once(void **state)
|
|||||||
roster_add("James", NULL, NULL, NULL, FALSE);
|
roster_add("James", NULL, NULL, NULL, FALSE);
|
||||||
roster_add("Dave", NULL, NULL, NULL, FALSE);
|
roster_add("Dave", NULL, NULL, NULL, FALSE);
|
||||||
roster_add("Bob", NULL, NULL, NULL, FALSE);
|
roster_add("Bob", NULL, NULL, NULL, FALSE);
|
||||||
GSList *list = roster_get_contacts(ROSTER_ORD_NAME);
|
GSList *list = roster_get_contacts(ROSTER_ORD_NAME, TRUE);
|
||||||
PContact first = list->data;
|
PContact first = list->data;
|
||||||
PContact second = (g_slist_next(list))->data;
|
PContact second = (g_slist_next(list))->data;
|
||||||
PContact third = (g_slist_next(g_slist_next(list)))->data;
|
PContact third = (g_slist_next(g_slist_next(list)))->data;
|
||||||
@ -126,7 +126,7 @@ void add_twice_in_middle_adds_once(void **state)
|
|||||||
roster_add("Dave", NULL, NULL, NULL, FALSE);
|
roster_add("Dave", NULL, NULL, NULL, FALSE);
|
||||||
roster_add("James", NULL, NULL, NULL, FALSE);
|
roster_add("James", NULL, NULL, NULL, FALSE);
|
||||||
roster_add("Bob", NULL, NULL, NULL, FALSE);
|
roster_add("Bob", NULL, NULL, NULL, FALSE);
|
||||||
GSList *list = roster_get_contacts(ROSTER_ORD_NAME);
|
GSList *list = roster_get_contacts(ROSTER_ORD_NAME, TRUE);
|
||||||
PContact first = list->data;
|
PContact first = list->data;
|
||||||
PContact second = (g_slist_next(list))->data;
|
PContact second = (g_slist_next(list))->data;
|
||||||
PContact third = (g_slist_next(g_slist_next(list)))->data;
|
PContact third = (g_slist_next(g_slist_next(list)))->data;
|
||||||
@ -146,7 +146,7 @@ void add_twice_at_end_adds_once(void **state)
|
|||||||
roster_add("Dave", NULL, NULL, NULL, FALSE);
|
roster_add("Dave", NULL, NULL, NULL, FALSE);
|
||||||
roster_add("Bob", NULL, NULL, NULL, FALSE);
|
roster_add("Bob", NULL, NULL, NULL, FALSE);
|
||||||
roster_add("James", NULL, NULL, NULL, FALSE);
|
roster_add("James", NULL, NULL, NULL, FALSE);
|
||||||
GSList *list = roster_get_contacts(ROSTER_ORD_NAME);
|
GSList *list = roster_get_contacts(ROSTER_ORD_NAME, TRUE);
|
||||||
PContact first = list->data;
|
PContact first = list->data;
|
||||||
PContact second = (g_slist_next(list))->data;
|
PContact second = (g_slist_next(list))->data;
|
||||||
PContact third = (g_slist_next(g_slist_next(list)))->data;
|
PContact third = (g_slist_next(g_slist_next(list)))->data;
|
||||||
|
Loading…
Reference in New Issue
Block a user