diff options
author | James Booth <boothj5@gmail.com> | 2015-01-04 23:40:10 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2015-01-04 23:40:10 +0000 |
commit | 8326c8b3a21fd4a6aa415f92584aebedd51b01d9 (patch) | |
tree | 74c4477596daed645d9af2bbb3223f9c42ca2aca /src/command | |
parent | 42a5c431c777ab22c2187bb6f50a62ef304d8d6b (diff) | |
download | profani-tty-8326c8b3a21fd4a6aa415f92584aebedd51b01d9.tar.gz |
Refactored chat session handling on sending message
Diffstat (limited to 'src/command')
-rw-r--r-- | src/command/command.c | 30 | ||||
-rw-r--r-- | src/command/commands.c | 110 |
2 files changed, 22 insertions, 118 deletions
diff --git a/src/command/command.c b/src/command/command.c index 470bb886..7fd1616e 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1814,15 +1814,7 @@ cmd_execute_default(const char * inp) if (otr_is_secure(chatwin->barejid)) { char *encrypted = otr_encrypt_message(chatwin->barejid, inp); if (encrypted != NULL) { - char *resource = NULL; - 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); + message_send_chat(chatwin->barejid, encrypted); otr_free_message(encrypted); if (prefs_get_boolean(PREF_CHLOG)) { const char *jid = jabber_get_fulljid(); @@ -1842,15 +1834,7 @@ cmd_execute_default(const char * inp) cons_show_error("Failed to send message."); } } else { - char *resource = NULL; - 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); + message_send_chat(chatwin->barejid, inp); if (prefs_get_boolean(PREF_CHLOG)) { const char *jid = jabber_get_fulljid(); Jid *jidp = jid_create(jid); @@ -1861,15 +1845,7 @@ cmd_execute_default(const char * inp) ui_outgoing_chat_msg("me", chatwin->barejid, inp); } #else - char *resource = NULL; - 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); + message_send_chat(chatwin->barejid, inp); if (prefs_get_boolean(PREF_CHLOG)) { const char *jid = jabber_get_fulljid(); Jid *jidp = jid_create(jid); diff --git a/src/command/commands.c b/src/command/commands.c index 89fe9557..049582c0 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1203,31 +1203,23 @@ cmd_msg(gchar **args, struct cmd_help_t help) barejid = usr; } - // if msg to current recipient, and resource specified, set resource - char *resource = NULL; - ProfWin *current = wins_get_current(); - if (current->type == WIN_CHAT) { - ProfChatWin *chatwin = (ProfChatWin*)current; - assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); - if ((g_strcmp0(chatwin->barejid, barejid) == 0) && (chatwin->resource)) { - resource = chatwin->resource; - } - } + // TODO if msg to current recipient, and resource specified, set resource +// char *resource = NULL; +// ProfWin *current = wins_get_current(); +// if (current->type == WIN_CHAT) { +// ProfChatWin *chatwin = (ProfChatWin*)current; +// assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); +// if ((g_strcmp0(chatwin->barejid, barejid) == 0) && (chatwin->resource)) { +// resource = chatwin->resource; +// } +// } if (msg != NULL) { #ifdef HAVE_LIBOTR if (otr_is_secure(barejid)) { char *encrypted = otr_encrypt_message(barejid, msg); if (encrypted != NULL) { - resource = NULL; - 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); + message_send_chat(barejid, encrypted); otr_free_message(encrypted); 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); g_string_append(otr_message, OTRL_MESSAGE_TAG_BASE); g_string_append(otr_message, OTRL_MESSAGE_TAG_V2); - resource = NULL; - 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); + message_send_chat(barejid, otr_message->str); g_string_free(otr_message, TRUE); } else { - resource = NULL; - 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); + message_send_chat(barejid, msg); } ui_outgoing_chat_msg("me", barejid, msg); @@ -1289,15 +1265,7 @@ cmd_msg(gchar **args, struct cmd_help_t help) } return TRUE; #else - resource = NULL; - 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); + message_send_chat(barejid, msg); ui_outgoing_chat_msg("me", barejid, msg); 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)) { char *encrypted = otr_encrypt_message(chatwin->barejid, tiny); if (encrypted != NULL) { - char *resource = NULL; - 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); + message_send_chat(chatwin->barejid, encrypted); otr_free_message(encrypted); if (prefs_get_boolean(PREF_CHLOG)) { 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."); } } else { - char *resource = NULL; - 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); + message_send_chat(chatwin->barejid, tiny); if (prefs_get_boolean(PREF_CHLOG)) { const char *jid = jabber_get_fulljid(); 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); } #else - char *resource = NULL; - 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); + message_send_chat(chatwin->barejid, tiny); if (prefs_get_boolean(PREF_CHLOG)) { const char *jid = jabber_get_fulljid(); 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'"); } else if (!otr_is_secure(barejid)) { char *otr_query_message = otr_start_query(); - char *resource = NULL; - 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); + message_send_chat(barejid, otr_query_message); } else { ui_gone_secure(barejid, otr_is_trusted(barejid)); } @@ -4034,15 +3970,7 @@ cmd_otr(gchar **args, struct cmd_help_t help) } else { ProfChatWin *chatwin = ui_get_current_chat(); char *otr_query_message = otr_start_query(); - char *resource = NULL; - 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); + message_send_chat(chatwin->barejid, otr_query_message); } } } |