1
1
mirror of https://github.com/profanity-im/profanity.git synced 2025-02-02 15:08:15 -05:00

Added p_contact_create_display_string

This commit is contained in:
James Booth 2013-10-07 00:16:58 +01:00
parent 9bea1ce830
commit 383d91ec36
3 changed files with 34 additions and 38 deletions

View File

@ -166,6 +166,31 @@ p_contact_name_or_jid(const PContact contact)
}
}
char *
p_contact_create_display_string(const PContact contact, const char * const resource)
{
GString *result_str = g_string_new("");
// use nickname if exists
if (contact->name != NULL) {
g_string_append(result_str, contact->name);
} else {
g_string_append(result_str, contact->barejid);
}
// add resource if not default provided by profanity
if (strcmp(resource, "__prof_default") != 0) {
g_string_append(result_str, " (");
g_string_append(result_str, resource);
g_string_append(result_str, ")");
}
char *result = result_str->str;
g_string_free(result_str, FALSE);
return result;
}
static Resource *
_highest_presence(Resource *first, Resource *second)
{

View File

@ -55,5 +55,6 @@ void p_contact_set_groups(const PContact contact, GSList *groups);
GSList * p_contact_groups(const PContact contact);
gboolean p_contact_in_group(const PContact contact, const char * const group);
gboolean p_contact_subscribed(const PContact contact);
char * p_contact_create_display_string(const PContact contact, const char * const resource);
#endif

View File

@ -377,36 +377,20 @@ void
ui_contact_online(const char * const barejid, const char * const resource,
const char * const show, const char * const status, GDateTime *last_activity)
{
Jid *jid = jid_create_from_bare_and_resource(barejid, resource);
PContact contact = roster_get_contact(barejid);
GString *display_str = g_string_new("");
// use nickname if exists
if (p_contact_name(contact) != NULL) {
g_string_append(display_str, p_contact_name(contact));
} else {
g_string_append(display_str, barejid);
}
// add resource if not default provided by profanity
if (strcmp(jid->resourcepart, "__prof_default") != 0) {
g_string_append(display_str, " (");
g_string_append(display_str, jid->resourcepart);
g_string_append(display_str, ")");
}
char *display_str = p_contact_create_display_string(contact, resource);
ProfWin *console = wins_get_console();
win_show_status_string(console, display_str->str, show, status, last_activity,
win_show_status_string(console, display_str, show, status, last_activity,
"++", "online");
ProfWin *window = wins_get_by_recipient(barejid);
if (window != NULL) {
win_show_status_string(window, display_str->str, show, status,
win_show_status_string(window, display_str, show, status,
last_activity, "++", "online");
}
jid_destroy(jid);
g_string_free(display_str, TRUE);
free(display_str);
if (wins_is_current(console)) {
wins_refresh_current();
@ -421,34 +405,20 @@ ui_contact_offline(const char * const from, const char * const show,
{
Jid *jidp = jid_create(from);
PContact contact = roster_get_contact(jidp->barejid);
GString *display_str = g_string_new("");
// use nickname if exists
if (p_contact_name(contact) != NULL) {
g_string_append(display_str, p_contact_name(contact));
} else {
g_string_append(display_str, jidp->barejid);
}
// add resource if not default provided by profanity
if (strcmp(jidp->resourcepart, "__prof_default") != 0) {
g_string_append(display_str, " (");
g_string_append(display_str, jidp->resourcepart);
g_string_append(display_str, ")");
}
char *display_str = p_contact_create_display_string(contact, jidp->resourcepart);
ProfWin *console = wins_get_console();
win_show_status_string(console, display_str->str, show, status, NULL, "--",
win_show_status_string(console, display_str, show, status, NULL, "--",
"offline");
ProfWin *window = wins_get_by_recipient(jidp->barejid);
if (window != NULL) {
win_show_status_string(window, display_str->str, show, status, NULL, "--",
win_show_status_string(window, display_str, show, status, NULL, "--",
"offline");
}
jid_destroy(jidp);
g_string_free(display_str, TRUE);
free(display_str);
if (wins_is_current(console)) {
wins_refresh_current();