mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
Merge branch 'master' into pgp
This commit is contained in:
commit
0fece78dfe
@ -113,7 +113,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:
|
||||
@ -1338,24 +1338,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) {
|
||||
ui_ev_focus_win(window);
|
||||
} else {
|
||||
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((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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -3153,7 +3152,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:
|
||||
@ -4236,12 +4235,11 @@ cmd_otr(gchar **args, struct cmd_help_t help)
|
||||
barejid = contact;
|
||||
}
|
||||
|
||||
ProfWin *window = (ProfWin*)wins_get_chat(barejid);
|
||||
if (window) {
|
||||
ui_ev_focus_win(window);
|
||||
} else {
|
||||
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((ProfWin*)chatwin);
|
||||
|
||||
if (ui_current_win_is_otr()) {
|
||||
ui_current_print_formatted_line('!', 0, "You are already in an OTR session.");
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -40,9 +40,8 @@ ui_ev_focus_win(ProfWin *win)
|
||||
ui_switch_win(win);
|
||||
}
|
||||
|
||||
void
|
||||
ProfChatWin*
|
||||
ui_ev_new_chat_win(const char * const barejid)
|
||||
{
|
||||
ProfWin *win = ui_new_chat_win(barejid);
|
||||
ui_switch_win(win);
|
||||
return ui_new_chat_win(barejid);
|
||||
}
|
@ -36,6 +36,6 @@
|
||||
#define UI_EVENTS_H
|
||||
|
||||
void ui_ev_focus_win(ProfWin *win);
|
||||
void ui_ev_new_chat_win(const char * const barejid);
|
||||
ProfChatWin* ui_ev_new_chat_win(const char * const barejid);
|
||||
|
||||
#endif
|
@ -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;
|
||||
@ -322,17 +322,17 @@ otr_on_message_send(const char * const barejid, const char * const message)
|
||||
|
||||
if (otr_is_secure(barejid)) {
|
||||
char *encrypted = otr_encrypt_message(barejid, message);
|
||||
if (encrypted != NULL) {
|
||||
if (encrypted) {
|
||||
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);
|
||||
} 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. Please check OTR policy");
|
||||
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)
|
||||
{
|
||||
|
@ -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
|
||||
|
191
src/ui/core.c
191
src/ui/core.c
@ -88,7 +88,7 @@ static Display *display;
|
||||
static GTimer *ui_idle_time;
|
||||
|
||||
//static void _win_handle_switch(const wint_t ch);
|
||||
static void _win_show_history(int win_index, const char * const contact);
|
||||
static void _win_show_history(ProfChatWin *chatwin, const char * const contact);
|
||||
static void _ui_draw_term_title(void);
|
||||
|
||||
void
|
||||
@ -441,7 +441,7 @@ ui_incoming_msg(const char * const barejid, const char * const resource, const c
|
||||
|
||||
chatwin->unread++;
|
||||
if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) {
|
||||
_win_show_history(num, barejid);
|
||||
_win_show_history(chatwin, barejid);
|
||||
}
|
||||
|
||||
// show users status first, when receiving message via delayed delivery
|
||||
@ -501,19 +501,14 @@ ui_incoming_private_msg(const char * const fulljid, const char * const message,
|
||||
|
||||
// not currently viewing chat window with sender
|
||||
} else {
|
||||
privatewin->unread++;
|
||||
status_bar_new(num);
|
||||
cons_show_incoming_message(display_from, num);
|
||||
win_print_incoming_message(window, tv_stamp, display_from, message);
|
||||
|
||||
if (prefs_get_boolean(PREF_FLASH)) {
|
||||
flash();
|
||||
}
|
||||
|
||||
privatewin->unread++;
|
||||
if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) {
|
||||
_win_show_history(num, fulljid);
|
||||
}
|
||||
|
||||
win_print_incoming_message(window, tv_stamp, display_from, message);
|
||||
}
|
||||
|
||||
int ui_index = num;
|
||||
@ -1365,30 +1360,6 @@ ui_recipient_gone(const char * const barejid, const char * const resource)
|
||||
}
|
||||
}
|
||||
|
||||
ProfWin*
|
||||
ui_new_chat_win(const char * const barejid)
|
||||
{
|
||||
ProfWin* window = wins_new_chat(barejid);
|
||||
|
||||
int num = wins_get_num(window);
|
||||
|
||||
if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) {
|
||||
_win_show_history(num, barejid);
|
||||
}
|
||||
|
||||
// if the contact is offline, show a message
|
||||
PContact contact = roster_get_contact(barejid);
|
||||
if (contact != NULL) {
|
||||
if (strcmp(p_contact_presence(contact), "offline") == 0) {
|
||||
const char * const show = p_contact_presence(contact);
|
||||
const char * const status = p_contact_status(contact);
|
||||
win_show_status_string(window, barejid, show, status, NULL, "--", "offline");
|
||||
}
|
||||
}
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
void
|
||||
ui_new_private_win(const char * const fulljid)
|
||||
{
|
||||
@ -1424,89 +1395,62 @@ ui_open_xmlconsole_win(void)
|
||||
}
|
||||
}
|
||||
|
||||
ProfChatWin*
|
||||
ui_new_chat_win(const char * const barejid)
|
||||
{
|
||||
ProfWin *window = wins_new_chat(barejid);
|
||||
ProfChatWin *chatwin = (ProfChatWin *)window;
|
||||
|
||||
#ifdef HAVE_LIBOTR
|
||||
if (otr_is_secure(barejid)) {
|
||||
chatwin->is_otr = TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) {
|
||||
_win_show_history(chatwin, barejid);
|
||||
}
|
||||
|
||||
// if the contact is offline, show a message
|
||||
PContact contact = roster_get_contact(barejid);
|
||||
if (contact) {
|
||||
if (strcmp(p_contact_presence(contact), "offline") == 0) {
|
||||
const char * const show = p_contact_presence(contact);
|
||||
const char * const status = p_contact_status(contact);
|
||||
win_show_status_string(window, barejid, show, status, NULL, "--", "offline");
|
||||
}
|
||||
}
|
||||
|
||||
return chatwin;
|
||||
}
|
||||
|
||||
void
|
||||
ui_outgoing_chat_msg(const char * const barejid, const char * const message, char *id)
|
||||
{
|
||||
PContact contact = roster_get_contact(barejid);
|
||||
ProfWin *window = (ProfWin*)wins_get_chat(barejid);
|
||||
int num = 0;
|
||||
|
||||
// create new window
|
||||
if (window == NULL) {
|
||||
window = wins_new_chat(barejid);
|
||||
#ifdef HAVE_LIBOTR
|
||||
ProfChatWin *chatwin = (ProfChatWin*)window;
|
||||
if (otr_is_secure(barejid)) {
|
||||
chatwin->is_otr = TRUE;
|
||||
}
|
||||
#endif
|
||||
num = wins_get_num(window);
|
||||
|
||||
if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) {
|
||||
_win_show_history(num, barejid);
|
||||
}
|
||||
|
||||
if (contact != NULL) {
|
||||
if (strcmp(p_contact_presence(contact), "offline") == 0) {
|
||||
const char *show = p_contact_presence(contact);
|
||||
const char *status = p_contact_status(contact);
|
||||
win_show_status_string(window, barejid, show, status, NULL, "--", "offline");
|
||||
}
|
||||
}
|
||||
|
||||
// use existing window
|
||||
} else {
|
||||
num = wins_get_num(window);
|
||||
}
|
||||
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);
|
||||
}
|
||||
ui_switch_win_num(num);
|
||||
}
|
||||
|
||||
void
|
||||
ui_outgoing_chat_msg_carbon(const char * const barejid, const char * const message)
|
||||
{
|
||||
PContact contact = roster_get_contact(barejid);
|
||||
ProfWin *window = (ProfWin*)wins_get_chat(barejid);
|
||||
int num = 0;
|
||||
ProfChatWin *chatwin = wins_get_chat(barejid);
|
||||
|
||||
// create new window
|
||||
if (window == NULL) {
|
||||
window = wins_new_chat(barejid);
|
||||
#ifdef HAVE_LIBOTR
|
||||
ProfChatWin *chatwin = (ProfChatWin*)window;
|
||||
if (otr_is_secure(barejid)) {
|
||||
chatwin->is_otr = TRUE;
|
||||
}
|
||||
#endif
|
||||
num = wins_get_num(window);
|
||||
|
||||
if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) {
|
||||
_win_show_history(num, barejid);
|
||||
}
|
||||
|
||||
if (contact != NULL) {
|
||||
if (strcmp(p_contact_presence(contact), "offline") == 0) {
|
||||
const char *show = p_contact_presence(contact);
|
||||
const char *status = p_contact_status(contact);
|
||||
win_show_status_string(window, barejid, show, status, NULL, "--", "offline");
|
||||
}
|
||||
}
|
||||
|
||||
// use existing window
|
||||
} else {
|
||||
num = wins_get_num(window);
|
||||
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((ProfWin*)chatwin);
|
||||
status_bar_active(num);
|
||||
}
|
||||
|
||||
@ -3003,39 +2947,34 @@ ui_hide_roster(void)
|
||||
}
|
||||
|
||||
static void
|
||||
_win_show_history(int win_index, const char * const contact)
|
||||
_win_show_history(ProfChatWin *chatwin, const char * const contact)
|
||||
{
|
||||
ProfWin *window = wins_get_by_num(win_index);
|
||||
if (window->type == WIN_CHAT) {
|
||||
ProfChatWin *chatwin = (ProfChatWin*) window;
|
||||
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
|
||||
if (!chatwin->history_shown) {
|
||||
Jid *jid = jid_create(jabber_get_fulljid());
|
||||
GSList *history = chat_log_get_previous(jid->barejid, contact);
|
||||
jid_destroy(jid);
|
||||
GSList *curr = history;
|
||||
while (curr != NULL) {
|
||||
char *line = curr->data;
|
||||
// entry
|
||||
if (line[2] == ':') {
|
||||
char hh[3]; memcpy(hh, &line[0], 2); hh[2] = '\0'; int ihh = atoi(hh);
|
||||
char mm[3]; memcpy(mm, &line[3], 2); mm[2] = '\0'; int imm = atoi(mm);
|
||||
char ss[3]; memcpy(ss, &line[6], 2); ss[2] = '\0'; int iss = atoi(ss);
|
||||
GDateTime *time = g_date_time_new_local(2000, 1, 1, ihh, imm, iss);
|
||||
GTimeVal tv;
|
||||
g_date_time_to_timeval(time, &tv);
|
||||
win_print(window, '-', &tv, NO_COLOUR_DATE, 0, "", curr->data+11);
|
||||
g_date_time_unref(time);
|
||||
// header
|
||||
} else {
|
||||
win_print(window, '-', NULL, 0, 0, "", curr->data);
|
||||
}
|
||||
curr = g_slist_next(curr);
|
||||
if (!chatwin->history_shown) {
|
||||
Jid *jid = jid_create(jabber_get_fulljid());
|
||||
GSList *history = chat_log_get_previous(jid->barejid, contact);
|
||||
jid_destroy(jid);
|
||||
GSList *curr = history;
|
||||
while (curr != NULL) {
|
||||
char *line = curr->data;
|
||||
// entry
|
||||
if (line[2] == ':') {
|
||||
char hh[3]; memcpy(hh, &line[0], 2); hh[2] = '\0'; int ihh = atoi(hh);
|
||||
char mm[3]; memcpy(mm, &line[3], 2); mm[2] = '\0'; int imm = atoi(mm);
|
||||
char ss[3]; memcpy(ss, &line[6], 2); ss[2] = '\0'; int iss = atoi(ss);
|
||||
GDateTime *time = g_date_time_new_local(2000, 1, 1, ihh, imm, iss);
|
||||
GTimeVal tv;
|
||||
g_date_time_to_timeval(time, &tv);
|
||||
win_print((ProfWin*)chatwin, '-', &tv, NO_COLOUR_DATE, 0, "", curr->data+11);
|
||||
g_date_time_unref(time);
|
||||
// header
|
||||
} else {
|
||||
win_print((ProfWin*)chatwin, '-', NULL, 0, 0, "", curr->data);
|
||||
}
|
||||
chatwin->history_shown = TRUE;
|
||||
|
||||
g_slist_free_full(history, free);
|
||||
curr = g_slist_next(curr);
|
||||
}
|
||||
chatwin->history_shown = TRUE;
|
||||
|
||||
g_slist_free_full(history, free);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user