mirror of
https://github.com/profanity-im/profanity.git
synced 2025-01-03 14:57:42 -05:00
MAM: Correctly display incoming MAM chat message
This commit is contained in:
parent
180ec2b474
commit
dd566d8d56
@ -622,16 +622,30 @@ void
|
||||
sv_ev_incoming_message(ProfMessage *message)
|
||||
{
|
||||
gboolean new_win = FALSE;
|
||||
ProfChatWin *chatwin = wins_get_chat(message->from_jid->barejid);
|
||||
ProfChatWin *chatwin;
|
||||
char *looking_for_jid = message->from_jid->barejid;
|
||||
|
||||
if (message->is_mam) {
|
||||
Jid *my_jid = jid_create(connection_get_fulljid());
|
||||
if (g_strcmp0(my_jid->barejid, message->from_jid->barejid) == 0) {
|
||||
looking_for_jid = message->to_jid->barejid;
|
||||
}
|
||||
jid_destroy(my_jid);
|
||||
}
|
||||
|
||||
chatwin = wins_get_chat(looking_for_jid);
|
||||
|
||||
if (!chatwin) {
|
||||
ProfWin *window = wins_new_chat(message->from_jid->barejid);
|
||||
ProfWin *window = wins_new_chat(looking_for_jid);
|
||||
chatwin = (ProfChatWin*)window;
|
||||
new_win = TRUE;
|
||||
|
||||
#ifdef HAVE_OMEMO
|
||||
if (omemo_automatic_start(message->from_jid->barejid)) {
|
||||
omemo_start_session(message->from_jid->barejid);
|
||||
chatwin->is_omemo = TRUE;
|
||||
if (!message->is_mam) {
|
||||
if (omemo_automatic_start(message->from_jid->barejid)) {
|
||||
omemo_start_session(message->from_jid->barejid);
|
||||
chatwin->is_omemo = TRUE;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -251,12 +251,19 @@ chatwin_incoming_msg(ProfChatWin *chatwin, ProfMessage *message, gboolean win_cr
|
||||
assert(chatwin != NULL);
|
||||
char *old_plain = message->plain;
|
||||
|
||||
message->plain = plugins_pre_chat_message_display(chatwin->barejid, message->from_jid->resourcepart, message->plain);
|
||||
message->plain = plugins_pre_chat_message_display(message->from_jid->barejid, message->from_jid->resourcepart, message->plain);
|
||||
|
||||
ProfWin *window = (ProfWin*)chatwin;
|
||||
int num = wins_get_num(window);
|
||||
|
||||
char *display_name = roster_get_msg_display_name(chatwin->barejid, message->from_jid->resourcepart);
|
||||
char *display_name;
|
||||
Jid *my_jid = jid_create(connection_get_fulljid());
|
||||
if (g_strcmp0(my_jid->barejid, message->from_jid->barejid) == 0) {
|
||||
display_name = strdup("me");
|
||||
} else {
|
||||
display_name = roster_get_msg_display_name(message->from_jid->barejid, message->from_jid->resourcepart);
|
||||
}
|
||||
jid_destroy(my_jid);
|
||||
|
||||
gboolean is_current = wins_is_current(window);
|
||||
gboolean notify = prefs_do_chat_notify(is_current);
|
||||
@ -304,7 +311,7 @@ chatwin_incoming_msg(ProfChatWin *chatwin, ProfMessage *message, gboolean win_cr
|
||||
|
||||
free(display_name);
|
||||
|
||||
plugins_post_chat_message_display(chatwin->barejid, message->from_jid->resourcepart, message->plain);
|
||||
plugins_post_chat_message_display(message->from_jid->barejid, message->from_jid->resourcepart, message->plain);
|
||||
|
||||
free(message->plain);
|
||||
message->plain = old_plain;
|
||||
|
@ -84,7 +84,7 @@ static void _handle_muc_private_message(xmpp_stanza_t *const stanza);
|
||||
static void _handle_conference(xmpp_stanza_t *const stanza);
|
||||
static void _handle_captcha(xmpp_stanza_t *const stanza);
|
||||
static void _handle_receipt_received(xmpp_stanza_t *const stanza);
|
||||
static void _handle_chat(xmpp_stanza_t *const stanza);
|
||||
static void _handle_chat(xmpp_stanza_t *const stanza, gboolean is_mam);
|
||||
static gboolean _handle_mam(xmpp_stanza_t *const stanza);
|
||||
|
||||
static void _send_message_stanza(xmpp_stanza_t *const stanza);
|
||||
@ -166,7 +166,7 @@ _message_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *con
|
||||
}
|
||||
}
|
||||
|
||||
_handle_chat(stanza);
|
||||
_handle_chat(stanza, FALSE);
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -1161,7 +1161,7 @@ out:
|
||||
}
|
||||
|
||||
static void
|
||||
_handle_chat(xmpp_stanza_t *const stanza)
|
||||
_handle_chat(xmpp_stanza_t *const stanza, gboolean is_mam)
|
||||
{
|
||||
// ignore if type not chat or absent
|
||||
const char *type = xmpp_stanza_get_type(stanza);
|
||||
@ -1206,10 +1206,15 @@ _handle_chat(xmpp_stanza_t *const stanza)
|
||||
|
||||
// standard chat message, use jid without resource
|
||||
ProfMessage *message = message_init();
|
||||
// TODO: safe to_jid too. also need to have the same check like in carbons. in case this is MAM.
|
||||
// or have a is_mam and handle later.
|
||||
message->from_jid = jid;
|
||||
message->type = PROF_MSG_TYPE_CHAT;
|
||||
message->from_jid = jid;
|
||||
|
||||
const gchar *to_text = xmpp_stanza_get_to(stanza);
|
||||
if (to_text) {
|
||||
message->to_jid = jid_create(to_text);
|
||||
}
|
||||
|
||||
message->is_mam = is_mam;
|
||||
|
||||
// message stanza id
|
||||
const char *id = xmpp_stanza_get_id(stanza);
|
||||
@ -1296,7 +1301,7 @@ _handle_mam(xmpp_stanza_t *const stanza)
|
||||
}
|
||||
|
||||
xmpp_stanza_t *message_stanza = xmpp_stanza_get_child_by_ns(forwarded, "jabber:client");
|
||||
_handle_chat(message_stanza);
|
||||
_handle_chat(message_stanza, TRUE);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -155,6 +155,7 @@ typedef struct prof_message_t {
|
||||
GDateTime *timestamp;
|
||||
prof_enc_t enc;
|
||||
gboolean trusted;
|
||||
gboolean is_mam;
|
||||
prof_msg_type_t type;
|
||||
} ProfMessage;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user