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

Show resource in titlebar and on each message

This commit is contained in:
James Booth 2015-01-10 18:35:59 +00:00
parent 3e1832b02e
commit c3ad3c0ba6
7 changed files with 39 additions and 25 deletions

@ -297,7 +297,7 @@ handle_incoming_private_message(char *fulljid, char *message)
} }
void void
handle_incoming_message(char *barejid, char *message) handle_incoming_message(char *barejid, char *resource, char *message)
{ {
#ifdef HAVE_LIBOTR #ifdef HAVE_LIBOTR
gboolean was_decrypted = FALSE; gboolean was_decrypted = FALSE;
@ -336,7 +336,7 @@ handle_incoming_message(char *barejid, char *message)
message_send_chat(barejid, otr_query_message); message_send_chat(barejid, otr_query_message);
} }
ui_incoming_msg(barejid, newmessage, NULL); ui_incoming_msg(barejid, resource, newmessage, NULL);
if (prefs_get_boolean(PREF_CHLOG)) { if (prefs_get_boolean(PREF_CHLOG)) {
const char *jid = jabber_get_fulljid(); const char *jid = jabber_get_fulljid();
@ -355,7 +355,7 @@ handle_incoming_message(char *barejid, char *message)
otr_free_message(newmessage); otr_free_message(newmessage);
#else #else
ui_incoming_msg(barejid, message, NULL); ui_incoming_msg(barejid, resource, message, NULL);
if (prefs_get_boolean(PREF_CHLOG)) { if (prefs_get_boolean(PREF_CHLOG)) {
const char *jid = jabber_get_fulljid(); const char *jid = jabber_get_fulljid();
@ -375,7 +375,7 @@ handle_delayed_private_message(char *fulljid, char *message, GTimeVal tv_stamp)
void void
handle_delayed_message(char *barejid, char *message, GTimeVal tv_stamp) handle_delayed_message(char *barejid, char *message, GTimeVal tv_stamp)
{ {
ui_incoming_msg(barejid, message, &tv_stamp); ui_incoming_msg(barejid, NULL, message, &tv_stamp);
if (prefs_get_boolean(PREF_CHLOG)) { if (prefs_get_boolean(PREF_CHLOG)) {
const char *jid = jabber_get_fulljid(); const char *jid = jabber_get_fulljid();

@ -69,7 +69,7 @@ void handle_room_role_list(const char * const from, const char * const role, GSL
void handle_room_role_set_error(const char * const room, const char * const nick, const char * const role, void handle_room_role_set_error(const char * const room, const char * const nick, const char * const role,
const char * const error); const char * const error);
void handle_room_kick_result_error(const char * const room, const char * const nick, const char * const error); void handle_room_kick_result_error(const char * const room, const char * const nick, const char * const error);
void handle_incoming_message(char *barejid, char *message); void handle_incoming_message(char *barejid, char *resource, char *message);
void handle_incoming_private_message(char *fulljid, char *message); void handle_incoming_private_message(char *fulljid, char *message);
void handle_delayed_message(char *fulljid, char *message, GTimeVal tv_stamp); void handle_delayed_message(char *fulljid, char *message, GTimeVal tv_stamp);
void handle_delayed_private_message(char *fulljid, char *message, GTimeVal tv_stamp); void handle_delayed_private_message(char *fulljid, char *message, GTimeVal tv_stamp);

@ -328,20 +328,25 @@ ui_get_current_chat(void)
} }
void void
ui_incoming_msg(const char * const barejid, 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;
char *display_from = NULL; GString *user = g_string_new("");
PContact contact = roster_get_contact(barejid); PContact contact = roster_get_contact(barejid);
if (contact != NULL) { if (contact != NULL) {
if (p_contact_name(contact) != NULL) { if (p_contact_name(contact) != NULL) {
display_from = strdup(p_contact_name(contact)); g_string_append(user, p_contact_name(contact));
} else { } else {
display_from = strdup(barejid); g_string_append(user, barejid);
} }
} else { } else {
display_from = strdup(barejid); g_string_append(user,barejid);
}
if (resource) {
g_string_append(user, "/");
g_string_append(user, resource);
} }
ProfChatWin *chatwin = wins_get_chat(barejid); ProfChatWin *chatwin = wins_get_chat(barejid);
@ -362,14 +367,14 @@ ui_incoming_msg(const char * const barejid, const char * const message, GTimeVal
// 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, display_from, message); win_print_incoming_message(window, tv_stamp, user->str, 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(display_from, num); cons_show_incoming_message(user->str, num);
if (prefs_get_boolean(PREF_FLASH)) { if (prefs_get_boolean(PREF_FLASH)) {
flash(); flash();
@ -388,7 +393,7 @@ ui_incoming_msg(const char * const barejid, const char * const message, GTimeVal
} }
} }
win_print_incoming_message(window, tv_stamp, display_from, message); win_print_incoming_message(window, tv_stamp, user->str, message);
} }
int ui_index = num; int ui_index = num;
@ -404,14 +409,14 @@ ui_incoming_msg(const char * const barejid, const char * const message, GTimeVal
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(display_from, ui_index, message); notify_message(user->str, ui_index, message);
} else { } else {
notify_message(display_from, ui_index, NULL); notify_message(user->str, ui_index, NULL);
} }
} }
} }
free(display_from); g_string_free(user, TRUE);
} }
void void

