Add prof_message_t to wrap all message attributes
Probably missing copy of body to plain in carbon and privmessage. Only covers the incoming message path because goal is OMEMO decryption of untrusted message. Cover some of the log functions but not all.
This commit is contained in:
@@ -241,23 +241,24 @@ chatwin_recipient_gone(ProfChatWin *chatwin)
|
||||
}
|
||||
|
||||
void
|
||||
chatwin_incoming_msg(ProfChatWin *chatwin, const char *const resource, const char *const message, GDateTime *timestamp, gboolean win_created, prof_enc_t enc_mode)
|
||||
chatwin_incoming_msg(ProfChatWin *chatwin, prof_message_t *message, gboolean win_created)
|
||||
{
|
||||
assert(chatwin != NULL);
|
||||
char *old_plain = message->plain;
|
||||
|
||||
char *plugin_message = plugins_pre_chat_message_display(chatwin->barejid, resource, message);
|
||||
message->plain = plugins_pre_chat_message_display(chatwin->barejid, message->jid->resourcepart, message->plain);
|
||||
|
||||
ProfWin *window = (ProfWin*)chatwin;
|
||||
int num = wins_get_num(window);
|
||||
|
||||
char *display_name = roster_get_msg_display_name(chatwin->barejid, resource);
|
||||
char *display_name = roster_get_msg_display_name(chatwin->barejid, message->jid->resourcepart);
|
||||
|
||||
gboolean is_current = wins_is_current(window);
|
||||
gboolean notify = prefs_do_chat_notify(is_current);
|
||||
|
||||
// currently viewing chat window with sender
|
||||
if (wins_is_current(window)) {
|
||||
win_print_incoming(window, timestamp, display_name, plugin_message, enc_mode);
|
||||
win_print_incoming(window, display_name, message);
|
||||
title_bar_set_typing(FALSE);
|
||||
status_bar_active(num, WIN_CHAT, chatwin->barejid);
|
||||
|
||||
@@ -277,14 +278,14 @@ chatwin_incoming_msg(ProfChatWin *chatwin, const char *const resource, const cha
|
||||
}
|
||||
|
||||
// show users status first, when receiving message via delayed delivery
|
||||
if (timestamp && win_created) {
|
||||
if (message->timestamp && win_created) {
|
||||
PContact pcontact = roster_get_contact(chatwin->barejid);
|
||||
if (pcontact) {
|
||||
win_show_contact(window, pcontact);
|
||||
}
|
||||
}
|
||||
|
||||
win_print_incoming(window, timestamp, display_name, plugin_message, enc_mode);
|
||||
win_print_incoming(window, display_name, message);
|
||||
}
|
||||
|
||||
if (prefs_get_boolean(PREF_BEEP)) {
|
||||
@@ -292,14 +293,15 @@ chatwin_incoming_msg(ProfChatWin *chatwin, const char *const resource, const cha
|
||||
}
|
||||
|
||||
if (notify) {
|
||||
notify_message(display_name, num, plugin_message);
|
||||
notify_message(display_name, num, message->plain);
|
||||
}
|
||||
|
||||
free(display_name);
|
||||
|
||||
plugins_post_chat_message_display(chatwin->barejid, resource, plugin_message);
|
||||
plugins_post_chat_message_display(chatwin->barejid, message->jid->resourcepart, message->plain);
|
||||
|
||||
free(plugin_message);
|
||||
free(message->plain);
|
||||
message->plain = old_plain;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -311,11 +313,11 @@ chatwin_outgoing_msg(ProfChatWin *chatwin, const char *const message, char *id,
|
||||
char enc_char = '-';
|
||||
if (chatwin->outgoing_char) {
|
||||
enc_char = chatwin->outgoing_char[0];
|
||||
} else if (enc_mode == PROF_MSG_OTR) {
|
||||
} else if (enc_mode == PROF_MSG_ENC_OTR) {
|
||||
enc_char = prefs_get_otr_char();
|
||||
} else if (enc_mode == PROF_MSG_PGP) {
|
||||
} else if (enc_mode == PROF_MSG_ENC_PGP) {
|
||||
enc_char = prefs_get_pgp_char();
|
||||
} else if (enc_mode == PROF_MSG_OMEMO) {
|
||||
} else if (enc_mode == PROF_MSG_ENC_OMEMO) {
|
||||
enc_char = prefs_get_omemo_char();
|
||||
}
|
||||
|
||||
@@ -332,9 +334,9 @@ chatwin_outgoing_carbon(ProfChatWin *chatwin, const char *const message, prof_en
|
||||
assert(chatwin != NULL);
|
||||
|
||||
char enc_char = '-';
|
||||
if (enc_mode == PROF_MSG_PGP) {
|
||||
if (enc_mode == PROF_MSG_ENC_PGP) {
|
||||
enc_char = prefs_get_pgp_char();
|
||||
} else if (enc_mode == PROF_MSG_OMEMO) {
|
||||
} else if (enc_mode == PROF_MSG_ENC_OMEMO) {
|
||||
enc_char = prefs_get_omemo_char();
|
||||
}
|
||||
|
||||
|
||||
@@ -383,7 +383,7 @@ mucwin_history(ProfMucWin *mucwin, const char *const nick, GDateTime *timestamp,
|
||||
}
|
||||
|
||||
static void
|
||||
_mucwin_print_mention(ProfWin *window, const char *const message, const char *const from, const char *const mynick, GSList *mentions, const char *const ch)
|
||||
_mucwin_print_mention(ProfWin *window, const char *const message, const char *const from, const char *const mynick, GSList *mentions, const char *const ch, int flags)
|
||||
{
|
||||
int last_pos = 0;
|
||||
int pos = 0;
|
||||
@@ -393,11 +393,11 @@ _mucwin_print_mention(ProfWin *window, const char *const message, const char *co
|
||||
|
||||
char *before_str = g_strndup(message + last_pos, pos - last_pos);
|
||||
if (strncmp(before_str, "/me ", 4) == 0) {
|
||||
win_print_them(window, THEME_ROOMMENTION, *ch, "");
|
||||
win_print_them(window, THEME_ROOMMENTION, *ch, flags, "");
|
||||
win_append_highlight(window, THEME_ROOMMENTION, "*%s ", from);
|
||||
win_append_highlight(window, THEME_ROOMMENTION, "%s", before_str + 4);
|
||||
} else {
|
||||
win_print_them(window, THEME_ROOMMENTION, *ch, from);
|
||||
win_print_them(window, THEME_ROOMMENTION, *ch, flags, from);
|
||||
win_append_highlight(window, THEME_ROOMMENTION, "%s", before_str);
|
||||
}
|
||||
g_free(before_str);
|
||||
@@ -512,11 +512,11 @@ mucwin_outgoing_msg(ProfMucWin *mucwin, const char *const message, const char *c
|
||||
char ch = '-';
|
||||
if (mucwin->message_char) {
|
||||
ch = mucwin->message_char[0];
|
||||
} else if (enc_mode == PROF_MSG_OTR) {
|
||||
} else if (enc_mode == PROF_MSG_ENC_OTR) {
|
||||
ch = prefs_get_otr_char();
|
||||
} else if (enc_mode == PROF_MSG_PGP) {
|
||||
} else if (enc_mode == PROF_MSG_ENC_PGP) {
|
||||
ch = prefs_get_pgp_char();
|
||||
} else if (enc_mode == PROF_MSG_OMEMO) {
|
||||
} else if (enc_mode == PROF_MSG_ENC_OMEMO) {
|
||||
ch = prefs_get_omemo_char();
|
||||
}
|
||||
|
||||
@@ -524,36 +524,41 @@ mucwin_outgoing_msg(ProfMucWin *mucwin, const char *const message, const char *c
|
||||
}
|
||||
|
||||
void
|
||||
mucwin_incoming_msg(ProfMucWin *mucwin, const char *const nick, const char *const message, const char *const id, GSList *mentions, GList *triggers, prof_enc_t enc_mode)
|
||||
mucwin_incoming_msg(ProfMucWin *mucwin, prof_message_t *message, GSList *mentions, GList *triggers)
|
||||
{
|
||||
assert(mucwin != NULL);
|
||||
int flags = 0;
|
||||
|
||||
if (id && g_hash_table_remove(mucwin->sent_messages, id)) {
|
||||
if (message->id && g_hash_table_remove(mucwin->sent_messages, message->id)) {
|
||||
/* Ignore reflection messages */
|
||||
return;
|
||||
}
|
||||
|
||||
if (!message->trusted) {
|
||||
flags |= NO_TRUST;
|
||||
}
|
||||
|
||||
ProfWin *window = (ProfWin*)mucwin;
|
||||
char *mynick = muc_nick(mucwin->roomjid);
|
||||
|
||||
char ch = '-';
|
||||
if (mucwin->message_char) {
|
||||
ch = mucwin->message_char[0];
|
||||
} else if (enc_mode == PROF_MSG_OTR) {
|
||||
} else if (message->enc == PROF_MSG_ENC_OTR) {
|
||||
ch = prefs_get_otr_char();
|
||||
} else if (enc_mode == PROF_MSG_PGP) {
|
||||
} else if (message->enc == PROF_MSG_ENC_PGP) {
|
||||
ch = prefs_get_pgp_char();
|
||||
} else if (enc_mode == PROF_MSG_OMEMO) {
|
||||
} else if (message->enc == PROF_MSG_ENC_OMEMO) {
|
||||
ch = prefs_get_omemo_char();
|
||||
}
|
||||
|
||||
if (g_slist_length(mentions) > 0) {
|
||||
_mucwin_print_mention(window, message, nick, mynick, mentions, &ch);
|
||||
_mucwin_print_mention(window, message->plain, message->jid->resourcepart, mynick, mentions, &ch, flags);
|
||||
} else if (triggers) {
|
||||
win_print_them(window, THEME_ROOMTRIGGER, ch, nick);
|
||||
_mucwin_print_triggers(window, message, triggers);
|
||||
win_print_them(window, THEME_ROOMTRIGGER, ch, flags, message->jid->resourcepart);
|
||||
_mucwin_print_triggers(window, message->plain, triggers);
|
||||
} else {
|
||||
win_println_them_message(window, ch, nick, "%s", message);
|
||||
win_println_them_message(window, ch, flags, message->jid->resourcepart, "%s", message->plain);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
#include "ui/window_list.h"
|
||||
|
||||
void
|
||||
privwin_incoming_msg(ProfPrivateWin *privatewin, const char *const message, GDateTime *timestamp)
|
||||
privwin_incoming_msg(ProfPrivateWin *privatewin, prof_message_t *message)
|
||||
{
|
||||
assert(privatewin != NULL);
|
||||
|
||||
@@ -60,7 +60,7 @@ privwin_incoming_msg(ProfPrivateWin *privatewin, const char *const message, GDat
|
||||
|
||||
// currently viewing chat window with sender
|
||||
if (wins_is_current(window)) {
|
||||
win_print_incoming(window, timestamp, jidp->resourcepart, message, PROF_MSG_PLAIN);
|
||||
win_print_incoming(window, jidp->resourcepart, message);
|
||||
title_bar_set_typing(FALSE);
|
||||
status_bar_active(num, WIN_PRIVATE, privatewin->fulljid);
|
||||
|
||||
@@ -68,7 +68,7 @@ privwin_incoming_msg(ProfPrivateWin *privatewin, const char *const message, GDat
|
||||
} else {
|
||||
status_bar_new(num, WIN_PRIVATE, privatewin->fulljid);
|
||||
cons_show_incoming_private_message(jidp->resourcepart, jidp->barejid, num, privatewin->unread);
|
||||
win_print_incoming(window, timestamp, jidp->resourcepart, message, PROF_MSG_PLAIN);
|
||||
win_print_incoming(window, jidp->resourcepart, message);
|
||||
|
||||
privatewin->unread++;
|
||||
|
||||
@@ -82,7 +82,7 @@ privwin_incoming_msg(ProfPrivateWin *privatewin, const char *const message, GDat
|
||||
}
|
||||
|
||||
if (notify) {
|
||||
notify_message(jidp->resourcepart, num, message);
|
||||
notify_message(jidp->resourcepart, num, message->plain);
|
||||
}
|
||||
|
||||
jid_destroy(jidp);
|
||||
|
||||
10
src/ui/ui.h
10
src/ui/ui.h
@@ -41,6 +41,7 @@
|
||||
#include "config/account.h"
|
||||
#include "command/cmd_funcs.h"
|
||||
#include "ui/win_types.h"
|
||||
#include "xmpp/message.h"
|
||||
#include "xmpp/muc.h"
|
||||
|
||||
#ifdef HAVE_LIBOTR
|
||||
@@ -52,6 +53,8 @@
|
||||
#define NO_EOL 4
|
||||
#define NO_COLOUR_FROM 8
|
||||
#define NO_COLOUR_DATE 16
|
||||
#define NO_TRUST 32
|
||||
|
||||
|
||||
// core UI
|
||||
void ui_init(void);
|
||||
@@ -117,8 +120,7 @@ gboolean ui_win_has_unsaved_form(int num);
|
||||
|
||||
// Chat window
|
||||
ProfChatWin* chatwin_new(const char *const barejid);
|
||||
void chatwin_incoming_msg(ProfChatWin *chatwin, const char *const resource, const char *const message,
|
||||
GDateTime *timestamp, gboolean win_created, prof_enc_t enc_mode);
|
||||
void chatwin_incoming_msg(ProfChatWin *chatwin, prof_message_t *message, gboolean win_created);
|
||||
void chatwin_receipt_received(ProfChatWin *chatwin, const char *const id);
|
||||
void chatwin_recipient_gone(ProfChatWin *chatwin);
|
||||
void chatwin_outgoing_msg(ProfChatWin *chatwin, const char *const message, char *id, prof_enc_t enc_mode,
|
||||
@@ -157,7 +159,7 @@ void mucwin_occupant_role_and_affiliation_change(ProfMucWin *mucwin, const char
|
||||
void mucwin_roster(ProfMucWin *mucwin, GList *occupants, const char *const presence);
|
||||
void mucwin_history(ProfMucWin *mucwin, const char *const nick, GDateTime *timestamp, const char *const message);
|
||||
void mucwin_outgoing_msg(ProfMucWin *mucwin, const char *const message, const char *const id, prof_enc_t enc_mode);
|
||||
void mucwin_incoming_msg(ProfMucWin *mucwin, const char *const nick, const char *const message, const char *const id, GSList *mentions, GList *triggers, prof_enc_t enc_mode);
|
||||
void mucwin_incoming_msg(ProfMucWin *mucwin, prof_message_t *message, GSList *mentions, GList *triggers);
|
||||
void mucwin_subject(ProfMucWin *mucwin, const char *const nick, const char *const subject);
|
||||
void mucwin_requires_config(ProfMucWin *mucwin);
|
||||
void mucwin_info(ProfMucWin *mucwin);
|
||||
@@ -195,7 +197,7 @@ void mucwin_set_message_char(ProfMucWin *mucwin, const char *const ch);
|
||||
void mucwin_unset_message_char(ProfMucWin *mucwin);
|
||||
|
||||
// MUC private chat window
|
||||
void privwin_incoming_msg(ProfPrivateWin *privatewin, const char *const message, GDateTime *timestamp);
|
||||
void privwin_incoming_msg(ProfPrivateWin *privatewin, prof_message_t *message);
|
||||
void privwin_outgoing_msg(ProfPrivateWin *privwin, const char *const message);
|
||||
void privwin_message_occupant_offline(ProfPrivateWin *privwin);
|
||||
|
||||
|
||||
@@ -1044,14 +1044,13 @@ win_show_status_string(ProfWin *window, const char *const from,
|
||||
}
|
||||
|
||||
void
|
||||
win_print_incoming(ProfWin *window, GDateTime *timestamp,
|
||||
const char *const from, const char *const message, prof_enc_t enc_mode)
|
||||
win_print_incoming(ProfWin *window, const char *const from, prof_message_t *message)
|
||||
{
|
||||
char enc_char = '-';
|
||||
int flags = NO_ME;
|
||||
|
||||
if (!trusted) {
|
||||
flags != NO_TRUST;
|
||||
if (!message->trusted) {
|
||||
flags |= NO_TRUST;
|
||||
}
|
||||
|
||||
switch (window->type)
|
||||
@@ -1061,18 +1060,18 @@ win_print_incoming(ProfWin *window, GDateTime *timestamp,
|
||||
ProfChatWin *chatwin = (ProfChatWin*)window;
|
||||
if (chatwin->incoming_char) {
|
||||
enc_char = chatwin->incoming_char[0];
|
||||
} else if (enc_mode == PROF_MSG_OTR) {
|
||||
} else if (message->enc == PROF_MSG_ENC_OTR) {
|
||||
enc_char = prefs_get_otr_char();
|
||||
} else if (enc_mode == PROF_MSG_PGP) {
|
||||
} else if (message->enc == PROF_MSG_ENC_PGP) {
|
||||
enc_char = prefs_get_pgp_char();
|
||||
} else if (enc_mode == PROF_MSG_OMEMO) {
|
||||
} else if (message->enc == PROF_MSG_ENC_OMEMO) {
|
||||
enc_char = prefs_get_omemo_char();
|
||||
}
|
||||
_win_printf(window, enc_char, 0, timestamp, flags, THEME_TEXT_THEM, from, "%s", message);
|
||||
_win_printf(window, enc_char, 0, message->timestamp, flags, THEME_TEXT_THEM, from, "%s", message->plain);
|
||||
break;
|
||||
}
|
||||
case WIN_PRIVATE:
|
||||
_win_printf(window, '-', 0, timestamp, flags, THEME_TEXT_THEM, from, "%s", message);
|
||||
_win_printf(window, '-', 0, message->timestamp, flags, THEME_TEXT_THEM, from, "%s", message->plain);
|
||||
break;
|
||||
default:
|
||||
assert(FALSE);
|
||||
@@ -1081,13 +1080,13 @@ win_print_incoming(ProfWin *window, GDateTime *timestamp,
|
||||
}
|
||||
|
||||
void
|
||||
win_print_them(ProfWin *window, theme_item_t theme_item, char ch, const char *const them)
|
||||
win_print_them(ProfWin *window, theme_item_t theme_item, char ch, int flags, const char *const them)
|
||||
{
|
||||
_win_printf(window, ch, 0, NULL, NO_ME | NO_EOL, theme_item, them, "");
|
||||
_win_printf(window, ch, 0, NULL, flags | NO_ME | NO_EOL, theme_item, them, "");
|
||||
}
|
||||
|
||||
void
|
||||
win_println_them_message(ProfWin *window, char ch, const char *const them, const char *const message, ...)
|
||||
win_println_them_message(ProfWin *window, char ch, int flags, const char *const them, const char *const message, ...)
|
||||
{
|
||||
GDateTime *timestamp = g_date_time_new_now_local();
|
||||
|
||||
@@ -1096,9 +1095,9 @@ win_println_them_message(ProfWin *window, char ch, const char *const them, const
|
||||
GString *fmt_msg = g_string_new(NULL);
|
||||
g_string_vprintf(fmt_msg, message, arg);
|
||||
|
||||
buffer_append(window->layout->buffer, ch, 0, timestamp, NO_ME, THEME_TEXT_THEM, them, fmt_msg->str, NULL);
|
||||
buffer_append(window->layout->buffer, ch, 0, timestamp, flags | NO_ME, THEME_TEXT_THEM, them, fmt_msg->str, NULL);
|
||||
|
||||
_win_print(window, ch, 0, timestamp, NO_ME, THEME_TEXT_THEM, them, fmt_msg->str, NULL);
|
||||
_win_print(window, ch, 0, timestamp, flags | NO_ME, THEME_TEXT_THEM, them, fmt_msg->str, NULL);
|
||||
inp_nonblocking(TRUE);
|
||||
g_date_time_unref(timestamp);
|
||||
|
||||
|
||||
@@ -60,13 +60,12 @@ void win_show_status_string(ProfWin *window, const char *const from,
|
||||
GDateTime *last_activity, const char *const pre,
|
||||
const char *const default_show);
|
||||
|
||||
void win_print_them(ProfWin *window, theme_item_t theme_item, char ch, const char *const them);
|
||||
void win_println_them_message(ProfWin *window, char ch, const char *const them, const char *const message, ...);
|
||||
void win_print_them(ProfWin *window, theme_item_t theme_item, char ch, int flags, const char *const them);
|
||||
void win_println_them_message(ProfWin *window, char ch, int flags, const char *const them, const char *const message, ...);
|
||||
void win_println_me_message(ProfWin *window, char ch, const char *const me, const char *const message, ...);
|
||||
|
||||
void win_print_outgoing(ProfWin *window, const char ch, const char *const message, ...);
|
||||
void win_print_incoming(ProfWin *window, GDateTime *timestamp,
|
||||
const char *const from, const char *const message, prof_enc_t enc_mode);
|
||||
void win_print_incoming(ProfWin *window, const char *const from, prof_message_t *message);
|
||||
void win_print_history(ProfWin *window, GDateTime *timestamp, const char *const message, ...);
|
||||
|
||||
void win_print_http_upload(ProfWin *window, const char *const message, char *url);
|
||||
|
||||
Reference in New Issue
Block a user