From 517bc30360627b34ab74cb679bfb1cf9a67f6630 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 5 Nov 2012 23:24:29 +0000 Subject: [PATCH] Handle sending messages in groupchat --- src/command.c | 6 +++++- src/jabber.c | 30 ++++++++++++++++++++++++++++++ src/jabber.h | 1 + src/windows.c | 25 ++++++++++++++++++------- 4 files changed, 54 insertions(+), 8 deletions(-) diff --git a/src/command.c b/src/command.c index 35fe72bb..62eea490 100644 --- a/src/command.c +++ b/src/command.c @@ -611,7 +611,11 @@ cmd_execute(const char * const command, const char * const inp) gboolean cmd_execute_default(const char * const inp) { - if (win_in_chat()) { + if (win_in_groupchat()) { + char *recipient = win_get_recipient(); + jabber_send_groupchat(inp, recipient); + free(recipient); + } else if (win_in_chat()) { char *recipient = win_get_recipient(); jabber_send(inp, recipient); diff --git a/src/jabber.c b/src/jabber.c index 14739bc1..3fe4a91e 100644 --- a/src/jabber.c +++ b/src/jabber.c @@ -186,6 +186,36 @@ jabber_send(const char * const msg, const char * const recipient) free(coded_msg3); } +void +jabber_send_groupchat(const char * const msg, const char * const recipient) +{ + char *coded_msg = str_replace(msg, "&", "&"); + char *coded_msg2 = str_replace(coded_msg, "<", "<"); + char *coded_msg3 = str_replace(coded_msg2, ">", ">"); + + xmpp_stanza_t *reply, *body, *text; + + reply = xmpp_stanza_new(jabber_conn.ctx); + xmpp_stanza_set_name(reply, "message"); + xmpp_stanza_set_type(reply, "groupchat"); + xmpp_stanza_set_attribute(reply, "to", recipient); + + body = xmpp_stanza_new(jabber_conn.ctx); + xmpp_stanza_set_name(body, "body"); + + text = xmpp_stanza_new(jabber_conn.ctx); + xmpp_stanza_set_text(text, coded_msg3); + + xmpp_stanza_add_child(body, text); + xmpp_stanza_add_child(reply, body); + + xmpp_send(jabber_conn.conn, reply); + xmpp_stanza_release(reply); + free(coded_msg); + free(coded_msg2); + free(coded_msg3); +} + void jabber_send_inactive(const char * const recipient) { diff --git a/src/jabber.h b/src/jabber.h index 8dacb2f8..ee9e49fc 100644 --- a/src/jabber.h +++ b/src/jabber.h @@ -48,6 +48,7 @@ void jabber_process_events(void); void jabber_subscribe(const char * const recipient); void jabber_join(const char * const room_jid, const char * const nick); void jabber_send(const char * const msg, const char * const recipient); +void jabber_send_groupchat(const char * const msg, const char * const recipient); void jabber_send_inactive(const char * const recipient); void jabber_send_composing(const char * const recipient); void jabber_send_paused(const char * const recipient); diff --git a/src/windows.c b/src/windows.c index 10613cdc..a6438779 100644 --- a/src/windows.c +++ b/src/windows.c @@ -536,7 +536,11 @@ win_show_room_message(const char * const room_jid, const char * const nick, WINDOW *win = _wins[win_index].win; _win_show_time(win); - _win_show_user(win, nick, 1); + if (strcmp(nick, room_get_nick_for_room(room_jid)) != 0) { + _win_show_user(win, nick, 1); + } else { + _win_show_user(win, nick, 0); + } _win_show_message(win, message); // currently in groupchat window @@ -552,18 +556,25 @@ win_show_room_message(const char * const room_jid, const char * const nick, dirty = TRUE; } - if (prefs_get_flash()) - flash(); + if (strcmp(nick, room_get_nick_for_room(room_jid)) != 0) { + if (prefs_get_flash()) { + flash(); + } + } _wins[win_index].unread++; } - if (prefs_get_beep()) - beep(); + if (strcmp(nick, room_get_nick_for_room(room_jid)) != 0) { + if (prefs_get_beep()) { + beep(); + } #ifdef HAVE_LIBNOTIFY - if (prefs_get_notify_message()) - _win_notify_message(nick); + if (prefs_get_notify_message()) { + _win_notify_message(nick); + } #endif + } } void