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

Handle sending messages in groupchat

This commit is contained in:
James Booth 2012-11-05 23:24:29 +00:00
parent 8f317f9dbf
commit 517bc30360
4 changed files with 54 additions and 8 deletions

View File

@ -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);

View File

@ -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, "<", "&lt;");
char *coded_msg3 = str_replace(coded_msg2, ">", "&gt;");
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)
{

View File

@ -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);

View File

@ -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