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*
|
char*
|
||||||
api_get_name_from_roster(const char* barejid)
|
api_get_name_from_roster(const char* barejid)
|
||||||
{
|
{
|
||||||
return roster_get_display_name(barejid);
|
return strdup(roster_get_display_name(barejid));
|
||||||
}
|
}
|
||||||
|
|
||||||
char*
|
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);
|
char* barejid_str = python_str_or_unicode_to_string(barejid);
|
||||||
|
|
||||||
allow_python_threads();
|
allow_python_threads();
|
||||||
char* name = roster_get_display_name(barejid_str);
|
char* name = strdup(roster_get_display_name(barejid_str));
|
||||||
free(barejid_str);
|
free(barejid_str);
|
||||||
disable_python_threads();
|
disable_python_threads();
|
||||||
if (name) {
|
if (name) {
|
||||||
|
@ -295,19 +295,7 @@ chatwin_recipient_gone(ProfChatWin* chatwin)
|
|||||||
{
|
{
|
||||||
assert(chatwin != NULL);
|
assert(chatwin != NULL);
|
||||||
|
|
||||||
const char* display_usr = NULL;
|
win_println((ProfWin*)chatwin, THEME_GONE, "!", "<- %s has left the conversation.", roster_get_display_name(chatwin->barejid));
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -267,20 +267,7 @@ cons_show_tlscert(const TLSCertificate* cert)
|
|||||||
void
|
void
|
||||||
cons_show_typing(const char* const barejid)
|
cons_show_typing(const char* const barejid)
|
||||||
{
|
{
|
||||||
ProfWin* console = wins_get_console();
|
win_println(wins_get_console(), THEME_TYPING, "-", "!! %s is typing a message…", roster_get_display_name(barejid));
|
||||||
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);
|
|
||||||
cons_alert(NULL);
|
cons_alert(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -925,17 +912,7 @@ cons_show_status(const char* const barejid)
|
|||||||
void
|
void
|
||||||
cons_show_room_invite(const char* const invitor, const char* const room, const char* const reason)
|
cons_show_room_invite(const char* const invitor, const char* const room, const char* const reason)
|
||||||
{
|
{
|
||||||
auto_char char* display_from = NULL;
|
const char* display_from = roster_get_display_name(invitor);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
cons_show("");
|
cons_show("");
|
||||||
cons_show("Chat room invite received:");
|
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);
|
is_current = wins_is_current(window);
|
||||||
}
|
}
|
||||||
if (!is_current || (is_current && prefs_get_boolean(PREF_NOTIFY_TYPING_CURRENT))) {
|
if (!is_current || (is_current && prefs_get_boolean(PREF_NOTIFY_TYPING_CURRENT))) {
|
||||||
PContact contact = roster_get_contact(barejid);
|
notify_typing(roster_get_display_name(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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -192,6 +192,8 @@ p_contact_barejid_collate_key(const PContact contact)
|
|||||||
const char*
|
const char*
|
||||||
p_contact_name(const PContact contact)
|
p_contact_name(const PContact contact)
|
||||||
{
|
{
|
||||||
|
if (!contact)
|
||||||
|
return NULL;
|
||||||
return contact->name;
|
return contact->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,25 +183,12 @@ roster_get_contact(const char* const barejid)
|
|||||||
return contact;
|
return contact;
|
||||||
}
|
}
|
||||||
|
|
||||||
char*
|
const char*
|
||||||
roster_get_display_name(const char* const barejid)
|
roster_get_display_name(const char* const barejid)
|
||||||
{
|
{
|
||||||
assert(roster != NULL);
|
assert(roster != NULL);
|
||||||
|
|
||||||
GString* result = g_string_new("");
|
return p_contact_name(roster_get_contact(barejid)) ?: barejid;
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gchar*
|
gchar*
|
||||||
@ -215,25 +202,12 @@ roster_get_msg_display_name(const char* const barejid, const char* const resourc
|
|||||||
return incoming_str;
|
return incoming_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
GString* result = g_string_new("");
|
const char* contact_name = roster_get_display_name(barejid);
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (resource && prefs_get_boolean(PREF_RESOURCE_MESSAGE)) {
|
if (resource && prefs_get_boolean(PREF_RESOURCE_MESSAGE)) {
|
||||||
g_string_append(result, "/");
|
return g_strdup_printf("%s/%s", contact_name, resource);
|
||||||
g_string_append(result, resource);
|
|
||||||
}
|
}
|
||||||
|
return g_strdup(contact_name);
|
||||||
return g_string_free(result, FALSE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
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_group_autocomplete(const char* const search_str, gboolean previous, void* context);
|
||||||
char* roster_barejid_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);
|
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);
|
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_name(PContact a, PContact b);
|
||||||
gint roster_compare_presence(PContact a, PContact b);
|
gint roster_compare_presence(PContact a, PContact b);
|
||||||
|
Loading…
Reference in New Issue
Block a user