Added static functions to commands.c for sending messages

This commit is contained in:
James Booth
2015-03-16 01:29:03 +00:00
parent e7e1688d8a
commit 981618b7da
2 changed files with 35 additions and 31 deletions

View File

@@ -76,6 +76,8 @@ static void _cmd_show_filtered_help(char *heading, gchar *cmd_filter[], int filt
static gint _compare_commands(Command *a, Command *b); static gint _compare_commands(Command *a, Command *b);
static void _who_room(gchar **args, struct cmd_help_t help); static void _who_room(gchar **args, struct cmd_help_t help);
static void _who_roster(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);
extern GHashTable *commands; extern GHashTable *commands;
@@ -121,24 +123,12 @@ cmd_execute_default(const char * inp)
return TRUE; return TRUE;
} }
if (otr_is_secure(chatwin->barejid)) { if (otr_is_secure(chatwin->barejid)) {
char *encrypted = otr_encrypt_message(chatwin->barejid, inp); _send_otr_chat_message(chatwin->barejid, inp);
if (encrypted != NULL) {
char *id = message_send_chat_encrypted(chatwin->barejid, encrypted);
otr_free_message(encrypted);
chat_log_otr_msg_out(chatwin->barejid, inp);
ui_outgoing_chat_msg(chatwin->barejid, inp, id);
} else {
cons_show_error("Failed to send message.");
}
} else { } else {
char *id = message_send_chat(chatwin->barejid, inp); _send_chat_message(chatwin->barejid, inp);
chat_log_msg_out(chatwin->barejid, inp);
ui_outgoing_chat_msg(chatwin->barejid, inp, id);
} }
#else #else
char *id = message_send_chat(chatwin->barejid, inp); _send_chat_message(chatwin->barejid, inp);
chat_log_msg_out(chatwin->barejid, inp);
ui_outgoing_chat_msg(chatwin->barejid, inp, id);
#endif #endif
} }
break; break;
@@ -1388,6 +1378,7 @@ cmd_msg(gchar **args, struct cmd_help_t help)
if (win_type == WIN_CHAT || win_type == WIN_CONSOLE) { if (win_type == WIN_CHAT || win_type == WIN_CONSOLE) {
chat_log_otr_msg_out(barejid, msg); chat_log_otr_msg_out(barejid, msg);
} }
free(id);
} else { } else {
cons_show_error("Failed to encrypt and send message,"); cons_show_error("Failed to encrypt and send message,");
} }
@@ -1412,6 +1403,7 @@ cmd_msg(gchar **args, struct cmd_help_t help)
if (win_type == WIN_CHAT || win_type == WIN_CONSOLE) { if (win_type == WIN_CHAT || win_type == WIN_CONSOLE) {
chat_log_msg_out(barejid, msg); chat_log_msg_out(barejid, msg);
} }
free(id);
} }
return TRUE; return TRUE;
#else #else
@@ -1420,6 +1412,7 @@ cmd_msg(gchar **args, struct cmd_help_t help)
if (win_type == WIN_CHAT || win_type == WIN_CONSOLE) { if (win_type == WIN_CHAT || win_type == WIN_CONSOLE) {
chat_log_msg_out(barejid, msg); chat_log_msg_out(barejid, msg);
} }
free(id);
return TRUE; return TRUE;
#endif #endif
@@ -3184,24 +3177,12 @@ cmd_tiny(gchar **args, struct cmd_help_t help)
ProfChatWin *chatwin = wins_get_current_chat(); ProfChatWin *chatwin = wins_get_current_chat();
#ifdef HAVE_LIBOTR #ifdef HAVE_LIBOTR
if (otr_is_secure(chatwin->barejid)) { if (otr_is_secure(chatwin->barejid)) {
char *encrypted = otr_encrypt_message(chatwin->barejid, tiny); _send_otr_chat_message(chatwin->barejid, tiny);
if (encrypted != NULL) {
char *id = message_send_chat_encrypted(chatwin->barejid, encrypted);
chat_log_otr_msg_out(chatwin->barejid, tiny);
ui_outgoing_chat_msg(chatwin->barejid, tiny, id);
otr_free_message(encrypted);
} else {
cons_show_error("Failed to send message.");
}
} else { } else {
char *id = message_send_chat(chatwin->barejid, tiny); _send_chat_message(chatwin->barejid, tiny);
chat_log_msg_out(chatwin->barejid, tiny);
ui_outgoing_chat_msg(chatwin->barejid, tiny, id);
} }
#else #else
char *id = message_send_chat(chatwin->barejid, tiny); _send_chat_message(chatwin->barejid, tiny);
chat_log_msg_out(chatwin->barejid, tiny);
ui_outgoing_chat_msg(chatwin->barejid, tiny, id);
#endif #endif
} else if (win_type == WIN_PRIVATE) { } else if (win_type == WIN_PRIVATE) {
ProfPrivateWin *privatewin = wins_get_current_private(); ProfPrivateWin *privatewin = wins_get_current_private();
@@ -4455,3 +4436,27 @@ gint _compare_commands(Command *a, Command *b)
return result; return result;
} }
static void
_send_chat_message(const char * const barejid, const char * const message)
{
char *id = message_send_chat(barejid, message);
chat_log_msg_out(barejid, message);
ui_outgoing_chat_msg(barejid, message, id);
free(id);
}
static void
_send_otr_chat_message(const char * const barejid, const char * const message)
{
char *encrypted = otr_encrypt_message(barejid, message);
if (encrypted != NULL) {
char *id = message_send_chat_encrypted(barejid, encrypted);
chat_log_otr_msg_out(barejid, message);
ui_outgoing_chat_msg(barejid, message, id);
otr_free_message(encrypted);
free(id);
} else {
cons_show_error("Failed to encrypt and send message.");
}
}

View File

@@ -906,7 +906,6 @@ win_print_with_receipt(ProfWin *window, const char show_char, GTimeVal *tstamp,
DeliveryReceipt *receipt = malloc(sizeof(struct delivery_receipt_t)); DeliveryReceipt *receipt = malloc(sizeof(struct delivery_receipt_t));
receipt->id = strdup(id); receipt->id = strdup(id);
receipt->received = FALSE; receipt->received = FALSE;
free(id);
buffer_push(window->layout->buffer, show_char, time, flags, theme_item, from, message, receipt); buffer_push(window->layout->buffer, show_char, time, flags, theme_item, from, message, receipt);
_win_print(window, show_char, time, flags, theme_item, from, message, receipt); _win_print(window, show_char, time, flags, theme_item, from, message, receipt);