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

Fixed chat state for non OTR

This commit is contained in:
James Booth 2014-12-28 22:40:59 +00:00
parent 53ecd3b383
commit ac4b59eda0
8 changed files with 41 additions and 160 deletions

View File

@ -82,7 +82,7 @@ chat_sessions_clear(void)
} }
void void
chat_session_start(const char * const recipient, gboolean recipient_supports) chat_session_new(const char * const recipient, gboolean recipient_supports)
{ {
ChatSession *new_session = malloc(sizeof(struct chat_session_t)); ChatSession *new_session = malloc(sizeof(struct chat_session_t));
new_session->recipient = strdup(recipient); new_session->recipient = strdup(recipient);
@ -260,6 +260,23 @@ chat_session_set_recipient_supports(const char * const recipient,
} }
} }
gboolean
chat_session_on_message_send(const char * const barejid)
{
gboolean send_state = FALSE;
if (prefs_get_boolean(PREF_STATES)) {
if (!chat_session_exists(barejid)) {
chat_session_new(barejid, TRUE);
}
if (chat_session_get_recipient_supports(barejid)) {
chat_session_set_active(barejid);
send_state = TRUE;
}
}
return send_state;
}
static void static void
_chat_session_free(ChatSession *session) _chat_session_free(ChatSession *session)
{ {

View File

@ -39,7 +39,7 @@
void chat_sessions_init(void); void chat_sessions_init(void);
void chat_sessions_clear(void); void chat_sessions_clear(void);
void chat_session_start(const char * const recipient, void chat_session_new(const char * const recipient,
gboolean recipient_supports); gboolean recipient_supports);
gboolean chat_session_exists(const char * const recipient); gboolean chat_session_exists(const char * const recipient);
void chat_session_end(const char * const recipient); void chat_session_end(const char * const recipient);
@ -56,5 +56,6 @@ gboolean chat_session_is_gone(const char * const recipient);
void chat_session_set_gone(const char * const recipient); void chat_session_set_gone(const char * const recipient);
void chat_session_set_sent(const char * const recipient); void chat_session_set_sent(const char * const recipient);
gboolean chat_session_get_sent(const char * const recipient); gboolean chat_session_get_sent(const char * const recipient);
gboolean chat_session_on_message_send(const char * const barejid);
#endif #endif

View File

@ -1803,17 +1803,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) {
gboolean send_state = FALSE; gboolean send_state = chat_session_on_message_send(chatwin->barejid);
if (prefs_get_boolean(PREF_STATES)) {
if (!chat_session_exists(chatwin->barejid)) {
chat_session_start(chatwin->barejid, TRUE);
}
if (chat_session_get_recipient_supports(chatwin->barejid)) {
chat_session_set_active(chatwin->barejid);
send_state = TRUE;
}
}
message_send_chat(chatwin->barejid, chatwin->barejid, encrypted, send_state); message_send_chat(chatwin->barejid, chatwin->barejid, encrypted, send_state);
otr_free_message(encrypted); otr_free_message(encrypted);
if (prefs_get_boolean(PREF_CHLOG)) { if (prefs_get_boolean(PREF_CHLOG)) {
@ -1834,16 +1824,7 @@ cmd_execute_default(const char * inp)
cons_show_error("Failed to send message."); cons_show_error("Failed to send message.");
} }
} else { } else {
gboolean send_state = FALSE; gboolean send_state = chat_session_on_message_send(chatwin->barejid);
if (prefs_get_boolean(PREF_STATES)) {
if (!chat_session_exists(chatwin->barejid)) {
chat_session_start(chatwin->barejid, TRUE);
}
if (chat_session_get_recipient_supports(chatwin->barejid)) {
chat_session_set_active(chatwin->barejid);
send_state = TRUE;
}
}
message_send_chat(chatwin->barejid, chatwin->resource, inp, send_state); message_send_chat(chatwin->barejid, chatwin->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();
@ -1855,16 +1836,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
gboolean send_state = FALSE; gboolean send_state = chat_session_on_message_send(chatwin->barejid);
if (prefs_get_boolean(PREF_STATES)) {
if (!chat_session_exists(chatwin->barejid)) {
chat_session_start(chatwin->barejid, TRUE);
}
if (chat_session_get_recipient_supports(chatwin->barejid)) {
chat_session_set_active(chatwin->barejid);
send_state = TRUE;
}
}
message_send_chat(chatwin->barejid, chatwin->resource, inp, send_state); message_send_chat(chatwin->barejid, chatwin->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();

View File

@ -1168,16 +1168,7 @@ cmd_msg(gchar **args, struct cmd_help_t help)
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) {
gboolean send_state = FALSE; gboolean send_state = chat_session_on_message_send(barejid);
if (prefs_get_boolean(PREF_STATES)) {
if (!chat_session_exists(barejid)) {
chat_session_start(barejid, TRUE);
}
if (chat_session_get_recipient_supports(barejid)) {
chat_session_set_active(barejid);
send_state = TRUE;
}
}
message_send_chat(barejid, resource, encrypted, send_state); 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);
@ -1207,31 +1198,12 @@ 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);
gboolean send_state = chat_session_on_message_send(barejid);
gboolean send_state = FALSE;
if (prefs_get_boolean(PREF_STATES)) {
if (!chat_session_exists(barejid)) {
chat_session_start(barejid, TRUE);
}
if (chat_session_get_recipient_supports(barejid)) {
chat_session_set_active(barejid);
send_state = TRUE;
}
}
message_send_chat(barejid, resource, otr_message->str, send_state); message_send_chat(barejid, resource, otr_message->str, send_state);
g_string_free(otr_message, TRUE); g_string_free(otr_message, TRUE);
} else { } else {
gboolean send_state = FALSE; gboolean send_state = chat_session_on_message_send(barejid);
if (prefs_get_boolean(PREF_STATES)) {
if (!chat_session_exists(barejid)) {
chat_session_start(barejid, TRUE);
}
if (chat_session_get_recipient_supports(barejid)) {
chat_session_set_active(barejid);
send_state = TRUE;
}
}
message_send_chat(barejid, resource, msg, send_state); message_send_chat(barejid, resource, msg, send_state);
} }
ui_outgoing_chat_msg("me", barejid, msg); ui_outgoing_chat_msg("me", barejid, msg);
@ -1245,16 +1217,7 @@ cmd_msg(gchar **args, struct cmd_help_t help)
} }
return TRUE; return TRUE;
#else #else
gboolean send_state = FALSE; gboolean send_state = chat_session_on_message_send(barejid);
if (prefs_get_boolean(PREF_STATES)) {
if (!chat_session_exists(barejid)) {
chat_session_start(barejid, TRUE);
}
if (chat_session_get_recipient_supports(barejid)) {
chat_session_set_active(barejid);
send_state = TRUE;
}
}
message_send_chat(barejid, resource, msg, send_state); message_send_chat(barejid, resource, msg, send_state);
ui_outgoing_chat_msg("me", barejid, msg); ui_outgoing_chat_msg("me", barejid, msg);
@ -1270,7 +1233,7 @@ cmd_msg(gchar **args, struct cmd_help_t help)
} else { // msg == NULL } else { // msg == NULL
if (prefs_get_boolean(PREF_STATES)) { if (prefs_get_boolean(PREF_STATES)) {
if (!chat_session_exists(barejid)) { if (!chat_session_exists(barejid)) {
chat_session_start(barejid, TRUE); chat_session_new(barejid, TRUE);
} }
} }
@ -3000,16 +2963,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) {
gboolean send_state = FALSE; gboolean send_state = chat_session_on_message_send(chatwin->barejid);
if (prefs_get_boolean(PREF_STATES)) {
if (!chat_session_exists(chatwin->barejid)) {
chat_session_start(chatwin->barejid, TRUE);
}
if (chat_session_get_recipient_supports(chatwin->barejid)) {
chat_session_set_active(chatwin->barejid);
send_state = TRUE;
}
}
message_send_chat(chatwin->barejid, chatwin->resource, encrypted, send_state); message_send_chat(chatwin->barejid, chatwin->resource, encrypted, send_state);
otr_free_message(encrypted); otr_free_message(encrypted);
if (prefs_get_boolean(PREF_CHLOG)) { if (prefs_get_boolean(PREF_CHLOG)) {
@ -3030,16 +2984,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 {
gboolean send_state = FALSE; gboolean send_state = chat_session_on_message_send(chatwin->barejid);
if (prefs_get_boolean(PREF_STATES)) {
if (!chat_session_exists(chatwin->barejid)) {
chat_session_start(chatwin->barejid, TRUE);
}
if (chat_session_get_recipient_supports(chatwin->barejid)) {
chat_session_set_active(chatwin->barejid);
send_state = TRUE;
}
}
message_send_chat(chatwin->barejid, chatwin->resource, tiny, send_state); message_send_chat(chatwin->barejid, chatwin->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();
@ -3051,17 +2996,8 @@ 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
gboolean send_state = FALSE; gboolean send_state = chat_session_on_message_send(chatwin->barejid);
if (prefs_get_boolean(PREF_STATES)) { message_send_chat(chatwin->barejid, chatwin->resource, tiny, send_state);
if (!chat_session_exists(chatwin->barejid)) {
chat_session_start(chatwin->barejid, TRUE);
}
if (chat_session_get_recipient_supports(chatwin->barejid)) {
chat_session_set_active(chatwin->barejid);
send_state = TRUE;
}
}
message_send_chat(chatwin->barejid, chatwin->resource, tiny);
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);
@ -3971,7 +3907,7 @@ cmd_otr(gchar **args, struct cmd_help_t help)
if (prefs_get_boolean(PREF_STATES)) { if (prefs_get_boolean(PREF_STATES)) {
if (!chat_session_exists(barejid)) { if (!chat_session_exists(barejid)) {
chat_session_start(barejid, TRUE); chat_session_new(barejid, TRUE);
} }
} }
@ -3984,16 +3920,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();
gboolean send_state = FALSE; gboolean send_state = chat_session_on_message_send(barejid);
if (prefs_get_boolean(PREF_STATES)) {
if (!chat_session_exists(barejid)) {
chat_session_start(barejid, TRUE);
}
if (chat_session_get_recipient_supports(barejid)) {
chat_session_set_active(barejid);
send_state = TRUE;
}
}
message_send_chat(barejid, NULL, otr_query_message, send_state); message_send_chat(barejid, NULL, otr_query_message, send_state);
} else { } else {
ui_gone_secure(barejid, otr_is_trusted(barejid)); ui_gone_secure(barejid, otr_is_trusted(barejid));
@ -4012,16 +3939,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();
gboolean send_state = FALSE; gboolean send_state = chat_session_on_message_send(chatwin->barejid);
if (prefs_get_boolean(PREF_STATES)) {
if (!chat_session_exists(chatwin->barejid)) {
chat_session_start(chatwin->barejid, TRUE);
}
if (chat_session_get_recipient_supports(chatwin->barejid)) {
chat_session_set_active(chatwin->barejid);
send_state = TRUE;
}
}
message_send_chat(chatwin->barejid, NULL, otr_query_message, send_state); message_send_chat(chatwin->barejid, NULL, otr_query_message, send_state);
} }
} }

