mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
Add to_jid field to ProfMessage struct
Is usefult in many cases if we want cleaner code. Hope this edit didn't break anything though ;-)
This commit is contained in:
parent
e23bc38083
commit
180ec2b474
@ -166,7 +166,7 @@ log_database_add_incoming(ProfMessage *message)
|
||||
const char *jid = connection_get_fulljid();
|
||||
Jid *myjid = jid_create(jid);
|
||||
|
||||
_add_to_db(message, NULL, message->jid, myjid);
|
||||
_add_to_db(message, NULL, message->from_jid, myjid);
|
||||
|
||||
jid_destroy(myjid);
|
||||
}
|
||||
@ -177,7 +177,7 @@ _log_database_add_outgoing(char *type, const char * const id, const char * const
|
||||
ProfMessage *msg = message_init();
|
||||
|
||||
msg->id = id ? strdup(id) : NULL;
|
||||
msg->jid = jid_create(barejid);
|
||||
msg->from_jid = jid_create(barejid);
|
||||
msg->plain = message ? strdup(message) : NULL;
|
||||
msg->replace_id = replace_id ? strdup(replace_id) : NULL;
|
||||
msg->timestamp = g_date_time_new_now_local(); //TODO: get from outside. best to have whole ProfMessage from outside
|
||||
@ -186,7 +186,7 @@ _log_database_add_outgoing(char *type, const char * const id, const char * const
|
||||
const char *jid = connection_get_fulljid();
|
||||
Jid *myjid = jid_create(jid);
|
||||
|
||||
_add_to_db(msg, type, myjid, msg->jid);
|
||||
_add_to_db(msg, type, myjid, msg->from_jid); // TODO: myjid now in profmessage
|
||||
|
||||
jid_destroy(myjid);
|
||||
message_free(msg);
|
||||
@ -234,13 +234,14 @@ log_database_get_previous_chat(const gchar *const contact_barejid)
|
||||
GSList *history = NULL;
|
||||
|
||||
while( sqlite3_step(stmt) == SQLITE_ROW ) {
|
||||
// TODO: also save to jid. since now part of profmessage
|
||||
char *message = (char*)sqlite3_column_text(stmt, 0);
|
||||
char *date = (char*)sqlite3_column_text(stmt, 1);
|
||||
char *from = (char*)sqlite3_column_text(stmt, 2);
|
||||
char *type = (char*)sqlite3_column_text(stmt, 3);
|
||||
|
||||
ProfMessage *msg = message_init();
|
||||
msg->jid = jid_create(from);
|
||||
msg->from_jid = jid_create(from);
|
||||
msg->plain = strdup(message);
|
||||
msg->timestamp = g_date_time_new_from_iso8601(date, NULL);
|
||||
msg->type = _get_message_type_type(type);
|
||||
|
@ -275,7 +275,7 @@ sv_ev_room_subject(const char *const room, const char *const nick, const char *c
|
||||
void
|
||||
sv_ev_room_history(ProfMessage *message)
|
||||
{
|
||||
ProfMucWin *mucwin = wins_get_muc(message->jid->barejid);
|
||||
ProfMucWin *mucwin = wins_get_muc(message->from_jid->barejid);
|
||||
if (mucwin) {
|
||||
// if this is the first successful connection
|
||||
if (ev_is_first_connect()) {
|
||||
@ -297,9 +297,9 @@ sv_ev_room_history(ProfMessage *message)
|
||||
static void _log_muc(ProfMessage *message)
|
||||
{
|
||||
if (message->enc == PROF_MSG_ENC_OMEMO) {
|
||||
groupchat_log_omemo_msg_in(message->jid->barejid, message->jid->resourcepart, message->plain);
|
||||
groupchat_log_omemo_msg_in(message->from_jid->barejid, message->from_jid->resourcepart, message->plain);
|
||||
} else {
|
||||
groupchat_log_msg_in(message->jid->barejid, message->jid->resourcepart, message->plain);
|
||||
groupchat_log_msg_in(message->from_jid->barejid, message->from_jid->resourcepart, message->plain);
|
||||
}
|
||||
log_database_add_incoming(message);
|
||||
}
|
||||
@ -307,7 +307,7 @@ static void _log_muc(ProfMessage *message)
|
||||
void
|
||||
sv_ev_room_message(ProfMessage *message)
|
||||
{
|
||||
ProfMucWin *mucwin = wins_get_muc(message->jid->barejid);
|
||||
ProfMucWin *mucwin = wins_get_muc(message->from_jid->barejid);
|
||||
if (!mucwin) {
|
||||
return;
|
||||
}
|
||||
@ -316,12 +316,12 @@ sv_ev_room_message(ProfMessage *message)
|
||||
|
||||
// only log message not coming from this client (but maybe same account, different client)
|
||||
// our messages are logged when outgoing
|
||||
if (!(g_strcmp0(mynick, message->jid->resourcepart) == 0 && message_is_sent_by_us(message, TRUE))) {
|
||||
if (!(g_strcmp0(mynick, message->from_jid->resourcepart) == 0 && message_is_sent_by_us(message, TRUE))) {
|
||||
_log_muc(message);
|
||||
}
|
||||
|
||||
char *old_plain = message->plain;
|
||||
message->plain = plugins_pre_room_message_display(message->jid->barejid, message->jid->resourcepart, message->plain);
|
||||
message->plain = plugins_pre_room_message_display(message->from_jid->barejid, message->from_jid->resourcepart, message->plain);
|
||||
|
||||
GSList *mentions = get_mentions(prefs_get_boolean(PREF_NOTIFY_MENTION_WHOLE_WORD), prefs_get_boolean(PREF_NOTIFY_MENTION_CASE_SENSITIVE), message->plain, mynick);
|
||||
gboolean mention = g_slist_length(mentions) > 0;
|
||||
@ -341,7 +341,7 @@ sv_ev_room_message(ProfMessage *message)
|
||||
is_current = TRUE;
|
||||
status_bar_active(num, WIN_MUC, mucwin->roomjid);
|
||||
|
||||
if ((g_strcmp0(mynick, message->jid->resourcepart) != 0) && (prefs_get_boolean(PREF_BEEP))) {
|
||||
if ((g_strcmp0(mynick, message->from_jid->resourcepart) != 0) && (prefs_get_boolean(PREF_BEEP))) {
|
||||
beep();
|
||||
}
|
||||
|
||||
@ -349,11 +349,11 @@ sv_ev_room_message(ProfMessage *message)
|
||||
} else {
|
||||
status_bar_new(num, WIN_MUC, mucwin->roomjid);
|
||||
|
||||
if ((g_strcmp0(mynick, message->jid->resourcepart) != 0) && (prefs_get_boolean(PREF_FLASH))) {
|
||||
if ((g_strcmp0(mynick, message->from_jid->resourcepart) != 0) && (prefs_get_boolean(PREF_FLASH))) {
|
||||
flash();
|
||||
}
|
||||
|
||||
cons_show_incoming_room_message(message->jid->resourcepart, mucwin->roomjid, num, mention, triggers, mucwin->unread);
|
||||
cons_show_incoming_room_message(message->from_jid->resourcepart, mucwin->roomjid, num, mention, triggers, mucwin->unread);
|
||||
|
||||
mucwin->unread++;
|
||||
|
||||
@ -371,9 +371,9 @@ sv_ev_room_message(ProfMessage *message)
|
||||
}
|
||||
mucwin->last_msg_timestamp = g_date_time_new_now_local();
|
||||
|
||||
if (prefs_do_room_notify(is_current, mucwin->roomjid, mynick, message->jid->resourcepart, message->plain, mention, triggers != NULL)) {
|
||||
if (prefs_do_room_notify(is_current, mucwin->roomjid, mynick, message->from_jid->resourcepart, message->plain, mention, triggers != NULL)) {
|
||||
Jid *jidp = jid_create(mucwin->roomjid);
|
||||
notify_room_message(message->jid->resourcepart, jidp->localpart, num, message->plain);
|
||||
notify_room_message(message->from_jid->resourcepart, jidp->localpart, num, message->plain);
|
||||
jid_destroy(jidp);
|
||||
}
|
||||
|
||||
@ -383,7 +383,7 @@ sv_ev_room_message(ProfMessage *message)
|
||||
|
||||
rosterwin_roster();
|
||||
|
||||
plugins_post_room_message_display(message->jid->barejid, message->jid->resourcepart, message->plain);
|
||||
plugins_post_room_message_display(message->from_jid->barejid, message->from_jid->resourcepart, message->plain);
|
||||
free(message->plain);
|
||||
message->plain = old_plain;
|
||||
}
|
||||
@ -392,11 +392,11 @@ void
|
||||
sv_ev_incoming_private_message(ProfMessage *message)
|
||||
{
|
||||
char *old_plain = message->plain;
|
||||
message->plain = plugins_pre_priv_message_display(message->jid->fulljid, message->plain);
|
||||
message->plain = plugins_pre_priv_message_display(message->from_jid->fulljid, message->plain);
|
||||
|
||||
ProfPrivateWin *privatewin = wins_get_private(message->jid->fulljid);
|
||||
ProfPrivateWin *privatewin = wins_get_private(message->from_jid->fulljid);
|
||||
if (privatewin == NULL) {
|
||||
ProfWin *window = wins_new_private(message->jid->fulljid);
|
||||
ProfWin *window = wins_new_private(message->from_jid->fulljid);
|
||||
privatewin = (ProfPrivateWin*)window;
|
||||
}
|
||||
|
||||
@ -405,7 +405,7 @@ sv_ev_incoming_private_message(ProfMessage *message)
|
||||
log_database_add_incoming(message);
|
||||
chat_log_msg_in(message);
|
||||
|
||||
plugins_post_priv_message_display(message->jid->fulljid, message->plain);
|
||||
plugins_post_priv_message_display(message->from_jid->fulljid, message->plain);
|
||||
|
||||
free(message->plain);
|
||||
message->plain = old_plain;
|
||||
@ -416,11 +416,11 @@ void
|
||||
sv_ev_delayed_private_message(ProfMessage *message)
|
||||
{
|
||||
char *old_plain = message->plain;
|
||||
message->plain = plugins_pre_priv_message_display(message->jid->fulljid, message->plain);
|
||||
message->plain = plugins_pre_priv_message_display(message->from_jid->fulljid, message->plain);
|
||||
|
||||
ProfPrivateWin *privatewin = wins_get_private(message->jid->fulljid);
|
||||
ProfPrivateWin *privatewin = wins_get_private(message->from_jid->fulljid);
|
||||
if (privatewin == NULL) {
|
||||
ProfWin *window = wins_new_private(message->jid->fulljid);
|
||||
ProfWin *window = wins_new_private(message->from_jid->fulljid);
|
||||
privatewin = (ProfPrivateWin*)window;
|
||||
}
|
||||
|
||||
@ -428,7 +428,7 @@ sv_ev_delayed_private_message(ProfMessage *message)
|
||||
privwin_incoming_msg(privatewin, message);
|
||||
chat_log_msg_in(message);
|
||||
|
||||
plugins_post_priv_message_display(message->jid->fulljid, message->plain);
|
||||
plugins_post_priv_message_display(message->from_jid->fulljid, message->plain);
|
||||
|
||||
free(message->plain);
|
||||
message->plain = old_plain;
|
||||
@ -437,19 +437,20 @@ sv_ev_delayed_private_message(ProfMessage *message)
|
||||
void
|
||||
sv_ev_outgoing_carbon(ProfMessage *message)
|
||||
{
|
||||
ProfChatWin *chatwin = wins_get_chat(message->jid->barejid);
|
||||
ProfChatWin *chatwin = wins_get_chat(message->from_jid->barejid);
|
||||
if (!chatwin) {
|
||||
chatwin = chatwin_new(message->jid->barejid);
|
||||
chatwin = chatwin_new(message->from_jid->barejid);
|
||||
}
|
||||
|
||||
chat_state_active(chatwin->state);
|
||||
|
||||
//TODO: check whether we need to change from and to for carbon. now that we have profmessage->to_jid?
|
||||
if (message->plain) {
|
||||
if (message->type == PROF_MSG_TYPE_MUCPM) {
|
||||
// MUC PM, should have resource (nick) in filename
|
||||
chat_log_msg_out(message->jid->barejid, message->plain, message->jid->resourcepart);
|
||||
chat_log_msg_out(message->from_jid->barejid, message->plain, message->from_jid->resourcepart);
|
||||
} else {
|
||||
chat_log_msg_out(message->jid->barejid, message->plain, NULL);
|
||||
chat_log_msg_out(message->from_jid->barejid, message->plain, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@ -566,7 +567,7 @@ static void
|
||||
_sv_ev_incoming_otr(ProfChatWin *chatwin, gboolean new_win, ProfMessage *message)
|
||||
{
|
||||
gboolean decrypted = FALSE;
|
||||
message->plain = otr_on_message_recv(message->jid->barejid, message->jid->resourcepart, message->body, &decrypted);
|
||||
message->plain = otr_on_message_recv(message->from_jid->barejid, message->from_jid->resourcepart, message->body, &decrypted);
|
||||
if (message->plain) {
|
||||
if (decrypted) {
|
||||
message->enc = PROF_MSG_ENC_OTR;
|
||||
@ -621,15 +622,15 @@ void
|
||||
sv_ev_incoming_message(ProfMessage *message)
|
||||
{
|
||||
gboolean new_win = FALSE;
|
||||
ProfChatWin *chatwin = wins_get_chat(message->jid->barejid);
|
||||
ProfChatWin *chatwin = wins_get_chat(message->from_jid->barejid);
|
||||
if (!chatwin) {
|
||||
ProfWin *window = wins_new_chat(message->jid->barejid);
|
||||
ProfWin *window = wins_new_chat(message->from_jid->barejid);
|
||||
chatwin = (ProfChatWin*)window;
|
||||
new_win = TRUE;
|
||||
|
||||
#ifdef HAVE_OMEMO
|
||||
if (omemo_automatic_start(message->jid->barejid)) {
|
||||
omemo_start_session(message->jid->barejid);
|
||||
if (omemo_automatic_start(message->from_jid->barejid)) {
|
||||
omemo_start_session(message->from_jid->barejid);
|
||||
chatwin->is_omemo = TRUE;
|
||||
}
|
||||
#endif
|
||||
@ -763,16 +764,17 @@ sv_ev_incoming_message(ProfMessage *message)
|
||||
void
|
||||
sv_ev_incoming_carbon(ProfMessage *message)
|
||||
{
|
||||
//TODO: check whether we need to change from and to for carbon. now that we have profmessage->to_jid?
|
||||
gboolean new_win = FALSE;
|
||||
ProfChatWin *chatwin = wins_get_chat(message->jid->barejid);
|
||||
ProfChatWin *chatwin = wins_get_chat(message->from_jid->barejid);
|
||||
if (!chatwin) {
|
||||
ProfWin *window = wins_new_chat(message->jid->barejid);
|
||||
ProfWin *window = wins_new_chat(message->from_jid->barejid);
|
||||
chatwin = (ProfChatWin*)window;
|
||||
new_win = TRUE;
|
||||
|
||||
#ifdef HAVE_OMEMO
|
||||
if (omemo_automatic_start(message->jid->barejid)) {
|
||||
omemo_start_session(message->jid->barejid);
|
||||
if (omemo_automatic_start(message->from_jid->barejid)) {
|
||||
omemo_start_session(message->from_jid->barejid);
|
||||
chatwin->is_omemo = TRUE;
|
||||
}
|
||||
#endif
|
||||
|
28
src/log.c
28
src/log.c
@ -357,15 +357,15 @@ chat_log_otr_msg_in(ProfMessage *message)
|
||||
char *pref_otr_log = prefs_get_string(PREF_OTR_LOG);
|
||||
if (message->enc == PROF_MSG_ENC_NONE || (strcmp(pref_otr_log, "on") == 0)) {
|
||||
if (message->type == PROF_MSG_TYPE_MUCPM) {
|
||||
_chat_log_chat(jidp->barejid, message->jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, message->jid->resourcepart);
|
||||
_chat_log_chat(jidp->barejid, message->from_jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, message->from_jid->resourcepart);
|
||||
} else {
|
||||
_chat_log_chat(jidp->barejid, message->jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, NULL);
|
||||
_chat_log_chat(jidp->barejid, message->from_jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, NULL);
|
||||
}
|
||||
} else if (strcmp(pref_otr_log, "redact") == 0) {
|
||||
if (message->type == PROF_MSG_TYPE_MUCPM) {
|
||||
_chat_log_chat(jidp->barejid, message->jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, message->jid->resourcepart);
|
||||
_chat_log_chat(jidp->barejid, message->from_jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, message->from_jid->resourcepart);
|
||||
} else {
|
||||
_chat_log_chat(jidp->barejid, message->jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, NULL);
|
||||
_chat_log_chat(jidp->barejid, message->from_jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, NULL);
|
||||
}
|
||||
}
|
||||
prefs_free_string(pref_otr_log);
|
||||
@ -382,15 +382,15 @@ chat_log_pgp_msg_in(ProfMessage *message)
|
||||
char *pref_pgp_log = prefs_get_string(PREF_PGP_LOG);
|
||||
if (strcmp(pref_pgp_log, "on") == 0) {
|
||||
if (message->type == PROF_MSG_TYPE_MUCPM) {
|
||||
_chat_log_chat(jidp->barejid, message->jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, message->jid->resourcepart);
|
||||
_chat_log_chat(jidp->barejid, message->from_jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, message->from_jid->resourcepart);
|
||||
} else {
|
||||
_chat_log_chat(jidp->barejid, message->jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, NULL);
|
||||
_chat_log_chat(jidp->barejid, message->from_jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, NULL);
|
||||
}
|
||||
} else if (strcmp(pref_pgp_log, "redact") == 0) {
|
||||
if (message->type == PROF_MSG_TYPE_MUCPM) {
|
||||
_chat_log_chat(jidp->barejid, message->jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, message->jid->resourcepart);
|
||||
_chat_log_chat(jidp->barejid, message->from_jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, message->from_jid->resourcepart);
|
||||
} else {
|
||||
_chat_log_chat(jidp->barejid, message->jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, NULL);
|
||||
_chat_log_chat(jidp->barejid, message->from_jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, NULL);
|
||||
}
|
||||
}
|
||||
prefs_free_string(pref_pgp_log);
|
||||
@ -407,15 +407,15 @@ chat_log_omemo_msg_in(ProfMessage *message)
|
||||
char *pref_omemo_log = prefs_get_string(PREF_OMEMO_LOG);
|
||||
if (strcmp(pref_omemo_log, "on") == 0) {
|
||||
if (message->type == PROF_MSG_TYPE_MUCPM) {
|
||||
_chat_log_chat(jidp->barejid, message->jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, message->jid->resourcepart);
|
||||
_chat_log_chat(jidp->barejid, message->from_jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, message->from_jid->resourcepart);
|
||||
} else {
|
||||
_chat_log_chat(jidp->barejid, message->jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, NULL);
|
||||
_chat_log_chat(jidp->barejid, message->from_jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, NULL);
|
||||
}
|
||||
} else if (strcmp(pref_omemo_log, "redact") == 0) {
|
||||
if (message->type == PROF_MSG_TYPE_MUCPM) {
|
||||
_chat_log_chat(jidp->barejid, message->jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, message->jid->resourcepart);
|
||||
_chat_log_chat(jidp->barejid, message->from_jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, message->from_jid->resourcepart);
|
||||
} else {
|
||||
_chat_log_chat(jidp->barejid, message->jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, message->jid->resourcepart);
|
||||
_chat_log_chat(jidp->barejid, message->from_jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, message->from_jid->resourcepart);
|
||||
}
|
||||
}
|
||||
prefs_free_string(pref_omemo_log);
|
||||
@ -431,9 +431,9 @@ chat_log_msg_in(ProfMessage *message)
|
||||
Jid *jidp = jid_create(jid);
|
||||
|
||||
if (message->type == PROF_MSG_TYPE_MUCPM) {
|
||||
_chat_log_chat(jidp->barejid, message->jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, message->jid->resourcepart);
|
||||
_chat_log_chat(jidp->barejid, message->from_jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, message->from_jid->resourcepart);
|
||||
} else {
|
||||
_chat_log_chat(jidp->barejid, message->jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, NULL);
|
||||
_chat_log_chat(jidp->barejid, message->from_jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, NULL);
|
||||
}
|
||||
jid_destroy(jidp);
|
||||
}
|
||||
|
@ -475,7 +475,7 @@ void
|
||||
api_incoming_message(const char *const barejid, const char *const resource, const char *const plain)
|
||||
{
|
||||
ProfMessage *message = message_init();
|
||||
message->jid = jid_create_from_bare_and_resource(barejid, resource);
|
||||
message->from_jid = jid_create_from_bare_and_resource(barejid, resource);
|
||||
message->plain = strdup(plain);
|
||||
|
||||
sv_ev_incoming_message(message);
|
||||
|
@ -251,12 +251,12 @@ 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->jid->resourcepart, message->plain);
|
||||
message->plain = plugins_pre_chat_message_display(chatwin->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->jid->resourcepart);
|
||||
char *display_name = roster_get_msg_display_name(chatwin->barejid, message->from_jid->resourcepart);
|
||||
|
||||
gboolean is_current = wins_is_current(window);
|
||||
gboolean notify = prefs_do_chat_notify(is_current);
|
||||
@ -304,7 +304,7 @@ chatwin_incoming_msg(ProfChatWin *chatwin, ProfMessage *message, gboolean win_cr
|
||||
|
||||
free(display_name);
|
||||
|
||||
plugins_post_chat_message_display(chatwin->barejid, message->jid->resourcepart, message->plain);
|
||||
plugins_post_chat_message_display(chatwin->barejid, message->from_jid->resourcepart, message->plain);
|
||||
|
||||
free(message->plain);
|
||||
message->plain = old_plain;
|
||||
|
@ -366,7 +366,7 @@ mucwin_history(ProfMucWin *mucwin, const ProfMessage *const message)
|
||||
assert(mucwin != NULL);
|
||||
|
||||
ProfWin *window = (ProfWin*)mucwin;
|
||||
char *nick = message->jid->resourcepart;
|
||||
char *nick = message->from_jid->resourcepart;
|
||||
|
||||
// 'unanimous' all in one color (like always was)
|
||||
// 'regular' colored like new messages too
|
||||
@ -570,9 +570,9 @@ mucwin_incoming_msg(ProfMucWin *mucwin, const ProfMessage *const message, GSList
|
||||
win_insert_last_read_position_marker((ProfWin*)mucwin, mucwin->roomjid);
|
||||
|
||||
if (g_slist_length(mentions) > 0) {
|
||||
_mucwin_print_mention(window, message->plain, message->jid->resourcepart, mynick, mentions, ch, flags);
|
||||
_mucwin_print_mention(window, message->plain, message->from_jid->resourcepart, mynick, mentions, ch, flags);
|
||||
} else if (triggers) {
|
||||
win_print_them(window, THEME_ROOMTRIGGER, ch, flags, message->jid->resourcepart);
|
||||
win_print_them(window, THEME_ROOMTRIGGER, ch, flags, message->from_jid->resourcepart);
|
||||
_mucwin_print_triggers(window, message->plain, triggers);
|
||||
} else {
|
||||
win_println_incoming_muc_msg(window, ch, flags, message);
|
||||
|
@ -1150,16 +1150,16 @@ win_print_incoming(ProfWin *window, const char *const display_name_from, ProfMes
|
||||
}
|
||||
|
||||
if (prefs_get_boolean(PREF_CORRECTION_ALLOW) && message->replace_id) {
|
||||
_win_correct(window, message->plain, message->id, message->replace_id, message->jid->barejid);
|
||||
_win_correct(window, message->plain, message->id, message->replace_id, message->from_jid->barejid);
|
||||
} else {
|
||||
_win_printf(window, enc_char, 0, message->timestamp, flags, THEME_TEXT_THEM, display_name_from, message->jid->barejid, message->id, "%s", message->plain);
|
||||
_win_printf(window, enc_char, 0, message->timestamp, flags, THEME_TEXT_THEM, display_name_from, message->from_jid->barejid, message->id, "%s", message->plain);
|
||||
}
|
||||
|
||||
free(enc_char);
|
||||
break;
|
||||
}
|
||||
case WIN_PRIVATE:
|
||||
_win_printf(window, "-", 0, message->timestamp, flags, THEME_TEXT_THEM, display_name_from, message->jid->barejid, message->id, "%s", message->plain);
|
||||
_win_printf(window, "-", 0, message->timestamp, flags, THEME_TEXT_THEM, display_name_from, message->from_jid->barejid, message->id, "%s", message->plain);
|
||||
break;
|
||||
default:
|
||||
assert(FALSE);
|
||||
@ -1177,9 +1177,9 @@ void
|
||||
win_println_incoming_muc_msg(ProfWin *window, char *show_char, int flags, const ProfMessage *const message)
|
||||
{
|
||||
if (prefs_get_boolean(PREF_CORRECTION_ALLOW) && message->replace_id) {
|
||||
_win_correct(window, message->plain, message->id, message->replace_id, message->jid->fulljid);
|
||||
_win_correct(window, message->plain, message->id, message->replace_id, message->from_jid->fulljid);
|
||||
} else {
|
||||
_win_printf(window, show_char, 0, message->timestamp, flags | NO_ME, THEME_TEXT_THEM, message->jid->resourcepart, message->jid->fulljid, message->id, "%s", message->plain);
|
||||
_win_printf(window, show_char, 0, message->timestamp, flags | NO_ME, THEME_TEXT_THEM, message->from_jid->resourcepart, message->from_jid->fulljid, message->id, "%s", message->plain);
|
||||
}
|
||||
|
||||
inp_nonblocking(TRUE);
|
||||
@ -1226,7 +1226,7 @@ win_print_history(ProfWin *window, const ProfMessage *const message)
|
||||
|
||||
char *display_name;
|
||||
if (message->type == PROF_MSG_TYPE_MUC) {
|
||||
display_name = strdup(message->jid->resourcepart);
|
||||
display_name = strdup(message->from_jid->resourcepart);
|
||||
|
||||
char *muc_history_color = prefs_get_string(PREF_HISTORY_COLOR_MUC);
|
||||
if (g_strcmp0(muc_history_color, "unanimous") == 0) {
|
||||
@ -1237,10 +1237,10 @@ win_print_history(ProfWin *window, const ProfMessage *const message)
|
||||
const char *jid = connection_get_fulljid();
|
||||
Jid *jidp = jid_create(jid);
|
||||
|
||||
if (g_strcmp0(jidp->barejid, message->jid->barejid) == 0) {
|
||||
if (g_strcmp0(jidp->barejid, message->from_jid->barejid) == 0) {
|
||||
display_name = strdup("me");
|
||||
} else {
|
||||
display_name = roster_get_msg_display_name(message->jid->barejid, message->jid->resourcepart);
|
||||
display_name = roster_get_msg_display_name(message->from_jid->barejid, message->from_jid->resourcepart);
|
||||
}
|
||||
jid_destroy(jidp);
|
||||
}
|
||||
|
@ -200,7 +200,8 @@ message_init(void)
|
||||
{
|
||||
ProfMessage *message = malloc(sizeof(ProfMessage));
|
||||
|
||||
message->jid = NULL;
|
||||
message->from_jid = NULL;
|
||||
message->to_jid = NULL;
|
||||
message->id = NULL;
|
||||
message->originid = NULL;
|
||||
message->replace_id = NULL;
|
||||
@ -219,8 +220,12 @@ void
|
||||
message_free(ProfMessage *message)
|
||||
{
|
||||
xmpp_ctx_t *ctx = connection_get_ctx();
|
||||
if (message->jid) {
|
||||
jid_destroy(message->jid);
|
||||
if (message->from_jid) {
|
||||
jid_destroy(message->from_jid);
|
||||
}
|
||||
|
||||
if (message->to_jid) {
|
||||
jid_destroy(message->to_jid);
|
||||
}
|
||||
|
||||
if (message->id) {
|
||||
@ -801,51 +806,51 @@ _handle_groupchat(xmpp_stanza_t *const stanza)
|
||||
}
|
||||
|
||||
const char *room_jid = xmpp_stanza_get_from(stanza);
|
||||
Jid *jid = jid_create(room_jid);
|
||||
Jid *from_jid = jid_create(room_jid);
|
||||
|
||||
// handle room subject
|
||||
xmpp_stanza_t *subject = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_SUBJECT);
|
||||
if (subject) {
|
||||
char *subject_text;
|
||||
subject_text = xmpp_stanza_get_text(subject);
|
||||
sv_ev_room_subject(jid->barejid, jid->resourcepart, subject_text);
|
||||
sv_ev_room_subject(from_jid->barejid, from_jid->resourcepart, subject_text);
|
||||
xmpp_free(ctx, subject_text);
|
||||
|
||||
jid_destroy(jid);
|
||||
jid_destroy(from_jid);
|
||||
return;
|
||||
}
|
||||
|
||||
// handle room broadcasts
|
||||
if (!jid->resourcepart) {
|
||||
if (!from_jid->resourcepart) {
|
||||
char *broadcast;
|
||||
broadcast = xmpp_message_get_body(stanza);
|
||||
if (!broadcast) {
|
||||
jid_destroy(jid);
|
||||
jid_destroy(from_jid);
|
||||
return;
|
||||
}
|
||||
|
||||
sv_ev_room_broadcast(room_jid, broadcast);
|
||||
xmpp_free(ctx, broadcast);
|
||||
|
||||
jid_destroy(jid);
|
||||
jid_destroy(from_jid);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!jid_is_valid_room_form(jid)) {
|
||||
log_error("Invalid room JID: %s", jid->str);
|
||||
jid_destroy(jid);
|
||||
if (!jid_is_valid_room_form(from_jid)) {
|
||||
log_error("Invalid room JID: %s", from_jid->str);
|
||||
jid_destroy(from_jid);
|
||||
return;
|
||||
}
|
||||
|
||||
// room not active in profanity
|
||||
if (!muc_active(jid->barejid)) {
|
||||
log_error("Message received for inactive chat room: %s", jid->str);
|
||||
jid_destroy(jid);
|
||||
if (!muc_active(from_jid->barejid)) {
|
||||
log_error("Message received for inactive chat room: %s", from_jid->str);
|
||||
jid_destroy(from_jid);
|
||||
return;
|
||||
}
|
||||
|
||||
ProfMessage *message = message_init();
|
||||
message->jid = jid;
|
||||
message->from_jid = from_jid;
|
||||
message->type = PROF_MSG_TYPE_MUC;
|
||||
|
||||
if (id) {
|
||||
@ -875,17 +880,17 @@ _handle_groupchat(xmpp_stanza_t *const stanza)
|
||||
#endif
|
||||
|
||||
if (!message->plain && !message->body) {
|
||||
log_error("Message received without body for room: %s", jid->str);
|
||||
log_error("Message received without body for room: %s", from_jid->str);
|
||||
goto out;
|
||||
} else if (!message->plain) {
|
||||
message->plain = strdup(message->body);
|
||||
}
|
||||
|
||||
// determine if the notifications happened whilst offline (MUC history)
|
||||
message->timestamp = stanza_get_delay_from(stanza, jid->barejid);
|
||||
message->timestamp = stanza_get_delay_from(stanza, from_jid->barejid);
|
||||
if (message->timestamp == NULL) {
|
||||
// checking the domainpart is a workaround for some prosody versions (gh#1190)
|
||||
message->timestamp = stanza_get_delay_from(stanza, jid->domainpart);
|
||||
message->timestamp = stanza_get_delay_from(stanza, from_jid->domainpart);
|
||||
}
|
||||
|
||||
bool is_muc_history = FALSE;
|
||||
@ -996,7 +1001,7 @@ _handle_muc_private_message(xmpp_stanza_t *const stanza)
|
||||
message->type = PROF_MSG_TYPE_MUCPM;
|
||||
|
||||
const gchar *from = xmpp_stanza_get_from(stanza);
|
||||
message->jid = jid_create(from);
|
||||
message->from_jid = jid_create(from);
|
||||
|
||||
// message stanza id
|
||||
const char *id = xmpp_stanza_get_id(stanza);
|
||||
@ -1016,7 +1021,7 @@ _handle_muc_private_message(xmpp_stanza_t *const stanza)
|
||||
message->body = xmpp_message_get_body(stanza);
|
||||
|
||||
if (!message->plain && !message->body) {
|
||||
log_error("Message received without body from: %s", message->jid->str);
|
||||
log_error("Message received without body from: %s", message->from_jid->str);
|
||||
goto out;
|
||||
} else if (!message->plain) {
|
||||
message->plain = strdup(message->body);
|
||||
@ -1133,17 +1138,18 @@ _handle_carbons(xmpp_stanza_t *const stanza)
|
||||
message->encrypted = xmpp_stanza_get_text(x);
|
||||
}
|
||||
|
||||
//TODO: now that profmessage has from_jid AND to_jid we should save both. and maybe also add is_carbon so we can decide later on.
|
||||
if (message->plain || message->encrypted || message->body) {
|
||||
// if we are the recipient, treat as standard incoming message
|
||||
if (g_strcmp0(my_jid->barejid, jid_to->barejid) == 0) {
|
||||
jid_destroy(jid_to);
|
||||
message->jid = jid_from;
|
||||
message->from_jid = jid_from;
|
||||
sv_ev_incoming_carbon(message);
|
||||
|
||||
// else treat as a sent message
|
||||
} else {
|
||||
jid_destroy(jid_from);
|
||||
message->jid = jid_to;
|
||||
message->from_jid = jid_to;
|
||||
sv_ev_outgoing_carbon(message);
|
||||
}
|
||||
}
|
||||
@ -1200,7 +1206,9 @@ _handle_chat(xmpp_stanza_t *const stanza)
|
||||
|
||||
// standard chat message, use jid without resource
|
||||
ProfMessage *message = message_init();
|
||||
message->jid = jid;
|
||||
// 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 stanza id
|
||||
|
@ -137,7 +137,8 @@ typedef enum {
|
||||
} prof_msg_type_t;
|
||||
|
||||
typedef struct prof_message_t {
|
||||
Jid *jid;
|
||||
Jid *from_jid;
|
||||
Jid *to_jid;
|
||||
/* regular <message id=""> */
|
||||
char *id;
|
||||
/* </origin-id> XEP-0359 */
|
||||
|
Loading…
Reference in New Issue
Block a user