1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Allow incoming private messages from chat rooms

This commit is contained in:
James Booth 2012-11-12 23:26:09 +00:00
parent df094a7d2c
commit 13689a1f84
2 changed files with 27 additions and 20 deletions

View File

@ -466,6 +466,15 @@ _chat_message_handler(xmpp_stanza_t * const stanza)
char from_cpy[strlen(from) + 1];
strcpy(from_cpy, from);
char *short_from = strtok(from_cpy, "/");
char *jid = NULL;
// private message from chat room use full jid (room/nick)
if (room_is_active(short_from)) {
jid = strdup(from);
// standard chat message, use jid without resource
} else {
jid = strdup(short_from);
}
// determine chatstate support of recipient
gboolean recipient_supports = FALSE;
@ -474,10 +483,10 @@ _chat_message_handler(xmpp_stanza_t * const stanza)
}
// create or update chat session
if (!chat_session_exists(short_from)) {
chat_session_start(short_from, recipient_supports);
if (!chat_session_exists(jid)) {
chat_session_start(jid, recipient_supports);
} else {
chat_session_set_recipient_supports(short_from, recipient_supports);
chat_session_set_recipient_supports(jid, recipient_supports);
}
// determine if the notifications happened whilst offline
@ -487,10 +496,10 @@ _chat_message_handler(xmpp_stanza_t * const stanza)
if (recipient_supports && (delay == NULL)) {
if (xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_COMPOSING) != NULL) {
if (prefs_get_notify_typing() || prefs_get_intype()) {
prof_handle_typing(short_from);
prof_handle_typing(jid);
}
} else if (xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_GONE) != NULL) {
prof_handle_gone(short_from);
prof_handle_gone(jid);
} else if (xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_PAUSED) != NULL) {
// do something
} else if (xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_INACTIVE) != NULL) {
@ -510,16 +519,18 @@ _chat_message_handler(xmpp_stanza_t * const stanza)
if (g_time_val_from_iso8601(utc_stamp, &tv_stamp)) {
if (message != NULL) {
prof_handle_delayed_message(short_from, message, tv_stamp);
prof_handle_delayed_message(jid, message, tv_stamp);
}
} else {
log_error("Couldn't parse datetime string of historic message: %s", utc_stamp);
}
} else {
prof_handle_incoming_message(short_from, message);
prof_handle_incoming_message(jid, message);
}
}
g_free(jid);
return 1;
}

View File

@ -303,13 +303,9 @@ void
win_show_incomming_msg(const char * const from, const char * const message,
GTimeVal *tv_stamp)
{
char from_cpy[strlen(from) + 1];
strcpy(from_cpy, from);
char *short_from = strtok(from_cpy, "/");
int win_index = _find_prof_win_index(short_from);
int win_index = _find_prof_win_index(from);
if (win_index == NUM_WINS)
win_index = _new_prof_win(short_from, WIN_CHAT);
win_index = _new_prof_win(from, WIN_CHAT);
WINDOW *win = _wins[win_index].win;
@ -327,12 +323,12 @@ win_show_incomming_msg(const char * const from, const char * const message,
if (strncmp(message, "/me ", 4) == 0) {
wattron(win, COLOUR_ONLINE);
wprintw(win, "*%s ", short_from);
wprintw(win, "*%s ", from);
wprintw(win, message + 4);
wprintw(win, "\n");
wattroff(win, COLOUR_ONLINE);
} else {
_win_show_user(win, short_from, 1);
_win_show_user(win, from, 1);
_win_show_message(win, message);
}
title_bar_set_typing(FALSE);
@ -343,13 +339,13 @@ win_show_incomming_msg(const char * const from, const char * const message,
// not currently viewing chat window with sender
} else {
status_bar_new(win_index);
_cons_show_incoming_message(short_from, win_index);
_cons_show_incoming_message(from, win_index);
if (prefs_get_flash())
flash();
_wins[win_index].unread++;
if (prefs_get_chlog() && prefs_get_history()) {
_win_show_history(win, win_index, short_from);
_win_show_history(win, win_index, from);
}
if (tv_stamp == NULL) {
@ -364,12 +360,12 @@ win_show_incomming_msg(const char * const from, const char * const message,
if (strncmp(message, "/me ", 4) == 0) {
wattron(win, COLOUR_ONLINE);
wprintw(win, "*%s ", short_from);
wprintw(win, "*%s ", from);
wprintw(win, message + 4);
wprintw(win, "\n");
wattroff(win, COLOUR_ONLINE);
} else {
_win_show_user(win, short_from, 1);
_win_show_user(win, from, 1);
_win_show_message(win, message);
}
}
@ -378,7 +374,7 @@ win_show_incomming_msg(const char * const from, const char * const message,
beep();
#ifdef HAVE_LIBNOTIFY
if (prefs_get_notify_message())
_win_notify_message(short_from);
_win_notify_message(from);
#endif
}