aboutsummaryrefslogtreecommitdiffstats
path: root/src/command
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-03-16 21:59:11 +0000
committerJames Booth <boothj5@gmail.com>2015-03-16 21:59:11 +0000
commit848baa95a2bb74f85ab5c5442d89e5098060ae5a (patch)
tree0ce1e4cc96b473ce0c57723fca8e308df84612c0 /src/command
parent11966d39b074e0bff4228067055807274d5d4834 (diff)
downloadprofani-tty-848baa95a2bb74f85ab5c5442d89e5098060ae5a.tar.gz
Added static function for sending otr tagged messages
Diffstat (limited to 'src/command')
-rw-r--r--src/command/commands.c37
1 files 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