From 848baa95a2bb74f85ab5c5442d89e5098060ae5a Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 16 Mar 2015 21:59:11 +0000 Subject: [PATCH] Added static function for sending otr tagged messages --- src/command/commands.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index ef912d88..e4717bff 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -75,6 +75,7 @@ static void _who_room(gchar **args, struct cmd_help_t help); static void _who_roster(gchar **args, struct cmd_help_t help); static void _send_chat_message(const char * const barejid, const char * const message); static void _send_otr_chat_message(const char * const barejid, const char * const message); +static void _send_otr_tagged_chat_message(const char * const barejid, const char * const message); extern GHashTable *commands; @@ -1358,31 +1359,22 @@ cmd_msg(gchar **args, struct cmd_help_t help) return TRUE; } else { - // get barejid char *barejid = roster_barejid_from_name(usr); if (barejid == NULL) { barejid = usr; } - if (msg != NULL) { + if (msg) { #ifdef HAVE_LIBOTR + prof_otrpolicy_t policy = otr_get_policy(barejid); if (otr_is_secure(barejid)) { _send_otr_chat_message(barejid, msg); + } else if (policy == PROF_OTRPOLICY_ALWAYS) { + cons_show_error("Failed to send message. Please check OTR policy"); + } else if (policy == PROF_OTRPOLICY_OPPORTUNISTIC) { + _send_otr_tagged_chat_message(barejid, msg); } else { - prof_otrpolicy_t policy = otr_get_policy(barejid); - if (policy == PROF_OTRPOLICY_ALWAYS) { - cons_show_error("Failed to send message. Please check OTR policy"); - return TRUE; - } else if (policy == PROF_OTRPOLICY_OPPORTUNISTIC) { - char *otr_tagged_msg = otr_tag_message(msg); - char *id = message_send_chat_encrypted(barejid, otr_tagged_msg); - ui_outgoing_chat_msg(barejid, msg, id); - chat_log_msg_out(barejid, msg); - free(id); - free(otr_tagged_msg); - } else { - _send_chat_message(barejid, msg); - } + _send_chat_message(barejid, msg); } return TRUE; #else @@ -1390,7 +1382,7 @@ cmd_msg(gchar **args, struct cmd_help_t help) return TRUE; #endif - } else { // msg == NULL + } else { ui_new_chat_win(barejid); #ifdef HAVE_LIBOTR if (otr_is_secure(barejid)) { @@ -4433,4 +4425,15 @@ _send_otr_chat_message(const char * const barejid, const char * const message) } else { cons_show_error("Failed to encrypt and send message."); } +} + +static void +_send_otr_tagged_chat_message(const char * const barejid, const char * const message) +{ + char *otr_tagged_msg = otr_tag_message(message); + char *id = message_send_chat_encrypted(barejid, otr_tagged_msg); + ui_outgoing_chat_msg(barejid, message, id); + chat_log_msg_out(barejid, message); + free(id); + free(otr_tagged_msg); } \ No newline at end of file