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

Added static function for sending otr tagged messages

This commit is contained in:
James Booth 2015-03-16 21:59:11 +00:00
parent 11966d39b0
commit 848baa95a2

View File

@ -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,39 +1359,30 @@ 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 {
prof_otrpolicy_t policy = otr_get_policy(barejid);
if (policy == PROF_OTRPOLICY_ALWAYS) {
} else 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);
_send_otr_tagged_chat_message(barejid, msg);
} else {
_send_chat_message(barejid, msg);
}
}
return TRUE;
#else
_send_chat_message(barejid, msg);
return TRUE;
#endif
} else { // msg == NULL
} else {
ui_new_chat_win(barejid);
#ifdef HAVE_LIBOTR
if (otr_is_secure(barejid)) {
@ -4434,3 +4426,14 @@ _send_otr_chat_message(const char * const barejid, const char * const message)
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);
}