1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Added roster list function to get display name for messages

This commit is contained in:
James Booth 2015-05-03 23:38:46 +01:00
parent ff867e7f2b
commit c3d2a7e937
3 changed files with 37 additions and 24 deletions

View File

@ -42,6 +42,7 @@
#include "contact.h" #include "contact.h"
#include "jid.h" #include "jid.h"
#include "tools/autocomplete.h" #include "tools/autocomplete.h"
#include "config/preferences.h"
// nicknames // nicknames
static Autocomplete name_ac; static Autocomplete name_ac;
@ -116,6 +117,33 @@ roster_get_contact(const char * const barejid)
return contact; return contact;
} }
char *
roster_get_msg_display_name(const char * const barejid, const char * const resource)
{
GString *result = g_string_new("");
PContact contact = roster_get_contact(barejid);
if (contact != NULL) {
if (p_contact_name(contact) != NULL) {
g_string_append(result, p_contact_name(contact));
} else {
g_string_append(result, barejid);
}
} else {
g_string_append(result, barejid);
}
if (resource && prefs_get_boolean(PREF_RESOURCE_MESSAGE)) {
g_string_append(result, "/");
g_string_append(result, resource);
}
char *result_str = result->str;
g_string_free(result, FALSE);
return result_str;
}
gboolean gboolean
roster_contact_offline(const char * const barejid, roster_contact_offline(const char * const barejid,
const char * const resource, const char * const status) const char * const resource, const char * const status)

View File

@ -67,5 +67,6 @@ char * roster_group_autocomplete(const char * const search_str);
char * roster_barejid_autocomplete(const char * const search_str); char * roster_barejid_autocomplete(const char * const search_str);
GSList * roster_get_contacts_by_presence(const char * const presence); GSList * roster_get_contacts_by_presence(const char * const presence);
GSList * roster_get_nogroup(void); GSList * roster_get_nogroup(void);
char * roster_get_msg_display_name(const char * const barejid, const char * const resource);
#endif #endif

View File

@ -389,23 +389,6 @@ void
ui_incoming_msg(const char * const barejid, const char * const resource, const char * const message, GTimeVal *tv_stamp) ui_incoming_msg(const char * const barejid, const char * const resource, const char * const message, GTimeVal *tv_stamp)
{ {
gboolean win_created = FALSE; gboolean win_created = FALSE;
GString *user = g_string_new("");
PContact contact = roster_get_contact(barejid);
if (contact != NULL) {
if (p_contact_name(contact) != NULL) {
g_string_append(user, p_contact_name(contact));
} else {
g_string_append(user, barejid);
}
} else {
g_string_append(user, barejid);
}
if (resource && prefs_get_boolean(PREF_RESOURCE_MESSAGE)) {
g_string_append(user, "/");
g_string_append(user, resource);
}
ProfChatWin *chatwin = wins_get_chat(barejid); ProfChatWin *chatwin = wins_get_chat(barejid);
if (chatwin == NULL) { if (chatwin == NULL) {
@ -415,19 +398,20 @@ ui_incoming_msg(const char * const barejid, const char * const resource, const c
} }
ProfWin *window = (ProfWin*) chatwin; ProfWin *window = (ProfWin*) chatwin;
int num = wins_get_num(window); int num = wins_get_num(window);
char *display_name = roster_get_msg_display_name(barejid, resource);
// currently viewing chat window with sender // currently viewing chat window with sender
if (wins_is_current(window)) { if (wins_is_current(window)) {
win_print_incoming_message(window, tv_stamp, user->str, message); win_print_incoming_message(window, tv_stamp, display_name, message);
title_bar_set_typing(FALSE); title_bar_set_typing(FALSE);
status_bar_active(num); status_bar_active(num);
// not currently viewing chat window with sender // not currently viewing chat window with sender
} else { } else {
status_bar_new(num); status_bar_new(num);
cons_show_incoming_message(user->str, num); cons_show_incoming_message(display_name, num);
if (prefs_get_boolean(PREF_FLASH)) { if (prefs_get_boolean(PREF_FLASH)) {
flash(); flash();
@ -446,7 +430,7 @@ ui_incoming_msg(const char * const barejid, const char * const resource, const c
} }
} }
win_print_incoming_message(window, tv_stamp, user->str, message); win_print_incoming_message(window, tv_stamp, display_name, message);
} }
int ui_index = num; int ui_index = num;
@ -462,14 +446,14 @@ ui_incoming_msg(const char * const barejid, const char * const resource, const c
gboolean is_current = wins_is_current(window); gboolean is_current = wins_is_current(window);
if ( !is_current || (is_current && prefs_get_boolean(PREF_NOTIFY_MESSAGE_CURRENT)) ) { if ( !is_current || (is_current && prefs_get_boolean(PREF_NOTIFY_MESSAGE_CURRENT)) ) {
if (prefs_get_boolean(PREF_NOTIFY_MESSAGE_TEXT)) { if (prefs_get_boolean(PREF_NOTIFY_MESSAGE_TEXT)) {
notify_message(user->str, ui_index, message); notify_message(display_name, ui_index, message);
} else { } else {
notify_message(user->str, ui_index, NULL); notify_message(display_name, ui_index, NULL);
} }
} }
} }
g_string_free(user, TRUE); free(display_name);
} }
void void