1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Only send chat states when preference set

This commit is contained in:
James Booth 2012-10-31 22:08:00 +00:00
parent 7982d7061b
commit 81dd0a1556
3 changed files with 43 additions and 32 deletions

View File

@ -1009,13 +1009,16 @@ static gboolean
_cmd_close(const char * const inp, struct cmd_help_t help) _cmd_close(const char * const inp, struct cmd_help_t help)
{ {
if (win_in_chat()) { if (win_in_chat()) {
char *recipient = win_get_recipient();
// send <gone/> chat state before closing if (prefs_get_states()) {
if (chat_session_get_recipient_supports(recipient)) { char *recipient = win_get_recipient();
chat_session_gone(recipient);
jabber_send_gone(recipient); // send <gone/> chat state before closing
chat_session_end(recipient); if (chat_session_get_recipient_supports(recipient)) {
chat_session_gone(recipient);
jabber_send_gone(recipient);
chat_session_end(recipient);
}
} }
win_close_win(); win_close_win();

View File

@ -137,28 +137,31 @@ inp_get_char(int *ch, char *input, int *size)
noecho(); noecho();
*ch = wgetch(inp_win); *ch = wgetch(inp_win);
// if not got char, and in chat window, flag as no activity if (prefs_get_states()) {
// send inactive or gone, depending how long inactive
if (*ch == ERR) {
if (win_in_chat()) {
char *recipient = win_get_recipient();
chat_session_no_activity(recipient);
if (chat_session_gone(recipient) && // if not got char, and in chat window, flag as no activity
!chat_session_get_sent(recipient)) { // send inactive or gone, depending how long inactive
jabber_send_gone(recipient); if (*ch == ERR) {
} else if (chat_session_inactive(recipient) && if (win_in_chat()) {
!chat_session_get_sent(recipient)) { char *recipient = win_get_recipient();
jabber_send_inactive(recipient); chat_session_no_activity(recipient);
if (chat_session_gone(recipient) &&
!chat_session_get_sent(recipient)) {
jabber_send_gone(recipient);
} else if (chat_session_inactive(recipient) &&
!chat_session_get_sent(recipient)) {
jabber_send_inactive(recipient);
}
} }
} }
}
// if got char and in chat window, chat session active // if got char and in chat window, chat session active
if (*ch != ERR) { if (*ch != ERR) {
if (win_in_chat()) { if (win_in_chat()) {
char *recipient = win_get_recipient(); char *recipient = win_get_recipient();
chat_session_set_active(recipient); chat_session_set_active(recipient);
}
} }
} }

View File

@ -137,8 +137,10 @@ jabber_process_events(void)
void void
jabber_send(const char * const msg, const char * const recipient) jabber_send(const char * const msg, const char * const recipient)
{ {
if (!chat_session_exists(recipient)) { if (prefs_get_states()) {
chat_session_start(recipient, TRUE); if (!chat_session_exists(recipient)) {
chat_session_start(recipient, TRUE);
}
} }
char *coded_msg = str_replace(msg, "&", "&amp;"); char *coded_msg = str_replace(msg, "&", "&amp;");
@ -158,12 +160,15 @@ jabber_send(const char * const msg, const char * const recipient)
text = xmpp_stanza_new(jabber_conn.ctx); text = xmpp_stanza_new(jabber_conn.ctx);
xmpp_stanza_set_text(text, coded_msg3); xmpp_stanza_set_text(text, coded_msg3);
// always send <active/> with messages when recipient supports chat states if (prefs_get_states()) {
if (chat_session_get_recipient_supports(recipient)) {
active = xmpp_stanza_new(jabber_conn.ctx); // always send <active/> with messages when recipient supports chat states
xmpp_stanza_set_name(active, "active"); if (chat_session_get_recipient_supports(recipient)) {
xmpp_stanza_set_ns(active, "http://jabber.org/protocol/chatstates"); active = xmpp_stanza_new(jabber_conn.ctx);
xmpp_stanza_add_child(reply, active); xmpp_stanza_set_name(active, "active");
xmpp_stanza_set_ns(active, "http://jabber.org/protocol/chatstates");
xmpp_stanza_add_child(reply, active);
}
} }
xmpp_stanza_add_child(body, text); xmpp_stanza_add_child(body, text);