1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-06-23 21:45:30 +00:00
profanity/src/ui/rosterwin.c

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

1245 lines
44 KiB
C
Raw Normal View History

2014-12-16 22:14:15 +00:00
/*
* rosterwin.c
2019-11-13 11:11:05 +00:00
* vim: expandtab:ts=4:sts=4:sw=4
2014-12-16 22:14:15 +00:00
*
2019-01-22 10:31:45 +00:00
* Copyright (C) 2012 - 2019 James Booth <boothj5@gmail.com>
2023-01-10 09:37:25 +00:00
* Copyright (C) 2019 - 2023 Michael Vetter <jubalh@iodoru.org>
2014-12-16 22:14:15 +00:00
*
* This file is part of Profanity.
*
* Profanity is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Profanity is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2016-07-24 00:14:49 +00:00
* along with Profanity. If not, see <https://www.gnu.org/licenses/>.
2014-12-16 22:14:15 +00:00
*
* In addition, as a special exception, the copyright holders give permission to
* link the code of portions of this program with the OpenSSL library under
* certain conditions as described in each individual source file, and
* distribute linked combinations including the two.
*
* You must obey the GNU General Public License in all respects for all of the
* code used other than OpenSSL. If you modify file(s) with this exception, you
* may extend this exception to your version of the file(s), but you are not
* obligated to do so. If you do not wish to do so, delete this exception
* statement from your version. If you delete this exception statement from all
* source files in the program, then also delete it here.
*
*/
#include "config.h"
2014-12-16 22:14:15 +00:00
#include <assert.h>
2014-12-16 23:00:05 +00:00
#include <stdlib.h>
2016-01-25 22:54:34 +00:00
#include <string.h>
2014-12-16 22:14:15 +00:00
2016-07-24 14:43:51 +00:00
#include "config/preferences.h"
2014-12-16 23:00:05 +00:00
#include "ui/ui.h"
2014-12-16 22:14:15 +00:00
#include "ui/window.h"
2016-07-24 14:43:51 +00:00
#include "ui/window_list.h"
2016-07-24 14:08:47 +00:00
#include "xmpp/roster_list.h"
#include "xmpp/contact.h"
2014-12-16 22:14:15 +00:00
2016-01-14 22:54:50 +00:00
typedef enum {
ROSTER_CONTACT,
ROSTER_CONTACT_ACTIVE,
ROSTER_CONTACT_UNREAD
} roster_contact_theme_t;
2020-07-07 12:18:57 +00:00
static void _rosterwin_contacts_all(ProfLayoutSplit* layout);
static void _rosterwin_contacts_by_presence(ProfLayoutSplit* layout, const char* const presence, char* title);
static void _rosterwin_contacts_by_group(ProfLayoutSplit* layout, char* group);
static void _rosteriwin_unsubscribed(ProfLayoutSplit* layout);
static void _rosterwin_contacts_header(ProfLayoutSplit* layout, const char* title, GSList* contacts);
static void _rosterwin_unsubscribed_header(ProfLayoutSplit* layout, GList* wins);
static void _rosterwin_contact(ProfLayoutSplit* layout, PContact contact);
static void _rosterwin_unsubscribed_item(ProfLayoutSplit* layout, ProfChatWin* chatwin);
static void _rosterwin_presence(ProfLayoutSplit* layout, const char* presence, const char* status,
int current_indent);
static void _rosterwin_resources(ProfLayoutSplit* layout, PContact contact, int current_indent,
roster_contact_theme_t theme_type, int unread);
static void _rosterwin_rooms(ProfLayoutSplit* layout, char* title, GList* rooms);
static void _rosterwin_rooms_by_service(ProfLayoutSplit* layout);
static void _rosterwin_rooms_header(ProfLayoutSplit* layout, GList* rooms, char* title);
static void _rosterwin_room(ProfLayoutSplit* layout, ProfMucWin* mucwin);
static void _rosterwin_print_rooms(ProfLayoutSplit* layout);
static void _rosterwin_private_chats(ProfLayoutSplit* layout, GList* orphaned_privchats);
static void _rosterwin_private_header(ProfLayoutSplit* layout, GList* privs);
static GSList* _filter_contacts(GSList* contacts);
static GSList* _filter_contacts_with_presence(GSList* contacts, const char* const presence);
static theme_item_t _get_roster_theme(roster_contact_theme_t theme_type, const char* presence);
static int _compare_rooms_name(ProfMucWin* a, ProfMucWin* b);
static int _compare_rooms_unread(ProfMucWin* a, ProfMucWin* b);
2016-01-30 23:11:31 +00:00
void
rosterwin_roster(void)
{
2020-07-07 12:18:57 +00:00
ProfWin* console = wins_get_console();
2016-01-30 23:11:31 +00:00
if (!console) {
return;
}
2016-05-05 22:51:49 +00:00
jabber_conn_status_t conn_status = connection_get_status();
2016-01-30 23:11:31 +00:00
if (conn_status != JABBER_CONNECTED) {
return;
}
2020-07-07 12:18:57 +00:00
ProfLayoutSplit* layout = (ProfLayoutSplit*)console->layout;
2016-01-30 23:11:31 +00:00
assert(layout->memcheck == LAYOUT_SPLIT_MEMCHECK);
if (layout->subwin == NULL) {
return;
}
2023-07-12 12:09:55 +00:00
werase(layout->subwin);
2016-01-30 23:11:31 +00:00
auto_gchar gchar* roomspos = prefs_get_string(PREF_ROSTER_ROOMS_POS);
2016-01-30 23:11:31 +00:00
if (prefs_get_boolean(PREF_ROSTER_ROOMS) && (g_strcmp0(roomspos, "first") == 0)) {
_rosterwin_print_rooms(layout);
2020-07-07 12:18:57 +00:00
GList* orphaned_privchats = NULL;
GList* privchats = wins_get_private_chats(NULL);
GList* curr = privchats;
while (curr) {
2020-07-07 12:18:57 +00:00
ProfPrivateWin* privwin = curr->data;
auto_jid Jid* jidp = jid_create(privwin->fulljid);
if (!muc_active(jidp->barejid)) {
orphaned_privchats = g_list_append(orphaned_privchats, privwin);
}
curr = g_list_next(curr);
}
auto_gchar gchar* privpref = prefs_get_string(PREF_ROSTER_PRIVATE);
if (g_strcmp0(privpref, "group") == 0 || orphaned_privchats) {
_rosterwin_private_chats(layout, orphaned_privchats);
}
g_list_free(orphaned_privchats);
2016-01-30 23:11:31 +00:00
}
if (prefs_get_boolean(PREF_ROSTER_CONTACTS)) {
auto_gchar gchar* by = prefs_get_string(PREF_ROSTER_BY);
2016-01-30 23:11:31 +00:00
if (g_strcmp0(by, "presence") == 0) {
_rosterwin_contacts_by_presence(layout, "chat", "Available for chat");
_rosterwin_contacts_by_presence(layout, "online", "Online");
_rosterwin_contacts_by_presence(layout, "away", "Away");
_rosterwin_contacts_by_presence(layout, "xa", "Extended Away");
_rosterwin_contacts_by_presence(layout, "dnd", "Do not disturb");
_rosterwin_contacts_by_presence(layout, "offline", "Offline");
2016-01-30 23:11:31 +00:00
} else if (g_strcmp0(by, "group") == 0) {
2020-07-07 12:18:57 +00:00
GList* groups = roster_get_groups();
GList* curr_group = groups;
2016-01-30 23:11:31 +00:00
while (curr_group) {
_rosterwin_contacts_by_group(layout, curr_group->data);
curr_group = g_list_next(curr_group);
2016-01-30 23:11:31 +00:00
}
g_list_free_full(groups, free);
_rosterwin_contacts_by_group(layout, NULL);
2016-01-30 23:11:31 +00:00
} else {
_rosterwin_contacts_all(layout);
2016-01-30 23:11:31 +00:00
}
2016-02-07 00:49:48 +00:00
if (prefs_get_boolean(PREF_ROSTER_UNSUBSCRIBED)) {
_rosteriwin_unsubscribed(layout);
2016-02-07 00:49:48 +00:00
}
2016-01-30 23:11:31 +00:00
}
if (prefs_get_boolean(PREF_ROSTER_ROOMS) && (g_strcmp0(roomspos, "last") == 0)) {
_rosterwin_print_rooms(layout);
2020-07-07 12:18:57 +00:00
GList* orphaned_privchats = NULL;
GList* privchats = wins_get_private_chats(NULL);
GList* curr = privchats;
while (curr) {
2020-07-07 12:18:57 +00:00
ProfPrivateWin* privwin = curr->data;
auto_jid Jid* jidp = jid_create(privwin->fulljid);
if (!muc_active(jidp->barejid)) {
orphaned_privchats = g_list_append(orphaned_privchats, privwin);
}
curr = g_list_next(curr);
}
auto_gchar gchar* privpref = prefs_get_string(PREF_ROSTER_PRIVATE);
if (g_strcmp0(privpref, "group") == 0 || orphaned_privchats) {
_rosterwin_private_chats(layout, orphaned_privchats);
}
g_list_free(privchats);
g_list_free(orphaned_privchats);
2016-01-30 23:11:31 +00:00
}
}
2016-01-30 23:11:31 +00:00
static void
2020-07-07 12:18:57 +00:00
_rosterwin_contacts_all(ProfLayoutSplit* layout)
2016-01-30 23:11:31 +00:00
{
2020-07-07 12:18:57 +00:00
GSList* contacts = NULL;
2016-01-30 23:11:31 +00:00
auto_gchar gchar* order = prefs_get_string(PREF_ROSTER_ORDER);
2016-01-30 23:11:31 +00:00
if (g_strcmp0(order, "presence") == 0) {
contacts = roster_get_contacts(ROSTER_ORD_PRESENCE);
2016-01-30 23:11:31 +00:00
} else {
contacts = roster_get_contacts(ROSTER_ORD_NAME);
2016-01-30 23:11:31 +00:00
}
2020-07-07 12:18:57 +00:00
GSList* filtered_contacts = _filter_contacts(contacts);
2016-01-31 02:27:02 +00:00
g_slist_free(contacts);
_rosterwin_contacts_header(layout, "Roster", filtered_contacts);
2016-01-30 23:11:31 +00:00
2016-01-31 02:27:02 +00:00
if (filtered_contacts) {
2020-07-07 12:18:57 +00:00
GSList* curr_contact = filtered_contacts;
2016-01-30 23:11:31 +00:00
while (curr_contact) {
PContact contact = curr_contact->data;
_rosterwin_contact(layout, contact);
curr_contact = g_slist_next(curr_contact);
}
}
2016-01-31 02:27:02 +00:00
g_slist_free(filtered_contacts);
2016-01-30 23:11:31 +00:00
}
2016-02-07 00:49:48 +00:00
static void
2020-07-07 12:18:57 +00:00
_rosteriwin_unsubscribed(ProfLayoutSplit* layout)
2016-02-07 00:49:48 +00:00
{
2020-07-07 12:18:57 +00:00
GList* wins = wins_get_chat_unsubscribed();
2016-02-07 00:49:48 +00:00
if (wins) {
_rosterwin_unsubscribed_header(layout, wins);
2016-02-07 00:49:48 +00:00
}
2020-07-07 12:18:57 +00:00
GList* curr = wins;
2016-02-07 00:49:48 +00:00
while (curr) {
2020-07-07 12:18:57 +00:00
ProfChatWin* chatwin = curr->data;
2016-02-07 00:49:48 +00:00
_rosterwin_unsubscribed_item(layout, chatwin);
curr = g_list_next(curr);
}
g_list_free(wins);
}
2016-01-30 23:11:31 +00:00
static void
2020-07-07 12:18:57 +00:00
_rosterwin_contacts_by_presence(ProfLayoutSplit* layout, const char* const presence, char* title)
2016-01-30 23:11:31 +00:00
{
2020-07-07 12:18:57 +00:00
GSList* contacts = roster_get_contacts_by_presence(presence);
GSList* filtered_contacts = _filter_contacts_with_presence(contacts, presence);
2016-01-31 02:27:02 +00:00
g_slist_free(contacts);
2016-01-30 23:11:31 +00:00
// if this group has contacts, or if we want to show empty groups
2016-01-31 02:27:02 +00:00
if (filtered_contacts || prefs_get_boolean(PREF_ROSTER_EMPTY)) {
_rosterwin_contacts_header(layout, title, filtered_contacts);
2016-01-30 23:11:31 +00:00
}
2016-01-31 02:27:02 +00:00
if (filtered_contacts) {
2020-07-07 12:18:57 +00:00
GSList* curr_contact = filtered_contacts;
2016-01-30 23:11:31 +00:00
while (curr_contact) {
PContact contact = curr_contact->data;
_rosterwin_contact(layout, contact);
curr_contact = g_slist_next(curr_contact);
}
}
2016-01-31 02:27:02 +00:00
g_slist_free(filtered_contacts);
2016-01-30 23:11:31 +00:00
}
static void
2020-07-07 12:18:57 +00:00
_rosterwin_contacts_by_group(ProfLayoutSplit* layout, char* group)
2016-01-30 23:11:31 +00:00
{
2020-07-07 12:18:57 +00:00
GSList* contacts = NULL;
2016-01-30 23:11:31 +00:00
auto_gchar gchar* order = prefs_get_string(PREF_ROSTER_ORDER);
2016-01-30 23:11:31 +00:00
if (g_strcmp0(order, "presence") == 0) {
contacts = roster_get_group(group, ROSTER_ORD_PRESENCE);
2016-01-30 23:11:31 +00:00
} else {
contacts = roster_get_group(group, ROSTER_ORD_NAME);
2016-01-30 23:11:31 +00:00
}
2020-07-07 12:18:57 +00:00
GSList* filtered_contacts = _filter_contacts(contacts);
2016-01-31 02:27:02 +00:00
g_slist_free(contacts);
if (filtered_contacts || prefs_get_boolean(PREF_ROSTER_EMPTY)) {
2016-01-30 23:11:31 +00:00
if (group) {
_rosterwin_contacts_header(layout, group, filtered_contacts);
2016-01-30 23:11:31 +00:00
} else {
_rosterwin_contacts_header(layout, "no group", filtered_contacts);
2016-01-30 23:11:31 +00:00
}
2020-07-07 12:18:57 +00:00
GSList* curr_contact = filtered_contacts;
2016-01-30 23:11:31 +00:00
while (curr_contact) {
PContact contact = curr_contact->data;
_rosterwin_contact(layout, contact);
curr_contact = g_slist_next(curr_contact);
}
}
2016-01-31 02:27:02 +00:00
g_slist_free(filtered_contacts);
2016-01-30 23:11:31 +00:00
}
2016-02-07 00:49:48 +00:00
static void
2020-07-07 12:18:57 +00:00
_rosterwin_unsubscribed_item(ProfLayoutSplit* layout, ProfChatWin* chatwin)
2016-02-07 00:49:48 +00:00
{
2020-07-07 12:18:57 +00:00
const char* const name = chatwin->barejid;
const char* const presence = "offline";
2016-02-07 00:49:48 +00:00
int unread = 0;
roster_contact_theme_t theme_type = ROSTER_CONTACT;
if (chatwin->unread > 0) {
theme_type = ROSTER_CONTACT_UNREAD;
unread = chatwin->unread;
} else {
theme_type = ROSTER_CONTACT_ACTIVE;
}
theme_item_t presence_colour = _get_roster_theme(theme_type, presence);
wattron(layout->subwin, theme_attrs(presence_colour));
2020-07-07 12:18:57 +00:00
GString* msg = g_string_new(" ");
2016-02-07 00:49:48 +00:00
int indent = prefs_get_roster_contact_indent();
int current_indent = 0;
if (indent > 0) {
current_indent += indent;
while (indent > 0) {
g_string_append(msg, " ");
indent--;
}
}
auto_gchar gchar* ch = prefs_get_roster_contact_char();
2016-02-07 00:49:48 +00:00
if (ch) {
2021-10-22 14:23:18 +00:00
g_string_append_printf(msg, "%s", ch);
2016-02-07 00:49:48 +00:00
}
auto_gchar gchar* unreadpos = prefs_get_string(PREF_ROSTER_UNREAD);
2016-02-07 00:49:48 +00:00
if ((g_strcmp0(unreadpos, "before") == 0) && unread > 0) {
g_string_append_printf(msg, "(%d) ", unread);
unread = 0;
}
g_string_append(msg, name);
if ((g_strcmp0(unreadpos, "after") == 0) && unread > 0) {
g_string_append_printf(msg, " (%d)", unread);
}
win_sub_newline_lazy(layout->subwin);
gboolean wrap = prefs_get_boolean(PREF_ROSTER_WRAP);
win_sub_print(layout->subwin, msg->str, FALSE, wrap, current_indent);
g_string_free(msg, TRUE);
wattroff(layout->subwin, theme_attrs(presence_colour));
}
2016-01-30 23:11:31 +00:00
static void
2020-07-07 12:18:57 +00:00
_rosterwin_contact(ProfLayoutSplit* layout, PContact contact)
2016-01-30 23:11:31 +00:00
{
2020-07-07 12:18:57 +00:00
const char* name = p_contact_name_or_jid(contact);
const char* presence = p_contact_presence(contact);
const char* status = p_contact_status(contact);
const char* barejid = p_contact_barejid(contact);
2016-01-30 23:11:31 +00:00
int unread = 0;
roster_contact_theme_t theme_type = ROSTER_CONTACT;
2020-07-07 12:18:57 +00:00
ProfChatWin* chatwin = wins_get_chat(barejid);
2016-01-30 23:11:31 +00:00
if (chatwin) {
if (chatwin->unread > 0) {
theme_type = ROSTER_CONTACT_UNREAD;
unread = chatwin->unread;
} else {
theme_type = ROSTER_CONTACT_ACTIVE;
}
}
theme_item_t presence_colour = _get_roster_theme(theme_type, presence);
int colour = 0;
2019-12-19 13:02:24 +00:00
if (prefs_get_boolean(PREF_ROSTER_COLOR_NICK)) {
colour = theme_hash_attrs(name);
wattron(layout->subwin, colour);
} else {
wattron(layout->subwin, theme_attrs(presence_colour));
}
2016-01-30 23:11:31 +00:00
2020-07-07 12:18:57 +00:00
GString* msg = g_string_new(" ");
2016-01-30 23:11:31 +00:00
int indent = prefs_get_roster_contact_indent();
int current_indent = 0;
if (indent > 0) {
current_indent += indent;
while (indent > 0) {
g_string_append(msg, " ");
indent--;
}
}
auto_gchar gchar* ch = prefs_get_roster_contact_char();
2016-01-30 23:11:31 +00:00
if (ch) {
2021-10-22 14:23:18 +00:00
g_string_append_printf(msg, "%s", ch);
2016-01-30 23:11:31 +00:00
}
auto_gchar gchar* unreadpos = prefs_get_string(PREF_ROSTER_UNREAD);
2016-01-30 23:11:31 +00:00
if ((g_strcmp0(unreadpos, "before") == 0) && unread > 0) {
g_string_append_printf(msg, "(%d) ", unread);
unread = 0;
}
g_string_append(msg, name);
if (g_strcmp0(unreadpos, "after") == 0) {
if (!prefs_get_boolean(PREF_ROSTER_RESOURCE)) {
if (unread > 0) {
g_string_append_printf(msg, " (%d)", unread);
}
unread = 0;
}
}
win_sub_newline_lazy(layout->subwin);
gboolean wrap = prefs_get_boolean(PREF_ROSTER_WRAP);
win_sub_print(layout->subwin, msg->str, FALSE, wrap, current_indent);
g_string_free(msg, TRUE);
2019-12-19 13:02:24 +00:00
if (prefs_get_boolean(PREF_ROSTER_COLOR_NICK)) {
wattroff(layout->subwin, colour);
} else {
wattroff(layout->subwin, theme_attrs(presence_colour));
}
2016-01-30 23:11:31 +00:00
if (prefs_get_boolean(PREF_ROSTER_RESOURCE)) {
_rosterwin_resources(layout, contact, current_indent, theme_type, unread);
} else if (prefs_get_boolean(PREF_ROSTER_PRESENCE) || prefs_get_boolean(PREF_ROSTER_STATUS)) {
if (unread > 0) {
2020-07-07 12:18:57 +00:00
GString* unreadmsg = g_string_new("");
2016-01-30 23:11:31 +00:00
g_string_append_printf(unreadmsg, " (%d)", unread);
2019-12-19 13:02:24 +00:00
2016-01-30 23:11:31 +00:00
wattron(layout->subwin, theme_attrs(presence_colour));
win_sub_print(layout->subwin, unreadmsg->str, FALSE, wrap, current_indent);
g_string_free(unreadmsg, TRUE);
wattroff(layout->subwin, theme_attrs(presence_colour));
2016-01-30 23:11:31 +00:00
}
2016-01-31 22:02:04 +00:00
_rosterwin_presence(layout, presence, status, current_indent);
2016-01-30 23:11:31 +00:00
}
}
2015-11-15 23:13:53 +00:00
static void
2020-07-07 12:18:57 +00:00
_rosterwin_presence(ProfLayoutSplit* layout, const char* presence, const char* status,
int current_indent)
2015-11-15 23:13:53 +00:00
{
// don't show presence for offline contacts
gboolean is_offline = g_strcmp0(presence, "offline") == 0;
if (is_offline) {
return;
}
auto_gchar gchar* by = prefs_get_string(PREF_ROSTER_BY);
2015-11-15 23:13:53 +00:00
gboolean by_presence = g_strcmp0(by, "presence") == 0;
2015-11-21 22:03:43 +00:00
int presence_indent = prefs_get_roster_presence_indent();
if (presence_indent > 0) {
current_indent += presence_indent;
}
2015-11-22 01:39:20 +00:00
gboolean wrap = prefs_get_boolean(PREF_ROSTER_WRAP);
2016-01-31 22:02:04 +00:00
theme_item_t colour = _get_roster_theme(ROSTER_CONTACT, presence);
2015-11-22 01:39:20 +00:00
// show only status when grouped by presence
if (by_presence) {
if (status && prefs_get_boolean(PREF_ROSTER_STATUS)) {
2016-01-31 22:02:04 +00:00
wattron(layout->subwin, theme_attrs(colour));
if (presence_indent == -1) {
2020-07-07 12:18:57 +00:00
GString* msg = g_string_new("");
g_string_append_printf(msg, ": \"%s\"", status);
2015-11-22 01:39:20 +00:00
win_sub_print(layout->subwin, msg->str, FALSE, wrap, current_indent);
g_string_free(msg, TRUE);
wattroff(layout->subwin, theme_attrs(colour));
} else {
2020-07-07 12:18:57 +00:00
GString* msg = g_string_new(" ");
while (current_indent > 0) {
g_string_append(msg, " ");
current_indent--;
}
g_string_append_printf(msg, "\"%s\"", status);
2015-11-22 00:54:40 +00:00
win_sub_newline_lazy(layout->subwin);
2015-11-22 01:39:20 +00:00
win_sub_print(layout->subwin, msg->str, FALSE, wrap, current_indent);
g_string_free(msg, TRUE);
wattroff(layout->subwin, theme_attrs(colour));
}
}
2020-07-07 12:18:57 +00:00
// show both presence and status when not grouped by presence
} else if (prefs_get_boolean(PREF_ROSTER_PRESENCE) || (status && prefs_get_boolean(PREF_ROSTER_STATUS))) {
2015-11-15 23:13:53 +00:00
wattron(layout->subwin, theme_attrs(colour));
if (presence_indent == -1) {
2020-07-07 12:18:57 +00:00
GString* msg = g_string_new("");
if (prefs_get_boolean(PREF_ROSTER_PRESENCE)) {
g_string_append_printf(msg, ": %s", presence);
if (status && prefs_get_boolean(PREF_ROSTER_STATUS)) {
g_string_append_printf(msg, " \"%s\"", status);
}
} else if (status && prefs_get_boolean(PREF_ROSTER_STATUS)) {
g_string_append_printf(msg, ": \"%s\"", status);
}
2015-11-22 01:39:20 +00:00
win_sub_print(layout->subwin, msg->str, FALSE, wrap, current_indent);
g_string_free(msg, TRUE);
wattroff(layout->subwin, theme_attrs(colour));
} else {
2020-07-07 12:18:57 +00:00
GString* msg = g_string_new(" ");
while (current_indent > 0) {
g_string_append(msg, " ");
current_indent--;
}
if (prefs_get_boolean(PREF_ROSTER_PRESENCE)) {
g_string_append(msg, presence);
if (status && prefs_get_boolean(PREF_ROSTER_STATUS)) {
g_string_append_printf(msg, " \"%s\"", status);
}
} else if (status && prefs_get_boolean(PREF_ROSTER_STATUS)) {
g_string_append_printf(msg, "\"%s\"", status);
2015-11-15 23:13:53 +00:00
}
2015-11-22 00:54:40 +00:00
win_sub_newline_lazy(layout->subwin);
2015-11-22 01:39:20 +00:00
win_sub_print(layout->subwin, msg->str, FALSE, wrap, current_indent);
g_string_free(msg, TRUE);
wattroff(layout->subwin, theme_attrs(colour));
2015-11-15 23:13:53 +00:00
}
}
}
2014-12-16 23:00:05 +00:00
static void
2020-07-07 12:18:57 +00:00
_rosterwin_resources(ProfLayoutSplit* layout, PContact contact, int current_indent, roster_contact_theme_t theme_type,
int unread)
2014-12-16 22:14:15 +00:00
{
2015-11-22 16:37:05 +00:00
gboolean join = prefs_get_boolean(PREF_ROSTER_RESOURCE_JOIN);
2020-07-07 12:18:57 +00:00
GList* resources = p_contact_get_available_resources(contact);
2015-11-15 22:54:09 +00:00
if (resources) {
2016-01-31 22:02:04 +00:00
// resource on same line as contact
2015-11-22 16:37:05 +00:00
if (join && (g_list_length(resources) == 1)) {
2020-07-07 12:18:57 +00:00
Resource* resource = resources->data;
const char* resource_presence = string_from_resource_presence(resource->presence);
theme_item_t resource_presence_colour = _get_roster_theme(theme_type, resource_presence);
2014-12-16 22:14:15 +00:00
2015-11-15 22:54:09 +00:00
wattron(layout->subwin, theme_attrs(resource_presence_colour));
2020-07-07 12:18:57 +00:00
GString* msg = g_string_new("");
auto_gchar gchar* ch = prefs_get_roster_resource_char();
2015-11-22 02:04:59 +00:00
if (ch) {
2021-10-22 14:29:08 +00:00
g_string_append_printf(msg, "%s", ch);
2015-11-22 16:37:05 +00:00
} else {
g_string_append(msg, " ");
2015-11-22 02:04:59 +00:00
}
2015-11-15 22:54:09 +00:00
g_string_append(msg, resource->name);
if (prefs_get_boolean(PREF_ROSTER_PRIORITY)) {
2015-11-22 00:48:18 +00:00
g_string_append_printf(msg, " %d", resource->priority);
}
auto_gchar gchar* unreadpos = prefs_get_string(PREF_ROSTER_UNREAD);
if ((g_strcmp0(unreadpos, "after") == 0) && unread > 0) {
g_string_append_printf(msg, " (%d)", unread);
}
2015-11-22 01:39:20 +00:00
gboolean wrap = prefs_get_boolean(PREF_ROSTER_WRAP);
2015-11-22 16:37:05 +00:00
win_sub_print(layout->subwin, msg->str, FALSE, wrap, 0);
2015-11-15 22:54:09 +00:00
g_string_free(msg, TRUE);
wattroff(layout->subwin, theme_attrs(resource_presence_colour));
2014-12-16 22:14:15 +00:00
if (prefs_get_boolean(PREF_ROSTER_PRESENCE) || prefs_get_boolean(PREF_ROSTER_STATUS)) {
2016-01-31 22:02:04 +00:00
_rosterwin_presence(layout, resource_presence, resource->status, current_indent);
2014-12-16 22:14:15 +00:00
}
2016-01-31 22:02:04 +00:00
2020-07-07 12:18:57 +00:00
// resource(s) on new lines
2015-11-22 16:37:05 +00:00
} else {
gboolean wrap = prefs_get_boolean(PREF_ROSTER_WRAP);
auto_gchar gchar* unreadpos = prefs_get_string(PREF_ROSTER_UNREAD);
if ((g_strcmp0(unreadpos, "after") == 0) && unread > 0) {
2020-07-07 12:18:57 +00:00
GString* unreadmsg = g_string_new("");
g_string_append_printf(unreadmsg, " (%d)", unread);
2020-07-07 12:18:57 +00:00
const char* presence = p_contact_presence(contact);
theme_item_t presence_colour = _get_roster_theme(theme_type, presence);
wattron(layout->subwin, theme_attrs(presence_colour));
win_sub_print(layout->subwin, unreadmsg->str, FALSE, wrap, current_indent);
g_string_free(unreadmsg, TRUE);
wattroff(layout->subwin, theme_attrs(presence_colour));
}
2015-11-22 16:37:05 +00:00
int resource_indent = prefs_get_roster_resource_indent();
if (resource_indent > 0) {
current_indent += resource_indent;
}
2015-11-15 22:54:09 +00:00
2020-07-07 12:18:57 +00:00
GList* curr_resource = resources;
2015-11-22 16:37:05 +00:00
while (curr_resource) {
2020-07-07 12:18:57 +00:00
Resource* resource = curr_resource->data;
const char* resource_presence = string_from_resource_presence(resource->presence);
2016-01-31 22:02:04 +00:00
theme_item_t resource_presence_colour = _get_roster_theme(ROSTER_CONTACT, resource_presence);
2015-11-22 16:37:05 +00:00
wattron(layout->subwin, theme_attrs(resource_presence_colour));
2020-07-07 12:18:57 +00:00
GString* msg = g_string_new(" ");
2015-11-22 16:37:05 +00:00
int this_indent = current_indent;
while (this_indent > 0) {
g_string_append(msg, " ");
this_indent--;
}
auto_char char* ch = prefs_get_roster_resource_char();
2015-11-22 16:37:05 +00:00
if (ch) {
2021-10-22 14:29:08 +00:00
g_string_append_printf(msg, "%s", ch);
2015-11-22 16:37:05 +00:00
}
g_string_append(msg, resource->name);
if (prefs_get_boolean(PREF_ROSTER_PRIORITY)) {
g_string_append_printf(msg, " %d", resource->priority);
}
win_sub_newline_lazy(layout->subwin);
win_sub_print(layout->subwin, msg->str, FALSE, wrap, current_indent);
g_string_free(msg, TRUE);
wattroff(layout->subwin, theme_attrs(resource_presence_colour));
if (prefs_get_boolean(PREF_ROSTER_PRESENCE) || prefs_get_boolean(PREF_ROSTER_STATUS)) {
2016-01-31 22:02:04 +00:00
_rosterwin_presence(layout, resource_presence, resource->status, current_indent);
2015-11-22 16:37:05 +00:00
}
curr_resource = g_list_next(curr_resource);
}
2015-11-15 22:54:09 +00:00
}
} else if (prefs_get_boolean(PREF_ROSTER_PRESENCE) || prefs_get_boolean(PREF_ROSTER_STATUS)) {
2020-07-07 12:18:57 +00:00
const char* presence = p_contact_presence(contact);
const char* status = p_contact_status(contact);
theme_item_t presence_colour = _get_roster_theme(theme_type, presence);
gboolean wrap = prefs_get_boolean(PREF_ROSTER_WRAP);
auto_gchar gchar* unreadpos = prefs_get_string(PREF_ROSTER_UNREAD);
if ((g_strcmp0(unreadpos, "after") == 0) && unread > 0) {
2020-07-07 12:18:57 +00:00
GString* unreadmsg = g_string_new("");
g_string_append_printf(unreadmsg, " (%d)", unread);
wattron(layout->subwin, theme_attrs(presence_colour));
win_sub_print(layout->subwin, unreadmsg->str, FALSE, wrap, current_indent);
g_string_free(unreadmsg, TRUE);
wattroff(layout->subwin, theme_attrs(presence_colour));
}
2016-01-31 22:02:04 +00:00
_rosterwin_presence(layout, presence, status, current_indent);
} else {
gboolean wrap = prefs_get_boolean(PREF_ROSTER_WRAP);
auto_gchar gchar* unreadpos = prefs_get_string(PREF_ROSTER_UNREAD);
if ((g_strcmp0(unreadpos, "after") == 0) && unread > 0) {
2020-07-07 12:18:57 +00:00
GString* unreadmsg = g_string_new("");
g_string_append_printf(unreadmsg, " (%d)", unread);
2020-07-07 12:18:57 +00:00
const char* presence = p_contact_presence(contact);
theme_item_t presence_colour = _get_roster_theme(theme_type, presence);
wattron(layout->subwin, theme_attrs(presence_colour));
win_sub_print(layout->subwin, unreadmsg->str, FALSE, wrap, current_indent);
g_string_free(unreadmsg, TRUE);
wattroff(layout->subwin, theme_attrs(presence_colour));
}
2015-11-15 22:54:09 +00:00
}
2015-11-15 22:54:09 +00:00
g_list_free(resources);
}
static void
2020-07-07 12:18:57 +00:00
_rosterwin_rooms(ProfLayoutSplit* layout, char* title, GList* rooms)
2015-11-15 22:54:09 +00:00
{
2020-07-07 12:18:57 +00:00
GList* rooms_sorted = NULL;
GList* curr_room = rooms;
2016-01-30 23:11:31 +00:00
while (curr_room) {
2020-07-07 12:18:57 +00:00
ProfMucWin* mucwin = wins_get_muc(curr_room->data);
2016-01-30 23:11:31 +00:00
if (mucwin) {
auto_gchar gchar* order = prefs_get_string(PREF_ROSTER_ROOMS_ORDER);
2016-01-30 23:11:31 +00:00
if (g_strcmp0(order, "unread") == 0) {
rooms_sorted = g_list_insert_sorted(rooms_sorted, mucwin, (GCompareFunc)_compare_rooms_unread);
} else {
rooms_sorted = g_list_insert_sorted(rooms_sorted, mucwin, (GCompareFunc)_compare_rooms_name);
}
}
2016-01-30 23:11:31 +00:00
curr_room = g_list_next(curr_room);
}
2016-01-30 23:11:31 +00:00
// if there are active rooms, or if we want to show empty groups
if (rooms_sorted || prefs_get_boolean(PREF_ROSTER_EMPTY)) {
_rosterwin_rooms_header(layout, rooms_sorted, title);
2020-07-07 12:18:57 +00:00
GList* curr_room = rooms_sorted;
2016-01-30 23:11:31 +00:00
while (curr_room) {
_rosterwin_room(layout, curr_room->data);
curr_room = g_list_next(curr_room);
2014-12-16 23:00:05 +00:00
}
}
2016-01-28 00:26:20 +00:00
2016-01-30 23:11:31 +00:00
g_list_free(rooms_sorted);
}
2014-12-16 23:16:23 +00:00
static void
2020-07-07 12:18:57 +00:00
_rosterwin_rooms_by_service(ProfLayoutSplit* layout)
{
2020-07-07 12:18:57 +00:00
GList* rooms = muc_rooms();
GList* curr = rooms;
GList* services = NULL;
2016-07-25 22:28:04 +00:00
while (curr) {
2020-07-07 12:18:57 +00:00
char* roomjid = curr->data;
auto_jid Jid* jidp = jid_create(roomjid);
2016-07-25 22:28:04 +00:00
if (!g_list_find_custom(services, jidp->domainpart, (GCompareFunc)g_strcmp0)) {
services = g_list_insert_sorted(services, strdup(jidp->domainpart), (GCompareFunc)g_strcmp0);
2016-01-31 19:38:06 +00:00
}
2016-07-25 22:28:04 +00:00
curr = g_list_next(curr);
2016-01-31 19:38:06 +00:00
}
2020-07-07 12:18:57 +00:00
GList* curr_service = services;
while (curr_service) {
2020-07-07 12:18:57 +00:00
char* service = curr_service->data;
GList* filtered_rooms = NULL;
2016-07-25 22:28:04 +00:00
curr = rooms;
while (curr) {
2020-07-07 12:18:57 +00:00
char* roomjid = curr->data;
auto_jid Jid* jidp = jid_create(roomjid);
if (g_strcmp0(curr_service->data, jidp->domainpart) == 0) {
2016-07-25 22:28:04 +00:00
filtered_rooms = g_list_append(filtered_rooms, strdup(jidp->barejid));
}
2016-07-25 22:28:04 +00:00
curr = g_list_next(curr);
}
_rosterwin_rooms(layout, service, filtered_rooms);
2016-07-25 22:28:04 +00:00
g_list_free_full(filtered_rooms, free);
curr_service = g_list_next(curr_service);
2014-12-16 23:00:05 +00:00
}
2016-07-25 22:28:04 +00:00
g_list_free(rooms);
g_list_free_full(services, free);
2014-12-16 23:00:05 +00:00
}
2016-01-30 23:11:31 +00:00
static void
2020-07-07 12:18:57 +00:00
_rosterwin_room(ProfLayoutSplit* layout, ProfMucWin* mucwin)
2016-01-02 01:22:19 +00:00
{
2020-07-07 12:18:57 +00:00
GString* msg = g_string_new(" ");
if (mucwin->unread_mentions) {
wattron(layout->subwin, theme_attrs(THEME_ROSTER_ROOM_MENTION));
} else if (mucwin->unread_triggers) {
wattron(layout->subwin, theme_attrs(THEME_ROSTER_ROOM_TRIGGER));
} else if (mucwin->unread > 0) {
2016-01-09 21:37:59 +00:00
wattron(layout->subwin, theme_attrs(THEME_ROSTER_ROOM_UNREAD));
} else {
2016-01-09 21:37:59 +00:00
wattron(layout->subwin, theme_attrs(THEME_ROSTER_ROOM));
}
2016-01-02 01:22:19 +00:00
int indent = prefs_get_roster_contact_indent();
int current_indent = 0;
if (indent > 0) {
current_indent += indent;
while (indent > 0) {
g_string_append(msg, " ");
indent--;
}
}
auto_gchar gchar* ch = prefs_get_roster_room_char();
2016-01-02 01:22:19 +00:00
if (ch) {
2021-10-22 14:39:54 +00:00
g_string_append_printf(msg, "%s", ch);
2016-01-02 01:22:19 +00:00
}
auto_gchar gchar* unreadpos = prefs_get_string(PREF_ROSTER_ROOMS_UNREAD);
if ((g_strcmp0(unreadpos, "before") == 0) && mucwin->unread > 0) {
g_string_append_printf(msg, "(%d) ", mucwin->unread);
}
Improve MUC title behaviour for roster, statusbar, and titlebar ## Abstract Continuation of https://github.com/profanity-im/profanity/pull/1881 Give all MUC title commands a consistent command structure and appearance. - `/roster room use name|jid` and `/roster room show|hide server` are now `/roster room title bookmark|jid|localpart|name` - `/statusbar room room|jid` is now `/statusbar room title bookmark|jid|localpart|name` - `/statusbar show|hide jid` and `/statusbar show|hide name` are now `/titlebar room title bookmark|jid|localpart|name` Fix both bugs mentioned in https://github.com/profanity-im/profanity/pull/1881 ### src/ui/mucwin.c:mucwin_generate_title Called by each command to generate a properly formatted title. It checks for "name" first because "name" is the default preference for each command. The last if-statement sets the title to "localpart" for special cases when the title should be "localpart" instead of the user-defined preference. ## Testing ### Preparation Remove preferences that will interfere with testing. ``` sed -i "/roster.rooms.title=/d" profrc sed -i "/statusbar.room.title=/d" profrc sed -i "/titlebar.muc.title=/d" profrc sed -i "/roster.rooms.use.name=/d" profrc sed -i "/roster.rooms.server=/d" profrc sed -i "/statusbar.room=/d" profrc sed -i "/titlebar.muc.title.jid=/d" profrc sed -i "/titlebar.muc.title.name=/d" profrc sed -i "/roster.rooms.by=/d" profrc ``` ### Command Definitions | Test | Window | | :--- | :--- | | `/help roster` | - /roster room title bookmark\|jid\|localpart\|name<br>- room title bookmark\|jid\|localpart\|name : Display the bookmark name, JID, JID localpart, or room name as the roster title for MUCs.<br>- *No /roster show\|hide server*<br>- *No /roster room use jid\|name* | | `/help statusbar` | - /statusbar room title bookmark\|jid\|localpart\|name<br>- room title bookmark\|jid\|localpart\|name : Display the bookmark name, JID, JID localpart, or room name as the title for MUC tabs.<br>- *No /statusbar room jid\|room* | | `/help titlebar` | - /titlebar room title bookmark\|jid\|localpart\|name<br>- room title bookmark\|jid\|localpart\|name : Display the bookmark name, JID, JID localpart, or room name as the MUC window title.<br>- *No /titlebar show\|hide jid\|name* | ### Autocomplete | Test | Command line | | :--- | :--- | | `/roster room <TAB>` | Autocompletes `title` | | `/roster room title <TAB>` | Autocompletes `bookmark\|jid\|localpart\|name` | | `/statusbar room <TAB>` | Autocompletes `title` | | `/statusbar room title <TAB>` | Autocompletes `bookmark\|jid\|localpart\|name` | | `/titlebar room <TAB>` | Autocompletes `title` | | `/titlebar room title <TAB>` | Autocompletes `bookmark\|jid\|localpart\|name` | | `/roster room <TAB>` | Does not autocomplete `use`, `show`, or `hide` | | `/roster room use <TAB>` | Does not autocomplete `name` | | `/roster room show <TAB>` | Does not autocomplete `server` | | `/roster room hide <TAB>` | Does not autocomplete `server` | | `/statusbar room <TAB>` | Does not autocomplete `jid` or `room` | | `/titlebar show <TAB>` | Does not autocomplete `jid` or `name` | | `/titlebar hide <TAB>` | Does not autocomplete `jid` or `name` | ### Set Preferences | Test | Window | profrc | | :--- | :--- | :--- | | `/roster room title bookmark` | Roster MUCs will display 'bookmark' as their title. | roster.rooms.title=bookmark | | `/roster room title jid` | Roster MUCs will display 'jid' as their title. | roster.rooms.title=jid | | `/roster room title localpart` | Roster MUCs will display 'localpart' as their title. | roster.rooms.title=localpart | | `/roster room title name` | Roster MUCs will display 'name' as their title. | roster.rooms.title=name | | `/roster room title invalid` | Invalid usage, see '/help roster' for details. | | | `/statusbar room title bookmark` | Displaying 'bookmark' as the title for MUC tabs. | statusbar.room.title=bookmark | | `/statusbar room title jid` | Displaying 'jid' as the title for MUC tabs. | statusbar.room.title=jid | | `/statusbar room title localpart` | Displaying 'localpart' as the title for MUC tabs. | statusbar.room.title=localpart | | `/statusbar room title name` | Displaying 'name' as the title for MUC tabs. | statusbar.room.title=name | | `/statusbar room title invalid` | Invalid usage, see '/help statusbar' for details. | | | `/titlebar room title bookmark` | MUC windows will display 'bookmark' as the window title. | titlebar.muc.title=bookmark | | `/titlebar room title jid` | MUC windows will display 'jid' as the window title. | titlebar.muc.title=jid | | `/titlebar room title localpart` | MUC windows will display 'localpart' as the window title. | titlebar.muc.title=localpart | | `/titlebar room title name` | MUC windows will display 'name' as the window title. | titlebar.muc.title=name | | `/titlebar room title invalid` | Invalid usage, see '/help titlebar' for details. | | | `/roster room use jid` | Invalid usage, see '/help roster' for details. | | | `/roster room use name` | Invalid usage, see '/help roster' for details. | | | `/roster room show server` | Invalid usage, see '/help roster' for details. | | | `/roster room hide server` | Invalid usage, see '/help roster' for details. | | | `/statusbar room jid` | Invalid usage, see '/help statusbar' for details. | | | `/statusbar room room` | Invalid usage, see '/help statusbar' for details. | | | `/titlebar show jid` | Invalid usage, see '/help titlebar' for details. | | | `/titlebar hide jid` | Invalid usage, see '/help titlebar' for details. | | | `/titlebar show name` | Invalid usage, see '/help titlebar' for details. | | | `/titlebar hide name` | Invalid usage, see '/help titlebar' for details. | | ### Display Set Preferences | Test | Window | | :--- | :--- | | /prefs ui | - Roster rooms title (/roster) : name<br>- Room tab display (/statusbar) : name<br>- MUC window title (/titlebar) : name | ### Test MUC Window #### Test: without *name* preference, without *room name* field ``` /join muc@dmn.im /room config /field1 "" /form submit /quit ``` | Test | Roster | Statusbar | Titlebar | | :--- | :--- | :--- | :--- | | `/join muc@dmn.im` | muc<span/>@dmn.im | muc<span/>@dmn.im | muc<span/>@dmn.im | | `/room config` | | muc<span/>@dmn.im conf | muc<span/>@dmn.im config | | `/field2 edit` | | | muc<span/>@dmn.im config * | | `/msg tst` | tst | muc<span/>@dmn.im/tst | muc<span/>@dmn.im/tst | | `/roster room by service` | muc | | | #### Test: with *name* preference, without *room name* field ``` /roster room title name /statusbar room title name /titlebar room title name /save /quit ``` | Test | Roster | Statusbar | Titlebar | | :--- | :--- | :--- | :--- | | `/join muc@dmn.im` | muc<span/>@dmn.im | muc<span/>@dmn.im | muc<span/>@dmn.im | | `/room config` | | muc<span/>@dmn.im conf | muc<span/>@dmn.im config | | `/field2 edit` | | | muc<span/>@dmn.im config * | | `/msg tst` | tst | muc<span/>@dmn.im/tst | muc<span/>@dmn.im/tst | | `/roster room by service` | muc | | | #### Test: without *name* preference, with *room name* field ``` sed -i "/roster.rooms.title=/d" profrc sed -i "/statusbar.room.title=/d" profrc sed -i "/titlebar.muc.title=/d" profrc /join muc@dmn.im /room config /field1 "my_room" /form submit /quit ``` | Test | Roster | Statusbar | Titlebar | | :--- | :--- | :--- | :--- | | `/join muc@dmn.im` | my_room | my_room | my_room | | `/room config` | | my_room conf | my_room config | | `/field2 edit` | | | my_room config * | | `/msg tst` | tst | my_room/tst | my_room/tst | | `/roster room by service` | my_room | | | #### Test: with *name* preference, with *room name* field ``` /quit /roster room title name /statusbar room title name /titlebar room title name /save /quit ``` | Test | Roster | Statusbar | Titlebar | | :--- | :--- | :--- | :--- | | `/join muc@dmn.im` | my_room | my_room | my_room | | `/room config` | | my_room conf | my_room config | | `/field2 edit` | | | my_room config * | | `/msg tst` | tst | my_room/tst | my_room/tst | | `/roster room by service` | my_room | | | #### Test: with *localpart* preference ``` /quit /roster room title localpart /statusbar room title localpart /titlebar room title localpart /save /quit ``` | Test | Roster | Statusbar | Titlebar | | :--- | :--- | :--- | :--- | | `/join muc@dmn.im` | muc | muc | muc | | `/room config` | | muc conf | muc config | | `/field2 edit` | | | muc config * | | `/msg tst` | tst | muc/tst | muc/tst | | `/roster room by service` | muc | | | #### Test: with *bookmark* preference, without *bookmark name* ``` /quit /roster room title bookmark /statusbar room title bookmark /titlebar room title bookmark /save /quit /bookmark add muc@dmn.im ``` | Test | Roster | Statusbar | Titlebar | | :--- | :--- | :--- | :--- | | `/bookmark join muc@dmn.im` | muc<span/>@dmn.im | muc<span/>@dmn.im | muc<span/>@dmn.im | | `/room config` | | muc<span/>@dmn.im conf | muc<span/>@dmn.im config | | `/field2 edit` | | | muc<span/>@dmn.im config * | | `/msg tst` | tst | muc<span/>@dmn.im/tst | muc<span/>@dmn.im/tst | | `/roster room by service` | muc | | | #### Test: with *bookmark* preference, with *bookmark name* ``` /quit /bookmark remove muc@dmn.im /bookmark add muc@dmn.im name "my_bookmark" ``` | Test | Roster | Statusbar | Titlebar | | :--- | :--- | :--- | :--- | | `/bookmark join muc@dmn.im` | my_bookmark | my_bookmark | my_bookmark | | `/room config` | | my_bookmark conf | my_bookmark config | | `/field2 edit` | | | my_bookmark config * | | `/msg tst` | tst | my_bookmark/tst | my_bookmark/tst | | `/roster room by service` | my_bookmark | | | #### Test: with *jid* preference ``` /quit /roster room title jid /statusbar room title jid /titlebar room title jid /save /quit ``` | Test | Roster | Statusbar | Titlebar | | :--- | :--- | :--- | :--- | | `/join muc@dmn.im` | muc<span/>@dmn.im | muc<span/>@dmn.im | muc<span/>@dmn.im | | `/room config` | | muc<span/>@dmn.im conf | muc<span/>@dmn.im config | | `/field2 edit` | | | muc<span/>@dmn.im config * | | `/msg tst` | tst | muc<span/>@dmn.im/tst | muc<span/>@dmn.im/tst | | `/roster room by service` | muc | | | ### Test Contact Chat Window Title #### Test: without contact nick ``` /roster add tst@dmn.im ``` | Test | Titlebar | | :--- | :--- | | `/msg tst@dmn.im` | tst<span/>@dmn.im | #### Test: with contact nick ``` /roster add tst@dmn.im my_tst ``` | Test | Titlebar | | :--- | :--- | | `/msg my_tst` | my_tst <tst<span/>@ike.snikket.chat> | ### Test Preference Upgrade #### Test /roster | Test | profrc | | :--- | :--- | | `sed -i '/\[ui\]/a\roster.rooms.use.name=name' profrc` | Original key removed. | | `sed -i '/\[ui\]/a\roster.rooms.use.name=' profrc` | Original key removed. | | `sed -i '/\[ui\]/a\roster.rooms.server=' profrc` | Original key removed. | | `sed -i '/\[ui\]/a\roster.rooms.use.name=jid' profrc` | Original key removed.<br>roster.rooms.title=jid | | `sed -i '/\[ui\]/a\roster.rooms.use.name=jid' profrc`<br>`sed -i '/\[ui\]/a\roster.rooms.server=false' profrc` | Original keys removed.<br>roster.rooms.title=localpart | | `sed -i '/\[ui\]/a\roster.rooms.use.name=jid' profrc`<br>`sed -i '/\[ui\]/a\roster.rooms.server=true' profrc` | Original keys removed.<br>roster.rooms.title=jid | | `sed -i '/\[ui\]/a\roster.rooms.use.name=jid' profrc`<br>`sed -i '/\[ui\]/a\roster.rooms.server=' profrc` | Original keys removed.<br>roster.rooms.title=jid | | `sed -i '/\[ui\]/a\statusbar.room=' profrc` | Original key removed. | | `sed -i '/\[ui\]/a\statusbar.room=room' profrc` | Original key removed.<br>statusbar.room.title=localpart | | `sed -i '/\[ui\]/a\statusbar.room=jid' profrc` | Original key removed.<br>statusbar.room.title=jid | | `sed -i '/\[ui\]/a\titlebar.muc.title.jid=' profrc` | Original key removed. | | `sed -i '/\[ui\]/a\titlebar.muc.title.name=' profrc` | Original key removed. | | `sed -i '/\[ui\]/a\titlebar.muc.title.jid=true' profrc` | Original key removed. | | `sed -i '/\[ui\]/a\titlebar.muc.title.name=true' profrc` | Original key removed. | | `sed -i '/\[ui\]/a\titlebar.muc.title.jid=false' profrc` | Original key removed. | | `sed -i '/\[ui\]/a\titlebar.muc.title.name=false' profrc` | Original key removed. | | `sed -i '/\[ui\]/a\titlebar.muc.title.jid=true' profrc`<br>`sed -i '/\[ui\]/a\titlebar.muc.title.name=false' profrc` | Original key removed.<br>titlebar.muc.title=jid | | `sed -i '/\[ui\]/a\titlebar.muc.title.jid=false' profrc`<br>`sed -i '/\[ui\]/a\titlebar.muc.title.name=true' profrc` | Original keys removed. | | `sed -i '/\[ui\]/a\titlebar.muc.title.jid=true' profrc`<br>`sed -i '/\[ui\]/a\titlebar.muc.title.name=true' profrc` | Original keys removed. | ### Test Valgrind No memory leaks detected relating to these changes.
2023-10-06 00:16:04 +00:00
auto_gchar gchar* mucwin_title = mucwin_generate_title(mucwin->roomjid, PREF_ROSTER_ROOMS_TITLE);
g_string_append(msg, mucwin_title);
if ((g_strcmp0(unreadpos, "after") == 0) && mucwin->unread > 0) {
2016-01-02 01:22:19 +00:00
g_string_append_printf(msg, " (%d)", mucwin->unread);
}
win_sub_newline_lazy(layout->subwin);
gboolean wrap = prefs_get_boolean(PREF_ROSTER_WRAP);
win_sub_print(layout->subwin, msg->str, FALSE, wrap, current_indent);
g_string_free(msg, TRUE);
if (mucwin->unread_mentions) {
wattroff(layout->subwin, theme_attrs(THEME_ROSTER_ROOM_MENTION));
} else if (mucwin->unread_triggers) {
wattroff(layout->subwin, theme_attrs(THEME_ROSTER_ROOM_TRIGGER));
} else if (mucwin->unread > 0) {
2016-01-09 21:37:59 +00:00
wattroff(layout->subwin, theme_attrs(THEME_ROSTER_ROOM_UNREAD));
} else {
2016-01-09 21:37:59 +00:00
wattroff(layout->subwin, theme_attrs(THEME_ROSTER_ROOM));
}
2016-01-24 00:33:24 +00:00
auto_gchar gchar* privpref = prefs_get_string(PREF_ROSTER_PRIVATE);
2016-01-24 01:04:21 +00:00
if (g_strcmp0(privpref, "room") == 0) {
2020-07-07 12:18:57 +00:00
GList* privs = wins_get_private_chats(mucwin->roomjid);
GList* curr = privs;
2016-01-24 01:04:21 +00:00
while (curr) {
2020-07-07 12:18:57 +00:00
ProfPrivateWin* privwin = curr->data;
2016-01-24 01:04:21 +00:00
win_sub_newline_lazy(layout->subwin);
2020-07-07 12:18:57 +00:00
GString* privmsg = g_string_new(" ");
2016-01-24 01:04:21 +00:00
indent = prefs_get_roster_contact_indent();
current_indent = 0;
if (indent > 0) {
current_indent += indent;
while (indent > 0) {
g_string_append(privmsg, " ");
indent--;
}
2016-01-24 00:33:24 +00:00
}
2016-01-24 01:04:21 +00:00
// TODO add preference
indent = prefs_get_roster_resource_indent();
if (indent > 0) {
current_indent += indent;
while (indent > 0) {
g_string_append(privmsg, " ");
indent--;
}
2016-01-24 00:33:24 +00:00
}
auto_gchar gchar* unreadpos2 = prefs_get_string(PREF_ROSTER_ROOMS_UNREAD);
if ((g_strcmp0(unreadpos2, "before") == 0) && privwin->unread > 0) {
2016-01-24 01:04:21 +00:00
g_string_append_printf(privmsg, "(%d) ", privwin->unread);
}
2016-01-24 00:33:24 +00:00
auto_gchar gchar* ch2 = prefs_get_roster_room_private_char();
if (ch2) {
g_string_append_printf(privmsg, "%s", ch2);
2016-01-24 01:04:21 +00:00
}
2016-01-24 00:33:24 +00:00
2020-07-07 12:18:57 +00:00
char* nick = privwin->fulljid + strlen(mucwin->roomjid) + 1;
g_string_append(privmsg, nick);
2016-01-24 00:33:24 +00:00
if ((g_strcmp0(unreadpos2, "after") == 0) && privwin->unread > 0) {
2016-01-24 01:04:21 +00:00
g_string_append_printf(privmsg, " (%d)", privwin->unread);
}
2016-01-24 00:33:24 +00:00
2020-07-07 12:18:57 +00:00
const char* presence = "offline";
2016-01-24 00:33:24 +00:00
2020-07-07 12:18:57 +00:00
Occupant* occupant = muc_roster_item(mucwin->roomjid, nick);
if (occupant) {
presence = string_from_resource_presence(occupant->presence);
}
2016-01-24 00:33:24 +00:00
theme_item_t colour;
2016-01-24 01:30:02 +00:00
if (privwin->unread > 0) {
colour = _get_roster_theme(ROSTER_CONTACT_UNREAD, presence);
2016-01-24 01:04:21 +00:00
} else {
colour = _get_roster_theme(ROSTER_CONTACT_ACTIVE, presence);
2016-01-24 01:04:21 +00:00
}
wattron(layout->subwin, theme_attrs(colour));
win_sub_print(layout->subwin, privmsg->str, FALSE, wrap, current_indent);
wattroff(layout->subwin, theme_attrs(colour));
2016-01-24 01:04:21 +00:00
g_string_free(privmsg, TRUE);
curr = g_list_next(curr);
2016-01-24 00:33:24 +00:00
}
2016-01-24 01:04:21 +00:00
g_list_free(privs);
2016-01-24 00:33:24 +00:00
}
2016-01-02 01:22:19 +00:00
}
static void
2020-07-07 12:18:57 +00:00
_rosterwin_print_rooms(ProfLayoutSplit* layout)
{
auto_gchar gchar* roomsbypref = prefs_get_string(PREF_ROSTER_ROOMS_BY);
if (g_strcmp0(roomsbypref, "service") == 0) {
_rosterwin_rooms_by_service(layout);
} else {
2020-07-07 12:18:57 +00:00
GList* rooms = muc_rooms();
_rosterwin_rooms(layout, "Rooms", rooms);
g_list_free(rooms);
}
}
2016-01-30 23:11:31 +00:00
static void
2020-07-07 12:18:57 +00:00
_rosterwin_private_chats(ProfLayoutSplit* layout, GList* orphaned_privchats)
2016-01-24 01:30:02 +00:00
{
2020-07-07 12:18:57 +00:00
GList* privs = NULL;
2016-01-31 19:38:06 +00:00
2023-06-13 20:05:45 +00:00
auto_gchar gchar* privpref = prefs_get_string(PREF_ROSTER_PRIVATE);
2016-01-31 19:38:06 +00:00
if (g_strcmp0(privpref, "group") == 0) {
privs = wins_get_private_chats(NULL);
} else {
2020-07-07 12:18:57 +00:00
GList* curr = orphaned_privchats;
2016-01-31 19:38:06 +00:00
while (curr) {
privs = g_list_append(privs, curr->data);
curr = g_list_next(curr);
}
}
2016-01-24 01:30:02 +00:00
if (privs || prefs_get_boolean(PREF_ROSTER_EMPTY)) {
_rosterwin_private_header(layout, privs);
2016-01-24 01:30:02 +00:00
2020-07-07 12:18:57 +00:00
GList* curr = privs;
2016-01-24 01:30:02 +00:00
while (curr) {
2020-07-07 12:18:57 +00:00
ProfPrivateWin* privwin = curr->data;
2016-01-24 01:30:02 +00:00
win_sub_newline_lazy(layout->subwin);
2020-07-07 12:18:57 +00:00
GString* privmsg = g_string_new(" ");
2016-01-24 01:30:02 +00:00
int indent = prefs_get_roster_contact_indent();
int current_indent = 0;
if (indent > 0) {
current_indent += indent;
while (indent > 0) {
g_string_append(privmsg, " ");
indent--;
}
}
auto_gchar gchar* unreadpos = prefs_get_string(PREF_ROSTER_ROOMS_UNREAD);
2016-01-24 01:30:02 +00:00
if ((g_strcmp0(unreadpos, "before") == 0) && privwin->unread > 0) {
g_string_append_printf(privmsg, "(%d) ", privwin->unread);
}
auto_gchar gchar* ch = prefs_get_roster_private_char();
2016-01-24 02:28:22 +00:00
if (ch) {
2021-10-22 14:33:10 +00:00
g_string_append_printf(privmsg, "%s", ch);
2016-01-24 02:28:22 +00:00
}
2016-01-24 01:30:02 +00:00
g_string_append(privmsg, privwin->fulljid);
if ((g_strcmp0(unreadpos, "after") == 0) && privwin->unread > 0) {
g_string_append_printf(privmsg, " (%d)", privwin->unread);
}
auto_jid Jid* jidp = jid_create(privwin->fulljid);
2020-07-07 12:18:57 +00:00
Occupant* occupant = muc_roster_item(jidp->barejid, jidp->resourcepart);
2020-07-07 12:18:57 +00:00
const char* presence = "offline";
if (occupant) {
presence = string_from_resource_presence(occupant->presence);
}
theme_item_t colour;
2016-01-24 01:30:02 +00:00
if (privwin->unread > 0) {
colour = _get_roster_theme(ROSTER_CONTACT_UNREAD, presence);
2016-01-24 01:30:02 +00:00
} else {
colour = _get_roster_theme(ROSTER_CONTACT_ACTIVE, presence);
2016-01-24 01:30:02 +00:00
}
gboolean wrap = prefs_get_boolean(PREF_ROSTER_WRAP);
2016-01-24 01:30:02 +00:00
wattron(layout->subwin, theme_attrs(colour));
win_sub_print(layout->subwin, privmsg->str, FALSE, wrap, current_indent);
wattroff(layout->subwin, theme_attrs(colour));
2016-01-24 01:30:02 +00:00
g_string_free(privmsg, TRUE);
curr = g_list_next(curr);
}
g_list_free(privs);
}
}
2016-01-30 23:11:31 +00:00
static theme_item_t
2020-07-07 12:18:57 +00:00
_get_roster_theme(roster_contact_theme_t theme_type, const char* presence)
2016-01-02 01:22:19 +00:00
{
2016-01-30 23:11:31 +00:00
switch (theme_type) {
2020-07-07 12:18:57 +00:00
case ROSTER_CONTACT:
return theme_roster_presence_attrs(presence);
case ROSTER_CONTACT_ACTIVE:
return theme_roster_active_presence_attrs(presence);
case ROSTER_CONTACT_UNREAD:
return theme_roster_unread_presence_attrs(presence);
default:
return theme_roster_presence_attrs(presence);
2016-01-24 01:30:02 +00:00
}
2016-01-02 01:22:19 +00:00
}
2016-01-30 23:11:31 +00:00
static int
2020-07-07 12:18:57 +00:00
_compare_rooms_name(ProfMucWin* a, ProfMucWin* b)
2016-01-30 22:54:52 +00:00
{
2016-01-30 23:11:31 +00:00
return g_strcmp0(a->roomjid, b->roomjid);
2016-01-30 22:54:52 +00:00
}
2016-01-30 23:11:31 +00:00
static int
2020-07-07 12:18:57 +00:00
_compare_rooms_unread(ProfMucWin* a, ProfMucWin* b)
2014-12-16 23:00:05 +00:00
{
2016-01-30 23:11:31 +00:00
if (a->unread > b->unread) {
return -1;
} else if (a->unread == b->unread) {
return g_strcmp0(a->roomjid, b->roomjid);
} else {
return 1;
2016-01-02 01:29:12 +00:00
}
2015-06-15 18:26:28 +00:00
}
2016-02-07 00:49:48 +00:00
static void
2020-07-07 12:18:57 +00:00
_rosterwin_unsubscribed_header(ProfLayoutSplit* layout, GList* wins)
2016-02-07 00:49:48 +00:00
{
win_sub_newline_lazy(layout->subwin);
2016-02-07 00:49:48 +00:00
2020-07-07 12:18:57 +00:00
GString* header = g_string_new(" ");
auto_gchar gchar* ch = prefs_get_roster_header_char();
2016-02-07 00:49:48 +00:00
if (ch) {
g_string_append_printf(header, "%s", ch);
2016-02-07 00:49:48 +00:00
}
g_string_append(header, "Unsubscribed");
auto_gchar gchar* countpref = prefs_get_string(PREF_ROSTER_COUNT);
2016-02-07 00:49:48 +00:00
if (g_strcmp0(countpref, "items") == 0) {
int itemcount = g_list_length(wins);
if (itemcount == 0 && prefs_get_boolean(PREF_ROSTER_COUNT_ZERO)) {
g_string_append_printf(header, " (%d)", itemcount);
} else {
g_string_append_printf(header, " (%d)", itemcount);
}
} else if (g_strcmp0(countpref, "unread") == 0) {
int unreadcount = 0;
2020-07-07 12:18:57 +00:00
GList* curr = wins;
2016-02-07 00:49:48 +00:00
while (curr) {
2020-07-07 12:18:57 +00:00
ProfChatWin* chatwin = curr->data;
2016-02-07 00:49:48 +00:00
unreadcount += chatwin->unread;
curr = g_list_next(curr);
}
if (unreadcount == 0 && prefs_get_boolean(PREF_ROSTER_COUNT_ZERO)) {
g_string_append_printf(header, " (%d)", unreadcount);
} else if (unreadcount > 0) {
g_string_append_printf(header, " (%d)", unreadcount);
}
}
gboolean wrap = prefs_get_boolean(PREF_ROSTER_WRAP);
wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
win_sub_print(layout->subwin, header->str, FALSE, wrap, 1);
wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
g_string_free(header, TRUE);
}
static void
2020-07-07 12:18:57 +00:00
_rosterwin_contacts_header(ProfLayoutSplit* layout, const char* const title, GSList* contacts)
{
win_sub_newline_lazy(layout->subwin);
2020-07-07 12:18:57 +00:00
GString* header = g_string_new(" ");
auto_gchar gchar* ch = prefs_get_roster_header_char();
if (ch) {
g_string_append_printf(header, "%s", ch);
}
g_string_append(header, title);
auto_gchar gchar* countpref = prefs_get_string(PREF_ROSTER_COUNT);
if (g_strcmp0(countpref, "items") == 0) {
int itemcount = g_slist_length(contacts);
if (itemcount == 0 && prefs_get_boolean(PREF_ROSTER_COUNT_ZERO)) {
g_string_append_printf(header, " (%d)", itemcount);
} else {
g_string_append_printf(header, " (%d)", itemcount);
}
} else if (g_strcmp0(countpref, "unread") == 0) {
int unreadcount = 0;
2020-07-07 12:18:57 +00:00
GSList* curr = contacts;
while (curr) {
PContact contact = curr->data;
2020-07-07 12:18:57 +00:00
const char* barejid = p_contact_barejid(contact);
ProfChatWin* chatwin = wins_get_chat(barejid);
if (chatwin) {
unreadcount += chatwin->unread;
}
curr = g_slist_next(curr);
}
if (unreadcount == 0 && prefs_get_boolean(PREF_ROSTER_COUNT_ZERO)) {
g_string_append_printf(header, " (%d)", unreadcount);
} else if (unreadcount > 0) {
g_string_append_printf(header, " (%d)", unreadcount);
}
}
gboolean wrap = prefs_get_boolean(PREF_ROSTER_WRAP);
if (layout->subwin != NULL) {
wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
win_sub_print(layout->subwin, header->str, FALSE, wrap, 1);
wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
}
g_string_free(header, TRUE);
}
static void
2020-07-07 12:18:57 +00:00
_rosterwin_rooms_header(ProfLayoutSplit* layout, GList* rooms, char* title)
{
win_sub_newline_lazy(layout->subwin);
2020-07-07 12:18:57 +00:00
GString* header = g_string_new(" ");
auto_gchar gchar* ch = prefs_get_roster_header_char();
if (ch) {
g_string_append_printf(header, "%s", ch);
}
g_string_append(header, title);
auto_gchar gchar* countpref = prefs_get_string(PREF_ROSTER_COUNT);
if (g_strcmp0(countpref, "items") == 0) {
int count = g_list_length(rooms);
if (count == 0 && prefs_get_boolean(PREF_ROSTER_COUNT_ZERO)) {
g_string_append_printf(header, " (%d)", count);
} else if (count > 0) {
g_string_append_printf(header, " (%d)", count);
}
} else if (g_strcmp0(countpref, "unread") == 0) {
int unread = 0;
2020-07-07 12:18:57 +00:00
GList* curr = rooms;
while (curr) {
2020-07-07 12:18:57 +00:00
ProfMucWin* mucwin = curr->data;
unread += mucwin->unread;
// include private chats
auto_gchar gchar* prefpriv = prefs_get_string(PREF_ROSTER_PRIVATE);
if (g_strcmp0(prefpriv, "room") == 0) {
2020-07-07 12:18:57 +00:00
GList* privwins = wins_get_private_chats(mucwin->roomjid);
GList* curr_priv = privwins;
while (curr_priv) {
2020-07-07 12:18:57 +00:00
ProfPrivateWin* privwin = curr_priv->data;
unread += privwin->unread;
curr_priv = g_list_next(curr_priv);
}
g_list_free(privwins);
}
curr = g_list_next(curr);
}
if (unread == 0 && prefs_get_boolean(PREF_ROSTER_COUNT_ZERO)) {
g_string_append_printf(header, " (%d)", unread);
} else if (unread > 0) {
g_string_append_printf(header, " (%d)", unread);
}
}
gboolean wrap = prefs_get_boolean(PREF_ROSTER_WRAP);
if (layout->subwin != NULL) {
wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
win_sub_print(layout->subwin, header->str, FALSE, wrap, 1);
wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
}
g_string_free(header, TRUE);
}
static void
2020-07-07 12:18:57 +00:00
_rosterwin_private_header(ProfLayoutSplit* layout, GList* privs)
{
win_sub_newline_lazy(layout->subwin);
2020-07-07 12:18:57 +00:00
GString* title_str = g_string_new(" ");
auto_gchar gchar* ch = prefs_get_roster_header_char();
if (ch) {
g_string_append_printf(title_str, "%s", ch);
}
g_string_append(title_str, "Private chats");
auto_gchar gchar* countpref = prefs_get_string(PREF_ROSTER_COUNT);
if (g_strcmp0(countpref, "items") == 0) {
int itemcount = g_list_length(privs);
if (itemcount == 0 && prefs_get_boolean(PREF_ROSTER_COUNT_ZERO)) {
g_string_append_printf(title_str, " (%d)", itemcount);
} else if (itemcount > 0) {
g_string_append_printf(title_str, " (%d)", itemcount);
}
} else if (g_strcmp0(countpref, "unread") == 0) {
int unreadcount = 0;
2020-07-07 12:18:57 +00:00
GList* curr = privs;
while (curr) {
2020-07-07 12:18:57 +00:00
ProfPrivateWin* privwin = curr->data;
unreadcount += privwin->unread;
curr = g_list_next(curr);
}
if (unreadcount == 0 && prefs_get_boolean(PREF_ROSTER_COUNT_ZERO)) {
g_string_append_printf(title_str, " (%d)", unreadcount);
} else if (unreadcount > 0) {
g_string_append_printf(title_str, " (%d)", unreadcount);
}
}
gboolean wrap = prefs_get_boolean(PREF_ROSTER_WRAP);
wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
win_sub_print(layout->subwin, title_str->str, FALSE, wrap, 1);
wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
g_string_free(title_str, TRUE);
}
2016-01-31 02:27:02 +00:00
static GSList*
2020-07-07 12:18:57 +00:00
_filter_contacts(GSList* contacts)
2016-01-31 02:27:02 +00:00
{
2020-07-07 12:18:57 +00:00
GSList* filtered_contacts = NULL;
2016-01-31 02:27:02 +00:00
// if show offline, include all contacts
if (prefs_get_boolean(PREF_ROSTER_OFFLINE)) {
2020-07-07 12:18:57 +00:00
GSList* curr = contacts;
2016-01-31 02:27:02 +00:00
while (curr) {
filtered_contacts = g_slist_append(filtered_contacts, curr->data);
curr = g_slist_next(curr);
}
2020-07-07 12:18:57 +00:00
// if dont show offline
2016-01-31 02:27:02 +00:00
} else {
2020-07-07 12:18:57 +00:00
GSList* curr = contacts;
while (curr) {
PContact contact = curr->data;
2020-07-07 12:18:57 +00:00
const char* presence = p_contact_presence(contact);
2016-01-31 02:27:02 +00:00
// include if offline and unread messages
if (g_strcmp0(presence, "offline") == 0) {
2020-07-07 12:18:57 +00:00
ProfChatWin* chatwin = wins_get_chat(p_contact_barejid(contact));
if (chatwin && chatwin->unread > 0) {
2016-01-31 02:27:02 +00:00
filtered_contacts = g_slist_append(filtered_contacts, contact);
}
2020-07-07 12:18:57 +00:00
// include if not offline
} else {
filtered_contacts = g_slist_append(filtered_contacts, contact);
2016-01-31 02:27:02 +00:00
}
curr = g_slist_next(curr);
2016-01-31 02:27:02 +00:00
}
}
return filtered_contacts;
}
static GSList*
2020-07-07 12:18:57 +00:00
_filter_contacts_with_presence(GSList* contacts, const char* const presence)
2016-01-31 02:27:02 +00:00
{
2020-07-07 12:18:57 +00:00
GSList* filtered_contacts = NULL;
2016-01-31 02:27:02 +00:00
// handling offline contacts
if (g_strcmp0(presence, "offline") == 0) {
// if show offline, include all contacts
if (prefs_get_boolean(PREF_ROSTER_OFFLINE)) {
2020-07-07 12:18:57 +00:00
GSList* curr = contacts;
2016-01-31 02:27:02 +00:00
while (curr) {
filtered_contacts = g_slist_append(filtered_contacts, curr->data);
curr = g_slist_next(curr);
}
2020-07-07 12:18:57 +00:00
// otherwise show if unread messages
} else {
2020-07-07 12:18:57 +00:00
GSList* curr = contacts;
2016-01-31 02:27:02 +00:00
while (curr) {
PContact contact = curr->data;
2020-07-07 12:18:57 +00:00
ProfChatWin* chatwin = wins_get_chat(p_contact_barejid(contact));
2016-01-31 02:27:02 +00:00
if (chatwin && chatwin->unread > 0) {
filtered_contacts = g_slist_append(filtered_contacts, contact);
}
curr = g_slist_next(curr);
}
}
2020-07-07 12:18:57 +00:00
// any other presence, include all
2016-01-31 02:27:02 +00:00
} else {
2020-07-07 12:18:57 +00:00
GSList* curr = contacts;
2016-01-31 02:27:02 +00:00
while (curr) {
filtered_contacts = g_slist_append(filtered_contacts, curr->data);
curr = g_slist_next(curr);
}
}
return filtered_contacts;
}