mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Simplify usage of roster_get_display_name()
Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
This commit is contained in:
parent
71344fc4fd
commit
8f7ece0c40
@ -240,7 +240,7 @@ api_get_current_nick(void)
|
||||
char*
|
||||
api_get_name_from_roster(const char* barejid)
|
||||
{
|
||||
return roster_get_display_name(barejid);
|
||||
return strdup(roster_get_display_name(barejid));
|
||||
}
|
||||
|
||||
char*
|
||||
|
@ -452,7 +452,7 @@ python_api_get_name_from_roster(PyObject* self, PyObject* args)
|
||||
char* barejid_str = python_str_or_unicode_to_string(barejid);
|
||||
|
||||
allow_python_threads();
|
||||
char* name = roster_get_display_name(barejid_str);
|
||||
char* name = strdup(roster_get_display_name(barejid_str));
|
||||
free(barejid_str);
|
||||
disable_python_threads();
|
||||
if (name) {
|
||||
|
@ -295,19 +295,7 @@ chatwin_recipient_gone(ProfChatWin* chatwin)
|
||||
{
|
||||
assert(chatwin != NULL);
|
||||
|
||||
const char* display_usr = NULL;
|
||||
PContact contact = roster_get_contact(chatwin->barejid);
|
||||
if (contact) {
|
||||
if (p_contact_name(contact)) {
|
||||
display_usr = p_contact_name(contact);
|
||||
} else {
|
||||
display_usr = chatwin->barejid;
|
||||
}
|
||||
} else {
|
||||
display_usr = chatwin->barejid;
|
||||
}
|
||||
|
||||
win_println((ProfWin*)chatwin, THEME_GONE, "!", "<- %s has left the conversation.", display_usr);
|
||||
win_println((ProfWin*)chatwin, THEME_GONE, "!", "<- %s has left the conversation.", roster_get_display_name(chatwin->barejid));
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -267,20 +267,7 @@ cons_show_tlscert(const TLSCertificate* cert)
|
||||
void
|
||||
cons_show_typing(const char* const barejid)
|
||||
{
|
||||
ProfWin* console = wins_get_console();
|
||||
const char* display_usr = NULL;
|
||||
PContact contact = roster_get_contact(barejid);
|
||||
if (contact) {
|
||||
if (p_contact_name(contact)) {
|
||||
display_usr = p_contact_name(contact);
|
||||
} else {
|
||||
display_usr = barejid;
|
||||
}
|
||||
} else {
|
||||
display_usr = barejid;
|
||||
}
|
||||
|
||||
win_println(console, THEME_TYPING, "-", "!! %s is typing a message…", display_usr);
|
||||
win_println(wins_get_console(), THEME_TYPING, "-", "!! %s is typing a message…", roster_get_display_name(barejid));
|
||||
cons_alert(NULL);
|
||||
}
|
||||
|
||||
@ -925,17 +912,7 @@ cons_show_status(const char* const barejid)
|
||||
void
|
||||
cons_show_room_invite(const char* const invitor, const char* const room, const char* const reason)
|
||||
{
|
||||
auto_char char* display_from = NULL;
|
||||
PContact contact = roster_get_contact(invitor);
|
||||
if (contact) {
|
||||
if (p_contact_name(contact)) {
|
||||
display_from = strdup(p_contact_name(contact));
|
||||
} else {
|
||||
display_from = strdup(invitor);
|
||||
}
|
||||
} else {
|
||||
display_from = strdup(invitor);
|
||||
}
|
||||
const char* display_from = roster_get_display_name(invitor);
|
||||
|
||||
cons_show("");
|
||||
cons_show("Chat room invite received:");
|
||||
|
@ -299,18 +299,7 @@ ui_contact_typing(const char* const barejid, const char* const resource)
|
||||
is_current = wins_is_current(window);
|
||||
}
|
||||
if (!is_current || (is_current && prefs_get_boolean(PREF_NOTIFY_TYPING_CURRENT))) {
|
||||
PContact contact = roster_get_contact(barejid);
|
||||
char const* display_usr = NULL;
|
||||
if (contact) {
|
||||
if (p_contact_name(contact)) {
|
||||
display_usr = p_contact_name(contact);
|
||||
} else {
|
||||
display_usr = barejid;
|
||||
}
|
||||
} else {
|
||||
display_usr = barejid;
|
||||
}
|
||||
notify_typing(display_usr);
|
||||
notify_typing(roster_get_display_name(barejid));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -192,6 +192,8 @@ p_contact_barejid_collate_key(const PContact contact)
|
||||
const char*
|
||||
p_contact_name(const PContact contact)
|
||||
{
|
||||
if (!contact)
|
||||
return NULL;
|
||||
return contact->name;
|
||||
}
|
||||
|
||||
|
@ -183,25 +183,12 @@ roster_get_contact(const char* const barejid)
|
||||
return contact;
|
||||
}
|
||||
|
||||
char*
|
||||
const char*
|
||||
roster_get_display_name(const char* const barejid)
|
||||
{
|
||||
assert(roster != NULL);
|
||||
|
||||
GString* result = g_string_new("");
|
||||
|
||||
PContact contact = roster_get_contact(barejid);
|
||||
if (contact) {
|
||||
if (p_contact_name(contact)) {
|
||||
g_string_append(result, p_contact_name(contact));
|
||||
} else {
|
||||
g_string_append(result, barejid);
|
||||
}
|
||||
} else {
|
||||
g_string_append(result, barejid);
|
||||
}
|
||||
|
||||
return g_string_free(result, FALSE);
|
||||
return p_contact_name(roster_get_contact(barejid)) ?: barejid;
|
||||
}
|
||||
|
||||
gchar*
|
||||
@ -215,25 +202,12 @@ roster_get_msg_display_name(const char* const barejid, const char* const resourc
|
||||
return incoming_str;
|
||||
}
|
||||
|
||||
GString* result = g_string_new("");
|
||||
|
||||
PContact contact = roster_get_contact(barejid);
|
||||
if (contact) {
|
||||
if (p_contact_name(contact)) {
|
||||
g_string_append(result, p_contact_name(contact));
|
||||
} else {
|
||||
g_string_append(result, barejid);
|
||||
}
|
||||
} else {
|
||||
g_string_append(result, barejid);
|
||||
}
|
||||
const char* contact_name = roster_get_display_name(barejid);
|
||||
|
||||
if (resource && prefs_get_boolean(PREF_RESOURCE_MESSAGE)) {
|
||||
g_string_append(result, "/");
|
||||
g_string_append(result, resource);
|
||||
return g_strdup_printf("%s/%s", contact_name, resource);
|
||||
}
|
||||
|
||||
return g_string_free(result, FALSE);
|
||||
return g_strdup(contact_name);
|
||||
}
|
||||
|
||||
gboolean
|
||||
|
@ -70,7 +70,7 @@ GList* roster_get_groups(void);
|
||||
char* roster_group_autocomplete(const char* const search_str, gboolean previous, void* context);
|
||||
char* roster_barejid_autocomplete(const char* const search_str, gboolean previous, void* context);
|
||||
GSList* roster_get_contacts_by_presence(const char* const presence);
|
||||
char* roster_get_display_name(const char* const barejid);
|
||||
const char* roster_get_display_name(const char* const barejid);
|
||||
gchar* roster_get_msg_display_name(const char* const barejid, const char* const resource);
|
||||
gint roster_compare_name(PContact a, PContact b);
|
||||
gint roster_compare_presence(PContact a, PContact b);
|
||||
|
Loading…
Reference in New Issue
Block a user