View File

@ -110,16 +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)
{ {
gboolean send_state = FALSE; gboolean send_state = chat_session_on_message_send(recipient);
if (prefs_get_boolean(PREF_STATES)) {
if (!chat_session_exists(recipient)) {
chat_session_start(recipient, TRUE);
}
if (chat_session_get_recipient_supports(recipient)) {
chat_session_set_active(recipient);
send_state = TRUE;
}
}
message_send_chat(recipient, NULL, message, send_state); message_send_chat(recipient, NULL, message, send_state);
} }

View File

@ -320,16 +320,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...");
gboolean send_state = FALSE; gboolean send_state = chat_session_on_message_send(barejid);
if (prefs_get_boolean(PREF_STATES)) {
if (!chat_session_exists(barejid)) {
chat_session_start(barejid, TRUE);
}
if (chat_session_get_recipient_supports(barejid)) {
chat_session_set_active(barejid);
send_state = TRUE;
}
}
message_send_chat(barejid, NULL, otr_query_message, send_state); message_send_chat(barejid, NULL, otr_query_message, send_state);
} }
} }
@ -344,16 +335,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...");
gboolean send_state = FALSE; gboolean send_state = chat_session_on_message_send(barejid);
if (prefs_get_boolean(PREF_STATES)) {
if (!chat_session_exists(barejid)) {
chat_session_start(barejid, TRUE);
}
if (chat_session_get_recipient_supports(barejid)) {
chat_session_set_active(barejid);
send_state = TRUE;
}
}
message_send_chat(barejid, NULL, otr_query_message, send_state); message_send_chat(barejid, NULL, otr_query_message, send_state);
} }

View File

@ -460,7 +460,7 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
// create or update chat session // create or update chat session
if (!chat_session_exists(jid->barejid)) { if (!chat_session_exists(jid->barejid)) {
chat_session_start(jid->barejid, recipient_supports); chat_session_new(jid->barejid, recipient_supports);
} else { } else {
chat_session_set_recipient_supports(jid->barejid, recipient_supports); chat_session_set_recipient_supports(jid->barejid, recipient_supports);
} }

View File

@ -134,7 +134,7 @@ void handle_message_error_when_recipient_cancel_disables_chat_session(void **sta
prefs_set_boolean(PREF_STATES, TRUE); prefs_set_boolean(PREF_STATES, TRUE);
chat_sessions_init(); chat_sessions_init();
chat_session_start(from, TRUE); chat_session_new(from, TRUE);
expect_any(ui_handle_recipient_not_found, recipient); expect_any(ui_handle_recipient_not_found, recipient);
expect_any(ui_handle_recipient_not_found, err_msg); expect_any(ui_handle_recipient_not_found, err_msg);