mirror of
https://github.com/profanity-im/profanity.git
synced 2025-02-02 15:08:15 -05:00
Removed hash_table_iter usage for room roster
This commit is contained in:
parent
7a03dd7641
commit
74a2d4601f
3
TODO_045
3
TODO_045
@ -1,6 +1,3 @@
|
|||||||
Test with valgrind using new commands
|
|
||||||
fix muc roster leak
|
|
||||||
|
|
||||||
Update website help
|
Update website help
|
||||||
|
|
||||||
Tag libstrophe release 0.8.7
|
Tag libstrophe release 0.8.7
|
||||||
|
@ -769,22 +769,22 @@ _who_room(gchar **args, struct cmd_help_t help)
|
|||||||
(g_strcmp0(args[0], "any") == 0)) {
|
(g_strcmp0(args[0], "any") == 0)) {
|
||||||
|
|
||||||
char *presence = args[0];
|
char *presence = args[0];
|
||||||
GList *list = muc_roster(room);
|
GList *occupants = muc_roster(room);
|
||||||
|
|
||||||
// no arg, show all contacts
|
// no arg, show all contacts
|
||||||
if ((presence == NULL) || (g_strcmp0(presence, "any") == 0)) {
|
if ((presence == NULL) || (g_strcmp0(presence, "any") == 0)) {
|
||||||
ui_room_roster(room, list, NULL);
|
ui_room_roster(room, occupants, NULL);
|
||||||
|
|
||||||
// available
|
// available
|
||||||
} else if (strcmp("available", presence) == 0) {
|
} else if (strcmp("available", presence) == 0) {
|
||||||
GList *filtered = NULL;
|
GList *filtered = NULL;
|
||||||
|
|
||||||
while (list != NULL) {
|
while (occupants != NULL) {
|
||||||
Occupant *occupant = list->data;
|
Occupant *occupant = occupants->data;
|
||||||
if (muc_occupant_available(occupant)) {
|
if (muc_occupant_available(occupant)) {
|
||||||
filtered = g_list_append(filtered, occupant);
|
filtered = g_list_append(filtered, occupant);
|
||||||
}
|
}
|
||||||
list = g_list_next(list);
|
occupants = g_list_next(occupants);
|
||||||
}
|
}
|
||||||
|
|
||||||
ui_room_roster(room, filtered, "available");
|
ui_room_roster(room, filtered, "available");
|
||||||
@ -793,12 +793,12 @@ _who_room(gchar **args, struct cmd_help_t help)
|
|||||||
} else if (strcmp("unavailable", presence) == 0) {
|
} else if (strcmp("unavailable", presence) == 0) {
|
||||||
GList *filtered = NULL;
|
GList *filtered = NULL;
|
||||||
|
|
||||||
while (list != NULL) {
|
while (occupants != NULL) {
|
||||||
Occupant *occupant = list->data;
|
Occupant *occupant = occupants->data;
|
||||||
if (!muc_occupant_available(occupant)) {
|
if (!muc_occupant_available(occupant)) {
|
||||||
filtered = g_list_append(filtered, occupant);
|
filtered = g_list_append(filtered, occupant);
|
||||||
}
|
}
|
||||||
list = g_list_next(list);
|
occupants = g_list_next(occupants);
|
||||||
}
|
}
|
||||||
|
|
||||||
ui_room_roster(room, filtered, "unavailable");
|
ui_room_roster(room, filtered, "unavailable");
|
||||||
@ -807,18 +807,20 @@ _who_room(gchar **args, struct cmd_help_t help)
|
|||||||
} else {
|
} else {
|
||||||
GList *filtered = NULL;
|
GList *filtered = NULL;
|
||||||
|
|
||||||
while (list != NULL) {
|
while (occupants != NULL) {
|
||||||
Occupant *occupant = list->data;
|
Occupant *occupant = occupants->data;
|
||||||
const char *presence_str = string_from_resource_presence(occupant->presence);
|
const char *presence_str = string_from_resource_presence(occupant->presence);
|
||||||
if (strcmp(presence_str, presence) == 0) {
|
if (strcmp(presence_str, presence) == 0) {
|
||||||
filtered = g_list_append(filtered, occupant);
|
filtered = g_list_append(filtered, occupant);
|
||||||
}
|
}
|
||||||
list = g_list_next(list);
|
occupants = g_list_next(occupants);
|
||||||
}
|
}
|
||||||
|
|
||||||
ui_room_roster(room, filtered, presence);
|
ui_room_roster(room, filtered, presence);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_list_free(occupants);
|
||||||
|
|
||||||
// role or affiliation filter
|
// role or affiliation filter
|
||||||
} else {
|
} else {
|
||||||
ProfWin *window = wins_get_by_recipient(room);
|
ProfWin *window = wins_get_by_recipient(room);
|
||||||
|
14
src/muc.c
14
src/muc.c
@ -454,7 +454,6 @@ muc_roster_item(const char * const room, const char * const nick)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Return a list of PContacts representing the room members in the room's roster
|
* Return a list of PContacts representing the room members in the room's roster
|
||||||
* The list is owned by the room and must not be mofified or freed
|
|
||||||
*/
|
*/
|
||||||
GList *
|
GList *
|
||||||
muc_roster(const char * const room)
|
muc_roster(const char * const room)
|
||||||
@ -462,15 +461,16 @@ muc_roster(const char * const room)
|
|||||||
ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
|
ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
|
||||||
if (chat_room) {
|
if (chat_room) {
|
||||||
GList *result = NULL;
|
GList *result = NULL;
|
||||||
GHashTableIter iter;
|
GList *occupants = g_hash_table_get_values(chat_room->roster);
|
||||||
gpointer key;
|
|
||||||
gpointer value;
|
|
||||||
|
|
||||||
g_hash_table_iter_init(&iter, chat_room->roster);
|
GList *curr = occupants;
|
||||||
while (g_hash_table_iter_next(&iter, &key, &value)) {
|
while (curr) {
|
||||||
result = g_list_insert_sorted(result, value, (GCompareFunc)_compare_occupants);
|
result = g_list_insert_sorted(result, curr->data, (GCompareFunc)_compare_occupants);
|
||||||
|
curr = g_list_next(curr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_list_free(occupants);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -681,8 +681,9 @@ handle_muc_self_online(const char * const room, const char * const nick, gboolea
|
|||||||
|
|
||||||
// show roster if occupants list disabled by default
|
// show roster if occupants list disabled by default
|
||||||
if (!prefs_get_boolean(PREF_OCCUPANTS)) {
|
if (!prefs_get_boolean(PREF_OCCUPANTS)) {
|
||||||
GList *roster = muc_roster(room);
|
GList *occupants = muc_roster(room);
|
||||||
ui_room_roster(room, roster, NULL);
|
ui_room_roster(room, occupants, NULL);
|
||||||
|
g_list_free(occupants);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *subject = muc_subject(room);
|
char *subject = muc_subject(room);
|
||||||
|
@ -2816,15 +2816,15 @@ _ui_muc_roster(const char * const room)
|
|||||||
{
|
{
|
||||||
ProfWin *window = wins_get_by_recipient(room);
|
ProfWin *window = wins_get_by_recipient(room);
|
||||||
if (window) {
|
if (window) {
|
||||||
GList *roster = muc_roster(room);
|
GList *occupants = muc_roster(room);
|
||||||
if (roster) {
|
if (occupants) {
|
||||||
werase(window->subwin);
|
werase(window->subwin);
|
||||||
|
|
||||||
if (prefs_get_boolean(PREF_MUC_PRIVILEGES)) {
|
if (prefs_get_boolean(PREF_MUC_PRIVILEGES)) {
|
||||||
wattron(window->subwin, COLOUR_ROOMINFO);
|
wattron(window->subwin, COLOUR_ROOMINFO);
|
||||||
wprintw(window->subwin, " -Moderators\n");
|
wprintw(window->subwin, " -Moderators\n");
|
||||||
wattroff(window->subwin, COLOUR_ROOMINFO);
|
wattroff(window->subwin, COLOUR_ROOMINFO);
|
||||||
GList *roster_curr = roster;
|
GList *roster_curr = occupants;
|
||||||
while (roster_curr) {
|
while (roster_curr) {
|
||||||
Occupant *occupant = roster_curr->data;
|
Occupant *occupant = roster_curr->data;
|
||||||
if (occupant->role == MUC_ROLE_MODERATOR) {
|
if (occupant->role == MUC_ROLE_MODERATOR) {
|
||||||
@ -2842,7 +2842,7 @@ _ui_muc_roster(const char * const room)
|
|||||||
wattron(window->subwin, COLOUR_ROOMINFO);
|
wattron(window->subwin, COLOUR_ROOMINFO);
|
||||||
wprintw(window->subwin, " -Participants\n");
|
wprintw(window->subwin, " -Participants\n");
|
||||||
wattroff(window->subwin, COLOUR_ROOMINFO);
|
wattroff(window->subwin, COLOUR_ROOMINFO);
|
||||||
roster_curr = roster;
|
roster_curr = occupants;
|
||||||
while (roster_curr) {
|
while (roster_curr) {
|
||||||
Occupant *occupant = roster_curr->data;
|
Occupant *occupant = roster_curr->data;
|
||||||
if (occupant->role == MUC_ROLE_PARTICIPANT) {
|
if (occupant->role == MUC_ROLE_PARTICIPANT) {
|
||||||
@ -2860,7 +2860,7 @@ _ui_muc_roster(const char * const room)
|
|||||||
wattron(window->subwin, COLOUR_ROOMINFO);
|
wattron(window->subwin, COLOUR_ROOMINFO);
|
||||||
wprintw(window->subwin, " -Visitors\n");
|
wprintw(window->subwin, " -Visitors\n");
|
||||||
wattroff(window->subwin, COLOUR_ROOMINFO);
|
wattroff(window->subwin, COLOUR_ROOMINFO);
|
||||||
roster_curr = roster;
|
roster_curr = occupants;
|
||||||
while (roster_curr) {
|
while (roster_curr) {
|
||||||
Occupant *occupant = roster_curr->data;
|
Occupant *occupant = roster_curr->data;
|
||||||
if (occupant->role == MUC_ROLE_VISITOR) {
|
if (occupant->role == MUC_ROLE_VISITOR) {
|
||||||
@ -2878,7 +2878,7 @@ _ui_muc_roster(const char * const room)
|
|||||||
wattron(window->subwin, COLOUR_ROOMINFO);
|
wattron(window->subwin, COLOUR_ROOMINFO);
|
||||||
wprintw(window->subwin, " -Occupants\n");
|
wprintw(window->subwin, " -Occupants\n");
|
||||||
wattroff(window->subwin, COLOUR_ROOMINFO);
|
wattroff(window->subwin, COLOUR_ROOMINFO);
|
||||||
GList *roster_curr = roster;
|
GList *roster_curr = occupants;
|
||||||
while (roster_curr) {
|
while (roster_curr) {
|
||||||
Occupant *occupant = roster_curr->data;
|
Occupant *occupant = roster_curr->data;
|
||||||
wprintw(window->subwin, " ");
|
wprintw(window->subwin, " ");
|
||||||
@ -2892,6 +2892,8 @@ _ui_muc_roster(const char * const room)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_list_free(occupants);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ void (*ui_room_occupant_affiliation_change)(const char * const room, const char
|
|||||||
const char * const actor, const char * const reason);
|
const char * const actor, const char * const reason);
|
||||||
void (*ui_room_occupant_role_and_affiliation_change)(const char * const room, const char * const nick, const char * const role,
|
void (*ui_room_occupant_role_and_affiliation_change)(const char * const room, const char * const nick, const char * const role,
|
||||||
const char * const affiliation, const char * const actor, const char * const reason);
|
const char * const affiliation, const char * const actor, const char * const reason);
|
||||||
void (*ui_room_roster)(const char * const room, GList *roster, const char * const presence);
|
void (*ui_room_roster)(const char * const room, GList *occupants, const char * const presence);
|
||||||
void (*ui_room_history)(const char * const room_jid, const char * const nick,
|
void (*ui_room_history)(const char * const room_jid, const char * const nick,
|
||||||
GTimeVal tv_stamp, const char * const message);
|
GTimeVal tv_stamp, const char * const message);
|
||||||
void (*ui_room_message)(const char * const room_jid, const char * const nick,
|
void (*ui_room_message)(const char * const room_jid, const char * const nick,
|
||||||
|
Loading…
Reference in New Issue
Block a user