@ -47,6 +47,7 @@
#include "ui/windows.h" #include "ui/windows.h"
#include "ui/window.h" #include "ui/window.h"
#include "roster_list.h" #include "roster_list.h"
#include "chat_session.h"
static WINDOW *win; static WINDOW *win;
static contact_presence_t current_presence; static contact_presence_t current_presence;
@ -307,9 +308,17 @@ static void
_show_contact_presence(ProfChatWin *chatwin) _show_contact_presence(ProfChatWin *chatwin)
{ {
int bracket_attrs = theme_attrs(THEME_TITLE_BRACKET); int bracket_attrs = theme_attrs(THEME_TITLE_BRACKET);
if (chatwin && chatwin->resource_override) { char *resource = NULL;
ChatSession *session = chat_session_get(chatwin->barejid);
if (chatwin->resource_override) {
resource = chatwin->resource_override;
} else if (session && session->resource) {
resource = session->resource;
}
if (resource) {
wprintw(win, "/"); wprintw(win, "/");
wprintw(win, chatwin->resource_override); wprintw(win, resource);
} }
if (prefs_get_boolean(PREF_PRESENCE)) { if (prefs_get_boolean(PREF_PRESENCE)) {
@ -318,10 +327,10 @@ _show_contact_presence(ProfChatWin *chatwin)
PContact contact = roster_get_contact(chatwin->barejid); PContact contact = roster_get_contact(chatwin->barejid);
if (contact) { if (contact) {
if (chatwin && chatwin->resource_override) { if (resource) {
Resource *resource = p_contact_get_resource(contact, chatwin->resource_override); Resource *resourcep = p_contact_get_resource(contact, resource);
if (resource) { if (resourcep) {
presence = string_from_resource_presence(resource->presence); presence = string_from_resource_presence(resourcep->presence);
} }
} else { } else {
presence = p_contact_presence(contact); presence = p_contact_presence(contact);

@ -116,7 +116,7 @@ void ui_handle_stanza(const char * const msg);
// ui events // ui events
void ui_contact_typing(const char * const from); void ui_contact_typing(const char * const from);
void ui_incoming_msg(const char * const from, const char * const message, GTimeVal *tv_stamp); void ui_incoming_msg(const char * const from, const char * const resource, const char * const message, GTimeVal *tv_stamp);
void ui_incoming_private_msg(const char * const fulljid, const char * const message, GTimeVal *tv_stamp); void ui_incoming_private_msg(const char * const fulljid, const char * const message, GTimeVal *tv_stamp);
void ui_disconnected(void); void ui_disconnected(void);

@ -499,7 +499,7 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
if (delayed) { if (delayed) {
handle_delayed_message(jid->barejid, message, tv_stamp); handle_delayed_message(jid->barejid, message, tv_stamp);
} else { } else {
handle_incoming_message(jid->barejid, message); handle_incoming_message(jid->barejid, jid->resourcepart, message);
} }
xmpp_free(ctx, message); xmpp_free(ctx, message);
} }

@ -189,7 +189,7 @@ void ui_handle_stanza(const char * const msg) {}
// ui events // ui events
void ui_contact_typing(const char * const from) {} void ui_contact_typing(const char * const from) {}
void ui_incoming_msg(const char * const from, const char * const message, GTimeVal *tv_stamp) {} void ui_incoming_msg(const char * const from, const char * const resource, const char * const message, GTimeVal *tv_stamp) {}
void ui_incoming_private_msg(const char * const fulljid, const char * const message, GTimeVal *tv_stamp) {} void ui_incoming_private_msg(const char * const fulljid, const char * const message, GTimeVal *tv_stamp) {}
void ui_disconnected(void) {} void ui_disconnected(void) {}