0
1
mirror of https://github.com/profanity-im/profanity.git synced 2025-07-26 12:14:28 -04:00

Refactored chat session handling on sending message

This commit is contained in:
James Booth 2015-01-04 23:40:10 +00:00
parent 42a5c431c7
commit 8326c8b3a2
13 changed files with 125 additions and 233 deletions

View File

@ -34,6 +34,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <assert.h>
#include <glib.h> #include <glib.h>
@ -57,7 +58,7 @@ typedef enum {
typedef struct chat_session_t { typedef struct chat_session_t {
char *barejid; char *barejid;
char *resource; char *resource;
gboolean supported; gboolean send_states;
chat_state_t state; chat_state_t state;
GTimer *active_timer; GTimer *active_timer;
gboolean sent; gboolean sent;
@ -66,12 +67,12 @@ typedef struct chat_session_t {
static GHashTable *sessions; static GHashTable *sessions;
static ChatSession* static ChatSession*
_chat_session_new(const char * const barejid, const char * const resource, gboolean supported) _chat_session_new(const char * const barejid, const char * const resource, gboolean send_states)
{ {
ChatSession *new_session = malloc(sizeof(struct chat_session_t)); ChatSession *new_session = malloc(sizeof(struct chat_session_t));
new_session->barejid = strdup(barejid); new_session->barejid = strdup(barejid);
new_session->resource = strdup(resource); new_session->resource = strdup(resource);
new_session->supported = supported; new_session->send_states = send_states;
new_session->state = CHAT_STATE_STARTED; new_session->state = CHAT_STATE_STARTED;
new_session->active_timer = g_timer_new(); new_session->active_timer = g_timer_new();
new_session->sent = FALSE; new_session->sent = FALSE;
@ -111,6 +112,7 @@ gboolean
chat_session_exists(const char * const barejid) chat_session_exists(const char * const barejid)
{ {
ChatSession *session = g_hash_table_lookup(sessions, barejid); ChatSession *session = g_hash_table_lookup(sessions, barejid);
return (session != NULL); return (session != NULL);
} }
@ -118,33 +120,22 @@ char*
chat_session_get_resource(const char * const barejid) chat_session_get_resource(const char * const barejid)
{ {
ChatSession *session = g_hash_table_lookup(sessions, barejid); ChatSession *session = g_hash_table_lookup(sessions, barejid);
if (session) { assert(session != NULL);
return session->resource;
} else { return session->resource;
return NULL;
}
} }
gboolean gboolean
chat_session_on_message_send(const char * const barejid) chat_session_send_states(const char * const barejid)
{ {
gboolean send_state = FALSE; ChatSession *session = g_hash_table_lookup(sessions, barejid);
assert(session != NULL);
if (prefs_get_boolean(PREF_STATES)) { return session->send_states;
ChatSession *session = g_hash_table_lookup(sessions, barejid);
if (session && session->supported) {
session->state = CHAT_STATE_ACTIVE;
g_timer_start(session->active_timer);
session->sent = TRUE;
send_state = TRUE;
}
}
return send_state;
} }
void void
chat_session_on_incoming_message(const char * const barejid, const char * const resource, gboolean supported) chat_session_on_incoming_message(const char * const barejid, const char * const resource, gboolean send_states)
{ {
ChatSession *session = g_hash_table_lookup(sessions, barejid); ChatSession *session = g_hash_table_lookup(sessions, barejid);
@ -153,14 +144,14 @@ chat_session_on_incoming_message(const char * const barejid, const char * const
if (g_strcmp0(session->resource, resource) != 0) { if (g_strcmp0(session->resource, resource) != 0) {
log_info("Replacing chat session %s/%s, with new session %s/%s", session->barejid, session->resource, barejid, resource); log_info("Replacing chat session %s/%s, with new session %s/%s", session->barejid, session->resource, barejid, resource);
g_hash_table_remove(sessions, session); g_hash_table_remove(sessions, session);
session = _chat_session_new(barejid, resource, supported); session = _chat_session_new(barejid, resource, send_states);
g_hash_table_insert(sessions, strdup(barejid), session); g_hash_table_insert(sessions, strdup(barejid), session);
} else { } else {
session->supported = supported; session->send_states = send_states;
} }
} else { } else {
log_info("Starting chat session with %s/%s", barejid, resource); log_info("Starting chat session with %s/%s", barejid, resource);
session = _chat_session_new(barejid, resource, supported); session = _chat_session_new(barejid, resource, send_states);
g_hash_table_insert(sessions, strdup(barejid), session); g_hash_table_insert(sessions, strdup(barejid), session);
} }
} else if (session) { } else if (session) {
@ -169,29 +160,34 @@ chat_session_on_incoming_message(const char * const barejid, const char * const
} }
} }
void
chat_session_on_message_send(const char * const barejid)
{
ChatSession *session = g_hash_table_lookup(sessions, barejid);
assert(session != NULL);
session->state = CHAT_STATE_ACTIVE;
g_timer_start(session->active_timer);
session->sent = TRUE;
}
void void
chat_session_on_window_close(const char * const barejid) chat_session_on_window_close(const char * const barejid)
{ {
if (prefs_get_boolean(PREF_STATES)) { ChatSession *session = g_hash_table_lookup(sessions, barejid);
ChatSession *session = g_hash_table_lookup(sessions, barejid); assert(session != NULL);
// send <gone/> chat state before closing
if (session && session->supported) { if (prefs_get_boolean(PREF_STATES) && session->send_states) {
session->state = CHAT_STATE_GONE; message_send_gone(barejid);
message_send_gone(barejid);
session->sent = TRUE;
g_hash_table_remove(sessions, barejid);
}
} }
} }
void void
chat_session_on_cancel(const char * const jid) chat_session_on_cancel(const char * const jid)
{ {
if (prefs_get_boolean(PREF_STATES)) { ChatSession *session = g_hash_table_lookup(sessions, jid);
ChatSession *session = g_hash_table_lookup(sessions, jid); if (session) {
if (session) { session->send_states = FALSE;
session->supported = FALSE;
}
} }
} }
@ -199,7 +195,7 @@ void
chat_session_on_activity(const char * const barejid) chat_session_on_activity(const char * const barejid)
{ {
ChatSession *session = g_hash_table_lookup(sessions, barejid); ChatSession *session = g_hash_table_lookup(sessions, barejid);
if (session && session->supported) { if (session) {
if (session->state != CHAT_STATE_COMPOSING) { if (session->state != CHAT_STATE_COMPOSING) {
session->sent = FALSE; session->sent = FALSE;
} }
@ -208,11 +204,15 @@ chat_session_on_activity(const char * const barejid)
g_timer_start(session->active_timer); g_timer_start(session->active_timer);
if (!session->sent || session->state == CHAT_STATE_PAUSED) { if (!session->sent || session->state == CHAT_STATE_PAUSED) {
Jid *jidp = jid_create_from_bare_and_resource(session->barejid, session->resource); if (prefs_get_boolean(PREF_STATES) && prefs_get_boolean(PREF_OUTTYPE) && session->send_states) {
message_send_composing(jidp->fulljid); Jid *jidp = jid_create_from_bare_and_resource(session->barejid, session->resource);
message_send_composing(jidp->fulljid);
jid_destroy(jidp);
}
session->sent = TRUE; session->sent = TRUE;
jid_destroy(jidp);
} }
} else if (prefs_get_boolean(PREF_STATES) && prefs_get_boolean(PREF_OUTTYPE)) {
message_send_composing(barejid);
} }
} }
@ -220,7 +220,7 @@ void
chat_session_on_inactivity(const char * const barejid) chat_session_on_inactivity(const char * const barejid)
{ {
ChatSession *session = g_hash_table_lookup(sessions, barejid); ChatSession *session = g_hash_table_lookup(sessions, barejid);
if (session && session->supported) { if (session) {
if (session->active_timer != NULL) { if (session->active_timer != NULL) {
gdouble elapsed = g_timer_elapsed(session->active_timer, NULL); gdouble elapsed = g_timer_elapsed(session->active_timer, NULL);
@ -247,13 +247,19 @@ chat_session_on_inactivity(const char * const barejid)
if (session->sent == FALSE) { if (session->sent == FALSE) {
Jid *jidp = jid_create_from_bare_and_resource(session->barejid, session->resource); Jid *jidp = jid_create_from_bare_and_resource(session->barejid, session->resource);
if (session->state == CHAT_STATE_GONE) { if (session->state == CHAT_STATE_GONE) {
message_send_gone(jidp->fulljid); if (prefs_get_boolean(PREF_STATES) && session->send_states) {
message_send_gone(jidp->fulljid);
}
session->sent = TRUE; session->sent = TRUE;
} else if (session->state == CHAT_STATE_INACTIVE) { } else if (session->state == CHAT_STATE_INACTIVE) {
message_send_inactive(jidp->fulljid); if (prefs_get_boolean(PREF_STATES) && session->send_states) {
message_send_inactive(jidp->fulljid);
}
session->sent = TRUE; session->sent = TRUE;
} else if (session->state == CHAT_STATE_PAUSED && prefs_get_boolean(PREF_OUTTYPE)) { } else if (session->state == CHAT_STATE_PAUSED && prefs_get_boolean(PREF_OUTTYPE)) {
message_send_paused(jidp->fulljid); if (prefs_get_boolean(PREF_STATES) && session->send_states) {
message_send_paused(jidp->fulljid);
}
session->sent = TRUE; session->sent = TRUE;
} }
jid_destroy(jidp); jid_destroy(jidp);

View File

@ -42,11 +42,14 @@ void chat_sessions_clear(void);
gboolean chat_session_exists(const char * const barejid); gboolean chat_session_exists(const char * const barejid);
char* chat_session_get_resource(const char * const barejid); char* chat_session_get_resource(const char * const barejid);
gboolean chat_session_on_message_send(const char * const barejid); gboolean chat_session_send_states(const char * const barejid);
void chat_session_on_message_send(const char * const barejid);
void chat_session_on_window_close(const char * const barejid); void chat_session_on_window_close(const char * const barejid);
void chat_session_on_incoming_message(const char * const barejid, const char * const resource, gboolean supported); void chat_session_on_incoming_message(const char * const barejid, const char * const resource, gboolean send_states);
void chat_session_on_cancel(const char * const jid); void chat_session_on_cancel(const char * const jid);
void chat_session_on_activity(const char * const barejid); void chat_session_on_activity(const char * const barejid);
void chat_session_on_inactivity(const char * const recipient); void chat_session_on_inactivity(const char * const barejid);
#endif #endif

View File

@ -1814,15 +1814,7 @@ cmd_execute_default(const char * inp)
if (otr_is_secure(chatwin->barejid)) { if (otr_is_secure(chatwin->barejid)) {
char *encrypted = otr_encrypt_message(chatwin->barejid, inp); char *encrypted = otr_encrypt_message(chatwin->barejid, inp);
if (encrypted != NULL) { if (encrypted != NULL) {
char *resource = NULL; message_send_chat(chatwin->barejid, encrypted);
gboolean send_state = FALSE;
if (chat_session_exists(chatwin->barejid)) {
resource = chat_session_get_resource(chatwin->barejid);
send_state = chat_session_on_message_send(chatwin->barejid);
} else {
send_state = TRUE;
}
message_send_chat(chatwin->barejid, resource, encrypted, send_state);
otr_free_message(encrypted); otr_free_message(encrypted);
if (prefs_get_boolean(PREF_CHLOG)) { if (prefs_get_boolean(PREF_CHLOG)) {
const char *jid = jabber_get_fulljid(); const char *jid = jabber_get_fulljid();
@ -1842,15 +1834,7 @@ cmd_execute_default(const char * inp)
cons_show_error("Failed to send message."); cons_show_error("Failed to send message.");
} }
} else { } else {
char *resource = NULL; message_send_chat(chatwin->barejid, inp);
gboolean send_state = FALSE;
if (chat_session_exists(chatwin->barejid)) {
resource = chat_session_get_resource(chatwin->barejid);
send_state = chat_session_on_message_send(chatwin->barejid);
} else {
send_state = TRUE;
}
message_send_chat(chatwin->barejid, resource, inp, send_state);
if (prefs_get_boolean(PREF_CHLOG)) { if (prefs_get_boolean(PREF_CHLOG)) {
const char *jid = jabber_get_fulljid(); const char *jid = jabber_get_fulljid();
Jid *jidp = jid_create(jid); Jid *jidp = jid_create(jid);
@ -1861,15 +1845,7 @@ cmd_execute_default(const char * inp)
ui_outgoing_chat_msg("me", chatwin->barejid, inp); ui_outgoing_chat_msg("me", chatwin->barejid, inp);
} }
#else #else
char *resource = NULL; message_send_chat(chatwin->barejid, inp);
gboolean send_state = FALSE;
if (chat_session_exists(chatwin->barejid)) {
resource = chat_session_get_resource(chatwin->barejid);
send_state = chat_session_on_message_send(chatwin->barejid);
} else {
send_state = TRUE;
}
message_send_chat(chatwin->barejid, resource, inp, send_state);
if (prefs_get_boolean(PREF_CHLOG)) { if (prefs_get_boolean(PREF_CHLOG)) {
const char *jid = jabber_get_fulljid(); const char *jid = jabber_get_fulljid();
Jid *jidp = jid_create(jid); Jid *jidp = jid_create(jid);

View File

@ -1203,31 +1203,23 @@ cmd_msg(gchar **args, struct cmd_help_t help)
barejid = usr; barejid = usr;
} }
// if msg to current recipient, and resource specified, set resource // TODO if msg to current recipient, and resource specified, set resource
char *resource = NULL; // char *resource = NULL;
ProfWin *current = wins_get_current(); // ProfWin *current = wins_get_current();
if (current->type == WIN_CHAT) { // if (current->type == WIN_CHAT) {
ProfChatWin *chatwin = (ProfChatWin*)current; // ProfChatWin *chatwin = (ProfChatWin*)current;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); // assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
if ((g_strcmp0(chatwin->barejid, barejid) == 0) && (chatwin->resource)) { // if ((g_strcmp0(chatwin->barejid, barejid) == 0) && (chatwin->resource)) {
resource = chatwin->resource; // resource = chatwin->resource;
} // }
} // }
if (msg != NULL) { if (msg != NULL) {
#ifdef HAVE_LIBOTR #ifdef HAVE_LIBOTR
if (otr_is_secure(barejid)) { if (otr_is_secure(barejid)) {
char *encrypted = otr_encrypt_message(barejid, msg); char *encrypted = otr_encrypt_message(barejid, msg);
if (encrypted != NULL) { if (encrypted != NULL) {
resource = NULL; message_send_chat(barejid, encrypted);
gboolean send_state = FALSE;
if (chat_session_exists(barejid)) {
resource = chat_session_get_resource(barejid);
send_state = chat_session_on_message_send(barejid);
} else {
send_state = TRUE;
}
message_send_chat(barejid, resource, encrypted, send_state);
otr_free_message(encrypted); otr_free_message(encrypted);
ui_outgoing_chat_msg("me", barejid, msg); ui_outgoing_chat_msg("me", barejid, msg);
@ -1256,27 +1248,11 @@ cmd_msg(gchar **args, struct cmd_help_t help)
GString *otr_message = g_string_new(msg); GString *otr_message = g_string_new(msg);
g_string_append(otr_message, OTRL_MESSAGE_TAG_BASE); g_string_append(otr_message, OTRL_MESSAGE_TAG_BASE);
g_string_append(otr_message, OTRL_MESSAGE_TAG_V2); g_string_append(otr_message, OTRL_MESSAGE_TAG_V2);
resource = NULL; message_send_chat(barejid, otr_message->str);
gboolean send_state = FALSE;
if (chat_session_exists(barejid)) {
resource = chat_session_get_resource(barejid);
send_state = chat_session_on_message_send(barejid);
} else {
send_state = TRUE;
}
message_send_chat(barejid, resource, otr_message->str, send_state);
g_string_free(otr_message, TRUE); g_string_free(otr_message, TRUE);
} else { } else {
resource = NULL; message_send_chat(barejid, msg);
gboolean send_state = FALSE;
if (chat_session_exists(barejid)) {
resource = chat_session_get_resource(barejid);
send_state = chat_session_on_message_send(barejid);
} else {
send_state = TRUE;
}
message_send_chat(barejid, resource, msg, send_state);
} }
ui_outgoing_chat_msg("me", barejid, msg); ui_outgoing_chat_msg("me", barejid, msg);
@ -1289,15 +1265,7 @@ cmd_msg(gchar **args, struct cmd_help_t help)
} }
return TRUE; return TRUE;
#else #else
resource = NULL; message_send_chat(barejid, msg);
gboolean send_state = FALSE;
if (chat_session_exists(barejid)) {
resource = chat_session_get_resource(barejid);
send_state = chat_session_on_message_send(barejid);
} else {
send_state = TRUE;
}
message_send_chat(barejid, resource, msg, send_state);
ui_outgoing_chat_msg("me", barejid, msg); ui_outgoing_chat_msg("me", barejid, msg);
if (((win_type == WIN_CHAT) || (win_type == WIN_CONSOLE)) && prefs_get_boolean(PREF_CHLOG)) { if (((win_type == WIN_CHAT) || (win_type == WIN_CONSOLE)) && prefs_get_boolean(PREF_CHLOG)) {
@ -3036,15 +3004,7 @@ cmd_tiny(gchar **args, struct cmd_help_t help)
if (otr_is_secure(chatwin->barejid)) { if (otr_is_secure(chatwin->barejid)) {
char *encrypted = otr_encrypt_message(chatwin->barejid, tiny); char *encrypted = otr_encrypt_message(chatwin->barejid, tiny);
if (encrypted != NULL) { if (encrypted != NULL) {
char *resource = NULL; message_send_chat(chatwin->barejid, encrypted);
gboolean send_state = FALSE;
if (chat_session_exists(chatwin->barejid)) {
resource = chat_session_get_resource(chatwin->barejid);
send_state = chat_session_on_message_send(chatwin->barejid);
} else {
send_state = TRUE;
}
message_send_chat(chatwin->barejid, resource, encrypted, send_state);
otr_free_message(encrypted); otr_free_message(encrypted);
if (prefs_get_boolean(PREF_CHLOG)) { if (prefs_get_boolean(PREF_CHLOG)) {
const char *jid = jabber_get_fulljid(); const char *jid = jabber_get_fulljid();
@ -3064,15 +3024,7 @@ cmd_tiny(gchar **args, struct cmd_help_t help)
cons_show_error("Failed to send message."); cons_show_error("Failed to send message.");
} }
} else { } else {
char *resource = NULL; message_send_chat(chatwin->barejid, tiny);
gboolean send_state = FALSE;
if (chat_session_exists(chatwin->barejid)) {
resource = chat_session_get_resource(chatwin->barejid);
send_state = chat_session_on_message_send(chatwin->barejid);
} else {
send_state = TRUE;
}
message_send_chat(chatwin->barejid, resource, tiny, send_state);
if (prefs_get_boolean(PREF_CHLOG)) { if (prefs_get_boolean(PREF_CHLOG)) {
const char *jid = jabber_get_fulljid(); const char *jid = jabber_get_fulljid();
Jid *jidp = jid_create(jid); Jid *jidp = jid_create(jid);
@ -3083,15 +3035,7 @@ cmd_tiny(gchar **args, struct cmd_help_t help)
ui_outgoing_chat_msg("me", chatwin->barejid, tiny); ui_outgoing_chat_msg("me", chatwin->barejid, tiny);
} }
#else #else
char *resource = NULL; message_send_chat(chatwin->barejid, tiny);
gboolean send_state = FALSE;
if (chat_session_exists(chatwin->barejid)) {
resource = chat_session_get_resource(chatwin->barejid);
send_state = chat_session_on_message_send(chatwin->barejid);
} else {
send_state = TRUE;
}
message_send_chat(chatwin->barejid, resource, tiny, send_state);
if (prefs_get_boolean(PREF_CHLOG)) { if (prefs_get_boolean(PREF_CHLOG)) {
const char *jid = jabber_get_fulljid(); const char *jid = jabber_get_fulljid();
Jid *jidp = jid_create(jid); Jid *jidp = jid_create(jid);
@ -4008,15 +3952,7 @@ cmd_otr(gchar **args, struct cmd_help_t help)
ui_current_print_formatted_line('!', 0, "You have not generated or loaded a private key, use '/otr gen'"); ui_current_print_formatted_line('!', 0, "You have not generated or loaded a private key, use '/otr gen'");
} else if (!otr_is_secure(barejid)) { } else if (!otr_is_secure(barejid)) {
char *otr_query_message = otr_start_query(); char *otr_query_message = otr_start_query();
char *resource = NULL; message_send_chat(barejid, otr_query_message);
gboolean send_state = FALSE;
if (chat_session_exists(barejid)) {
resource = chat_session_get_resource(barejid);
send_state = chat_session_on_message_send(barejid);
} else {
send_state = TRUE;
}
message_send_chat(barejid, resource, otr_query_message, send_state);
} else { } else {
ui_gone_secure(barejid, otr_is_trusted(barejid)); ui_gone_secure(barejid, otr_is_trusted(barejid));
} }
@ -4034,15 +3970,7 @@ cmd_otr(gchar **args, struct cmd_help_t help)
} else { } else {
ProfChatWin *chatwin = ui_get_current_chat(); ProfChatWin *chatwin = ui_get_current_chat();
char *otr_query_message = otr_start_query(); char *otr_query_message = otr_start_query();
char *resource = NULL; message_send_chat(chatwin->barejid, otr_query_message);
gboolean send_state = FALSE;
if (chat_session_exists(chatwin->barejid)) {
resource = chat_session_get_resource(chatwin->barejid);
send_state = chat_session_on_message_send(chatwin->barejid);
} else {
send_state = TRUE;
}
message_send_chat(chatwin->barejid, resource, otr_query_message, send_state);
} }
} }
} }

View File

@ -110,15 +110,7 @@ static void
cb_inject_message(void *opdata, const char *accountname, cb_inject_message(void *opdata, const char *accountname,
const char *protocol, const char *recipient, const char *message) const char *protocol, const char *recipient, const char *message)
{ {
char *resource = NULL; message_send_chat(recipient, message);
gboolean send_state = FALSE;
if (chat_session_exists(recipient)) {
resource = chat_session_get_resource(recipient);
send_state = chat_session_on_message_send(recipient);
} else {
send_state = TRUE;
}
message_send_chat(recipient, resource, message, send_state);
} }
static void static void

View File

@ -318,15 +318,7 @@ handle_incoming_message(char *barejid, char *message)
memmove(whitespace_base, whitespace_base+tag_length, tag_length); memmove(whitespace_base, whitespace_base+tag_length, tag_length);
char *otr_query_message = otr_start_query(); char *otr_query_message = otr_start_query();
cons_show("OTR Whitespace pattern detected. Attempting to start OTR session..."); cons_show("OTR Whitespace pattern detected. Attempting to start OTR session...");
char *resource = NULL; message_send_chat(barejid, otr_query_message);
gboolean send_state = FALSE;
if (chat_session_exists(barejid)) {
resource = chat_session_get_resource(barejid);
send_state = chat_session_on_message_send(barejid);
} else {
send_state = TRUE;
}
message_send_chat(barejid, resource, otr_query_message, send_state);
} }
} }
} }
@ -340,15 +332,7 @@ handle_incoming_message(char *barejid, char *message)
if (policy == PROF_OTRPOLICY_ALWAYS && !was_decrypted && !whitespace_base) { if (policy == PROF_OTRPOLICY_ALWAYS && !was_decrypted && !whitespace_base) {
char *otr_query_message = otr_start_query(); char *otr_query_message = otr_start_query();
cons_show("Attempting to start OTR session..."); cons_show("Attempting to start OTR session...");
char *resource = NULL; message_send_chat(barejid, otr_query_message);
gboolean send_state = FALSE;
if (chat_session_exists(barejid)) {
resource = chat_session_get_resource(barejid);
send_state = chat_session_on_message_send(barejid);
} else {
send_state = TRUE;
}
message_send_chat(barejid, resource, otr_query_message, send_state);
} }
ui_incoming_msg(barejid, newmessage, NULL); ui_incoming_msg(barejid, newmessage, NULL);

View File

@ -705,7 +705,9 @@ ui_close_connected_win(int index)
otr_end_session(chatwin->barejid); otr_end_session(chatwin->barejid);
} }
#endif #endif
chat_session_on_window_close(chatwin->barejid); if (chat_session_exists(chatwin->barejid)) {
chat_session_on_window_close(chatwin->barejid);
}
} }
} }
} }
@ -1162,7 +1164,9 @@ ui_prune_wins(void)
if (window->type == WIN_CHAT) { if (window->type == WIN_CHAT) {
if (conn_status == JABBER_CONNECTED) { if (conn_status == JABBER_CONNECTED) {
ProfChatWin *chatwin = (ProfChatWin*)window; ProfChatWin *chatwin = (ProfChatWin*)window;
chat_session_on_window_close(chatwin->barejid); if (chat_session_exists(chatwin->barejid)) {
chat_session_on_window_close(chatwin->barejid);
}
} }
} }

View File

@ -151,17 +151,11 @@ inp_get_char(char *input, int *size, int *result)
in_command = TRUE; in_command = TRUE;
} }
if (prefs_get_boolean(PREF_STATES)) { if (*result == ERR) {
if (*result == ERR) { prof_handle_idle();
prof_handle_idle(); }
} if ((*result != ERR) && (*result != KEY_CODE_YES) && !in_command && _printable(ch)) {
if (prefs_get_boolean(PREF_OUTTYPE) prof_handle_activity();
&& (*result != ERR)
&& (*result != KEY_CODE_YES)
&& !in_command
&& _printable(ch)) {
prof_handle_activity();
}
} }
// if it wasn't an arrow key etc // if it wasn't an arrow key etc

View File

@ -80,19 +80,29 @@ message_add_handlers(void)
} }
void void
message_send_chat(const char * const barejid, const char * const resource, const char * const msg, gboolean send_state) message_send_chat(const char * const barejid, const char * const msg)
{ {
xmpp_stanza_t *message; xmpp_stanza_t *message;
xmpp_conn_t * const conn = connection_get_conn(); xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx(); xmpp_ctx_t * const ctx = connection_get_ctx();
char *resource = NULL;
gboolean send_state = FALSE;
if (chat_session_exists(barejid)) {
chat_session_on_message_send(barejid);
resource = chat_session_get_resource(barejid);
send_state = chat_session_send_states(barejid);
} else {
send_state = TRUE;
}
GString *jid = g_string_new(barejid); GString *jid = g_string_new(barejid);
if (resource) { if (resource) {
g_string_append(jid, "/"); g_string_append(jid, "/");
g_string_append(jid, resource); g_string_append(jid, resource);
} }
if (send_state) { if (prefs_get_boolean(PREF_STATES) && send_state) {
message = stanza_create_message(ctx, jid->str, STANZA_TYPE_CHAT, msg, STANZA_NAME_ACTIVE); message = stanza_create_message(ctx, jid->str, STANZA_TYPE_CHAT, msg, STANZA_NAME_ACTIVE);
} else { } else {
message = stanza_create_message(ctx, jid->str, STANZA_TYPE_CHAT, msg, NULL); message = stanza_create_message(ctx, jid->str, STANZA_TYPE_CHAT, msg, NULL);
@ -149,22 +159,22 @@ message_send_invite(const char * const roomjid, const char * const contact,
} }
void void
message_send_composing(const char * const fulljid) message_send_composing(const char * const jid)
{ {
xmpp_conn_t * const conn = connection_get_conn(); xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx(); xmpp_ctx_t * const ctx = connection_get_ctx();
xmpp_stanza_t *stanza = stanza_create_chat_state(ctx, fulljid, STANZA_NAME_COMPOSING); xmpp_stanza_t *stanza = stanza_create_chat_state(ctx, jid, STANZA_NAME_COMPOSING);
xmpp_send(conn, stanza); xmpp_send(conn, stanza);
xmpp_stanza_release(stanza); xmpp_stanza_release(stanza);
} }
void void
message_send_paused(const char * const fulljid) message_send_paused(const char * const jid)
{ {
xmpp_conn_t * const conn = connection_get_conn(); xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx(); xmpp_ctx_t * const ctx = connection_get_ctx();
xmpp_stanza_t *stanza = stanza_create_chat_state(ctx, fulljid, xmpp_stanza_t *stanza = stanza_create_chat_state(ctx, jid,
STANZA_NAME_PAUSED); STANZA_NAME_PAUSED);
xmpp_send(conn, stanza); xmpp_send(conn, stanza);
@ -172,11 +182,11 @@ message_send_paused(const char * const fulljid)
} }
void void
message_send_inactive(const char * const fulljid) message_send_inactive(const char * const jid)
{ {
xmpp_conn_t * const conn = connection_get_conn(); xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx(); xmpp_ctx_t * const ctx = connection_get_ctx();
xmpp_stanza_t *stanza = stanza_create_chat_state(ctx, fulljid, xmpp_stanza_t *stanza = stanza_create_chat_state(ctx, jid,
STANZA_NAME_INACTIVE); STANZA_NAME_INACTIVE);
xmpp_send(conn, stanza); xmpp_send(conn, stanza);
@ -184,11 +194,11 @@ message_send_inactive(const char * const fulljid)
} }
void void
message_send_gone(const char * const fulljid) message_send_gone(const char * const jid)
{ {
xmpp_conn_t * const conn = connection_get_conn(); xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx(); xmpp_ctx_t * const ctx = connection_get_ctx();
xmpp_stanza_t *stanza = stanza_create_chat_state(ctx, fulljid, xmpp_stanza_t *stanza = stanza_create_chat_state(ctx, jid,
STANZA_NAME_GONE); STANZA_NAME_GONE);
xmpp_send(conn, stanza); xmpp_send(conn, stanza);

View File

@ -145,16 +145,15 @@ char* jabber_get_account_name(void);
GList * jabber_get_available_resources(void); GList * jabber_get_available_resources(void);
// message functions // message functions
void message_send_chat(const char * const barejid, const char * const resource, const char * const msg, void message_send_chat(const char * const barejid, const char * const msg);
gboolean send_state);
void message_send_private(const char * const fulljid, const char * const msg); void message_send_private(const char * const fulljid, const char * const msg);
void message_send_groupchat(const char * const roomjid, const char * const msg); void message_send_groupchat(const char * const roomjid, const char * const msg);
void message_send_groupchat_subject(const char * const roomjid, const char * const subject); void message_send_groupchat_subject(const char * const roomjid, const char * const subject);
void message_send_inactive(const char * const fulljid); void message_send_inactive(const char * const jid);
void message_send_composing(const char * const fulljid); void message_send_composing(const char * const jid);
void message_send_paused(const char * const fulljid); void message_send_paused(const char * const jid);
void message_send_gone(const char * const fulljid); void message_send_gone(const char * const jid);
void message_send_invite(const char * const room, const char * const contact, void message_send_invite(const char * const room, const char * const contact,
const char * const reason); const char * const reason);

View File

@ -552,9 +552,7 @@ cmd_otr_start_sends_otr_query_message_to_current_recipeint(void **state)
will_return(otr_start_query, query_message); will_return(otr_start_query, query_message);
expect_string(message_send_chat, barejid, chatwin->barejid); expect_string(message_send_chat, barejid, chatwin->barejid);
expect_value(message_send_chat, resource, NULL);
expect_string(message_send_chat, msg, query_message); expect_string(message_send_chat, msg, query_message);
expect_any(message_send_chat, send_state);
gboolean result = cmd_otr(args, *help); gboolean result = cmd_otr(args, *help);
assert_true(result); assert_true(result);

View File

@ -141,9 +141,10 @@ void handle_message_error_when_recipient_cancel_disables_chat_session(void **sta
expect_any(ui_handle_recipient_not_found, err_msg); expect_any(ui_handle_recipient_not_found, err_msg);
handle_message_error(from, type, err_msg); handle_message_error(from, type, err_msg);
gboolean chat_session_supported = chat_session_on_message_send(from); chat_session_on_message_send(from);
gboolean send_states = chat_session_send_states(from);
assert_false(chat_session_supported); assert_false(send_states);
chat_sessions_clear(); chat_sessions_clear();
} }

View File

@ -58,13 +58,10 @@ GList * jabber_get_available_resources(void)
} }
// message functions // message functions
void message_send_chat(const char * const barejid, const char * const resource, const char * const msg, void message_send_chat(const char * const barejid, const char * const msg)
gboolean send_state)
{ {
check_expected(barejid); check_expected(barejid);
check_expected(resource);
check_expected(msg); check_expected(msg);
check_expected(send_state);
} }
void message_send_private(const char * const fulljid, const char * const msg) {} void message_send_private(const char * const fulljid, const char * const msg) {}
@ -218,4 +215,4 @@ void roster_send_add_new(const char * const barejid, const char * const name)
void roster_send_remove(const char * const barejid) void roster_send_remove(const char * const barejid)
{ {
check_expected(barejid); check_expected(barejid);
} }