1
1
mirror of https://github.com/profanity-im/profanity.git synced 2025-01-03 14:57:42 -05:00

Return result on OTR message sending

This commit is contained in:
James Booth 2015-04-29 22:59:44 +01:00
parent 0df8b8beff
commit 665c34414d
11 changed files with 75 additions and 50 deletions

View File

@ -110,7 +110,7 @@ cmd_execute_default(const char * inp)
case WIN_CHAT:
{
ProfChatWin *chatwin = wins_get_current_chat();
cl_ev_send_msg(chatwin->barejid, inp);
cl_ev_send_msg(chatwin, inp);
break;
}
case WIN_PRIVATE:
@ -1327,23 +1327,23 @@ cmd_msg(gchar **args, struct cmd_help_t help)
barejid = usr;
}
if (msg) {
cl_ev_send_msg(barejid, msg);
return TRUE;
} else {
ProfWin *window = (ProfWin*)wins_get_chat(barejid);
if (!window) {
window = ui_ev_new_chat_win(barejid);
}
ui_ev_focus_win(window);
ProfChatWin *chatwin = wins_get_chat(barejid);
if (!chatwin) {
chatwin = ui_ev_new_chat_win(barejid);
}
ui_ev_focus_win((ProfWin*)chatwin);
if (msg) {
cl_ev_send_msg(chatwin, msg);
} else {
#ifdef HAVE_LIBOTR
if (otr_is_secure(barejid)) {
ui_gone_secure(barejid, otr_is_trusted(barejid));
}
#endif
return TRUE;
}
return TRUE;
}
}
@ -3141,7 +3141,7 @@ cmd_tiny(gchar **args, struct cmd_help_t help)
case WIN_CHAT:
{
ProfChatWin *chatwin = wins_get_current_chat();
cl_ev_send_msg(chatwin->barejid, tiny);
cl_ev_send_msg(chatwin, tiny);
break;
}
case WIN_PRIVATE:
@ -4169,11 +4169,11 @@ cmd_otr(gchar **args, struct cmd_help_t help)
barejid = contact;
}
ProfWin *window = (ProfWin*)wins_get_chat(barejid);
if (!window) {
window = ui_ev_new_chat_win(barejid);
ProfChatWin *chatwin = wins_get_chat(barejid);
if (!chatwin) {
chatwin = ui_ev_new_chat_win(barejid);
}
ui_ev_focus_win(window);
ui_ev_focus_win((ProfWin*)chatwin);
if (ui_current_win_is_otr()) {
ui_current_print_formatted_line('!', 0, "You are already in an OTR session.");

View File

@ -37,6 +37,7 @@
#include "config.h"
#include "log.h"
#include "ui/ui.h"
#include "ui/windows.h"
#include "xmpp/xmpp.h"
#ifdef HAVE_LIBOTR
#include "otr/otr.h"
@ -60,14 +61,21 @@ cl_ev_connect_account(ProfAccount *account)
}
void
cl_ev_send_msg(const char * const barejid, const char * const msg)
cl_ev_send_msg(ProfChatWin *chatwin, const char * const msg)
{
chat_state_active(chatwin->state);
#ifdef HAVE_LIBOTR
otr_on_message_send(barejid, msg);
prof_otrsendres_t res = otr_on_message_send(chatwin->barejid, msg);
if (res != PROF_OTRSUCCESS) {
char *errmsg = otr_senderror_str(res);
// TODO reference passed window
ui_current_error_line(errmsg);
}
#else
char *id = message_send_chat(barejid, msg);
chat_log_msg_out(barejid, msg);
ui_outgoing_chat_msg(barejid, msg, id);
char *id = message_send_chat(chatwin->barejid, msg);
chat_log_msg_out(chatwin->barejid, msg);
ui_outgoing_chat_msg(chatwin->barejid, msg, id);
free(id);
#endif
}

View File

@ -38,7 +38,7 @@
jabber_conn_status_t cl_ev_connect_jid(const char * const jid, const char * const passwd, const char * const altdomain, const int port);
jabber_conn_status_t cl_ev_connect_account(ProfAccount *account);
void cl_ev_send_msg(const char * const barejid, const char * const msg);
void cl_ev_send_msg(ProfChatWin *chatwin, const char * const msg);
void cl_ev_send_muc_msg(const char * const roomjid, const char * const msg);
void cl_ev_send_priv_msg(const char * const fulljid, const char * const msg);

View File

@ -40,7 +40,7 @@ ui_ev_focus_win(ProfWin *win)
ui_switch_win(win);
}
ProfWin*
ProfChatWin*
ui_ev_new_chat_win(const char * const barejid)
{
return ui_new_chat_win(barejid);

View File

@ -36,6 +36,6 @@
#define UI_EVENTS_H
void ui_ev_focus_win(ProfWin *win);
ProfWin* ui_ev_new_chat_win(const char * const barejid);
ProfChatWin* ui_ev_new_chat_win(const char * const barejid);
#endif

View File

@ -313,7 +313,7 @@ otr_on_message_recv(const char * const barejid, const char * const resource, con
otr_free_message(decrypted);
}
void
prof_otrsendres_t
otr_on_message_send(const char * const barejid, const char * const message)
{
char *id = NULL;
@ -328,11 +328,11 @@ otr_on_message_send(const char * const barejid, const char * const message)
ui_outgoing_chat_msg(barejid, message, id);
otr_free_message(encrypted);
} else {
cons_show_error("Failed to encrypt and send message.");
return PROF_OTRENCFAIL;
}
} else if (policy == PROF_OTRPOLICY_ALWAYS) {
cons_show_error("Failed to send message. OTR policy set to: always");
return PROF_OTRPOLICYFAIL;
} else if (policy == PROF_OTRPOLICY_OPPORTUNISTIC) {
char *otr_tagged_msg = otr_tag_message(message);
@ -348,6 +348,8 @@ otr_on_message_send(const char * const barejid, const char * const message)
}
free(id);
return PROF_OTRSUCCESS;
}
void
@ -741,6 +743,16 @@ otr_decrypt_message(const char * const from, const char * const message, gboolea
}
}
char*
otr_senderror_str(prof_otrsendres_t res)
{
switch (res) {
case PROF_OTRENCFAIL: return "Failed to encrypt and send message.";
case PROF_OTRPOLICYFAIL: return "Failed to send message. OTR policy set to: always";
default: return "Unknown OTR error.";
}
}
void
otr_free_message(char *message)
{

View File

@ -46,6 +46,12 @@ typedef enum {
PROF_OTRPOLICY_ALWAYS
} prof_otrpolicy_t;
typedef enum {
PROF_OTRENCFAIL,
PROF_OTRPOLICYFAIL,
PROF_OTRSUCCESS
} prof_otrsendres_t;
OtrlUserState otr_userstate(void);
OtrlMessageAppOps* otr_messageops(void);
GHashTable* otr_smpinitators(void);
@ -58,7 +64,7 @@ void otr_poll(void);
void otr_on_connect(ProfAccount *account);
void otr_on_message_recv(const char * const barejid, const char * const resource, const char * const message);
void otr_on_message_send(const char * const barejid, const char * const message);
prof_otrsendres_t otr_on_message_send(const char * const barejid, const char * const message);
void otr_keygen(ProfAccount *account);
@ -88,4 +94,6 @@ void otr_free_message(char *message);
prof_otrpolicy_t otr_get_policy(const char * const recipient);
char* otr_senderror_str(prof_otrsendres_t res);
#endif

View File

@ -1395,7 +1395,7 @@ ui_open_xmlconsole_win(void)
}
}
ProfWin*
ProfChatWin*
ui_new_chat_win(const char * const barejid)
{
ProfWin *window = wins_new_chat(barejid);
@ -1421,7 +1421,7 @@ ui_new_chat_win(const char * const barejid)
}
}
return window;
return chatwin;
}
void
@ -1429,40 +1429,28 @@ ui_outgoing_chat_msg(const char * const barejid, const char * const message, cha
{
ProfWin *window = (ProfWin*)wins_get_chat(barejid);
// create new window
if (!window) {
window = ui_new_chat_win(barejid);
}
ProfChatWin *chatwin = (ProfChatWin*)window;
chat_state_active(chatwin->state);
if (prefs_get_boolean(PREF_RECEIPTS_REQUEST) && id) {
win_print_with_receipt(window, '-', NULL, 0, THEME_TEXT_ME, "me", message, id);
} else {
win_print(window, '-', NULL, 0, THEME_TEXT_ME, "me", message);
}
int num = wins_get_num(window);
ui_switch_win_num(num);
}
void
ui_outgoing_chat_msg_carbon(const char * const barejid, const char * const message)
{
ProfWin *window = (ProfWin*)wins_get_chat(barejid);
ProfChatWin *chatwin = wins_get_chat(barejid);
// create new window
if (!window) {
window = ui_new_chat_win(barejid);
if (!chatwin) {
chatwin = ui_new_chat_win(barejid);
}
ProfChatWin *chatwin = (ProfChatWin*)window;
chat_state_active(chatwin->state);
win_print(window, '-', NULL, 0, THEME_TEXT_ME, "me", message);
win_print((ProfWin*)chatwin, '-', NULL, 0, THEME_TEXT_ME, "me", message);
int num = wins_get_num(window);
int num = wins_get_num((ProfWin*)chatwin);
status_bar_active(num);
}

View File

@ -88,7 +88,7 @@ void ui_handle_otr_error(const char * const barejid, const char * const message)
unsigned long ui_get_idle_time(void);
void ui_reset_idle_time(void);
void ui_new_private_win(const char * const fulljid);
ProfWin* ui_new_chat_win(const char * const barejid);
ProfChatWin* ui_new_chat_win(const char * const barejid);
void ui_print_system_msg_from_recipient(const char * const barejid, const char *message);
gint ui_unread(void);
void ui_close_connected_win(int index);

View File

@ -42,7 +42,10 @@ char* otr_start_query(void)
void otr_poll(void) {}
void otr_on_connect(ProfAccount *account) {}
void otr_on_message_recv(const char * const barejid, const char * const resource, const char * const message) {}
void otr_on_message_send(const char * const barejid, const char * const message) {}
prof_otrsendres_t otr_on_message_send(const char * const barejid, const char * const message)
{
return PROF_OTRSUCCESS;
}
void otr_keygen(ProfAccount *account)
{
@ -106,3 +109,9 @@ prof_otrpolicy_t otr_get_policy(const char * const recipient)
{
return PROF_OTRPOLICY_MANUAL;
}
char* otr_senderror_str(prof_otrsendres_t res)
{
return NULL;
}

View File

@ -105,7 +105,7 @@ unsigned long ui_get_idle_time(void)
void ui_reset_idle_time(void) {}
void ui_new_private_win(const char * const fulljid) {}
ProfWin* ui_new_chat_win(const char * const barejid)
ProfChatWin* ui_new_chat_win(const char * const barejid)
{
return NULL;
}