mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Merge pull request #1306 from profanity-im/feature/mam
Add basic MAM support
This commit is contained in:
commit
a800bfcbf8
@ -1799,6 +1799,7 @@ _get_group(preference_t pref)
|
|||||||
case PREF_REVEAL_OS:
|
case PREF_REVEAL_OS:
|
||||||
case PREF_TLS_CERTPATH:
|
case PREF_TLS_CERTPATH:
|
||||||
case PREF_CORRECTION_ALLOW:
|
case PREF_CORRECTION_ALLOW:
|
||||||
|
case PREF_MAM:
|
||||||
return PREF_GROUP_CONNECTION;
|
return PREF_GROUP_CONNECTION;
|
||||||
case PREF_OTR_LOG:
|
case PREF_OTR_LOG:
|
||||||
case PREF_OTR_POLICY:
|
case PREF_OTR_POLICY:
|
||||||
@ -2070,6 +2071,8 @@ _get_key(preference_t pref)
|
|||||||
return "avatar.cmd";
|
return "avatar.cmd";
|
||||||
case PREF_SLASH_GUARD:
|
case PREF_SLASH_GUARD:
|
||||||
return "slashguard";
|
return "slashguard";
|
||||||
|
case PREF_MAM:
|
||||||
|
return "mam";
|
||||||
default:
|
default:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -170,6 +170,7 @@ typedef enum {
|
|||||||
PREF_HISTORY_COLOR_MUC,
|
PREF_HISTORY_COLOR_MUC,
|
||||||
PREF_AVATAR_CMD,
|
PREF_AVATAR_CMD,
|
||||||
PREF_SLASH_GUARD,
|
PREF_SLASH_GUARD,
|
||||||
|
PREF_MAM,
|
||||||
} preference_t;
|
} preference_t;
|
||||||
|
|
||||||
typedef struct prof_alias_t {
|
typedef struct prof_alias_t {
|
||||||
|
@ -166,7 +166,7 @@ log_database_add_incoming(ProfMessage *message)
|
|||||||
const char *jid = connection_get_fulljid();
|
const char *jid = connection_get_fulljid();
|
||||||
Jid *myjid = jid_create(jid);
|
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);
|
jid_destroy(myjid);
|
||||||
}
|
}
|
||||||
@ -177,7 +177,7 @@ _log_database_add_outgoing(char *type, const char * const id, const char * const
|
|||||||
ProfMessage *msg = message_init();
|
ProfMessage *msg = message_init();
|
||||||
|
|
||||||
msg->id = id ? strdup(id) : NULL;
|
msg->id = id ? strdup(id) : NULL;
|
||||||
msg->jid = jid_create(barejid);
|
msg->from_jid = jid_create(barejid);
|
||||||
msg->plain = message ? strdup(message) : NULL;
|
msg->plain = message ? strdup(message) : NULL;
|
||||||
msg->replace_id = replace_id ? strdup(replace_id) : 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
|
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();
|
const char *jid = connection_get_fulljid();
|
||||||
Jid *myjid = jid_create(jid);
|
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);
|
jid_destroy(myjid);
|
||||||
message_free(msg);
|
message_free(msg);
|
||||||
@ -234,13 +234,14 @@ log_database_get_previous_chat(const gchar *const contact_barejid)
|
|||||||
GSList *history = NULL;
|
GSList *history = NULL;
|
||||||
|
|
||||||
while( sqlite3_step(stmt) == SQLITE_ROW ) {
|
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 *message = (char*)sqlite3_column_text(stmt, 0);
|
||||||
char *date = (char*)sqlite3_column_text(stmt, 1);
|
char *date = (char*)sqlite3_column_text(stmt, 1);
|
||||||
char *from = (char*)sqlite3_column_text(stmt, 2);
|
char *from = (char*)sqlite3_column_text(stmt, 2);
|
||||||
char *type = (char*)sqlite3_column_text(stmt, 3);
|
char *type = (char*)sqlite3_column_text(stmt, 3);
|
||||||
|
|
||||||
ProfMessage *msg = message_init();
|
ProfMessage *msg = message_init();
|
||||||
msg->jid = jid_create(from);
|
msg->from_jid = jid_create(from);
|
||||||
msg->plain = strdup(message);
|
msg->plain = strdup(message);
|
||||||
msg->timestamp = g_date_time_new_from_iso8601(date, NULL);
|
msg->timestamp = g_date_time_new_from_iso8601(date, NULL);
|
||||||
msg->type = _get_message_type_type(type);
|
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
|
void
|
||||||
sv_ev_room_history(ProfMessage *message)
|
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 (mucwin) {
|
||||||
// if this is the first successful connection
|
// if this is the first successful connection
|
||||||
if (ev_is_first_connect()) {
|
if (ev_is_first_connect()) {
|
||||||
@ -297,9 +297,9 @@ sv_ev_room_history(ProfMessage *message)
|
|||||||
static void _log_muc(ProfMessage *message)
|
static void _log_muc(ProfMessage *message)
|
||||||
{
|
{
|
||||||
if (message->enc == PROF_MSG_ENC_OMEMO) {
|
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 {
|
} 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);
|
log_database_add_incoming(message);
|
||||||
}
|
}
|
||||||
@ -307,7 +307,7 @@ static void _log_muc(ProfMessage *message)
|
|||||||
void
|
void
|
||||||
sv_ev_room_message(ProfMessage *message)
|
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) {
|
if (!mucwin) {
|
||||||
return;
|
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)
|
// only log message not coming from this client (but maybe same account, different client)
|
||||||
// our messages are logged when outgoing
|
// 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);
|
_log_muc(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *old_plain = message->plain;
|
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);
|
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;
|
gboolean mention = g_slist_length(mentions) > 0;
|
||||||
@ -341,7 +341,7 @@ sv_ev_room_message(ProfMessage *message)
|
|||||||
is_current = TRUE;
|
is_current = TRUE;
|
||||||
status_bar_active(num, WIN_MUC, mucwin->roomjid);
|
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();
|
beep();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -349,11 +349,11 @@ sv_ev_room_message(ProfMessage *message)
|
|||||||
} else {
|
} else {
|
||||||
status_bar_new(num, WIN_MUC, mucwin->roomjid);
|
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();
|
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++;
|
mucwin->unread++;
|
||||||
|
|
||||||
@ -371,9 +371,9 @@ sv_ev_room_message(ProfMessage *message)
|
|||||||
}
|
}
|
||||||
mucwin->last_msg_timestamp = g_date_time_new_now_local();
|
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);
|
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);
|
jid_destroy(jidp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -383,7 +383,7 @@ sv_ev_room_message(ProfMessage *message)
|
|||||||
|
|
||||||
rosterwin_roster();
|
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);
|
free(message->plain);
|
||||||
message->plain = old_plain;
|
message->plain = old_plain;
|
||||||
}
|
}
|
||||||
@ -392,11 +392,11 @@ void
|
|||||||
sv_ev_incoming_private_message(ProfMessage *message)
|
sv_ev_incoming_private_message(ProfMessage *message)
|
||||||
{
|
{
|
||||||
char *old_plain = message->plain;
|
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) {
|
if (privatewin == NULL) {
|
||||||
ProfWin *window = wins_new_private(message->jid->fulljid);
|
ProfWin *window = wins_new_private(message->from_jid->fulljid);
|
||||||
privatewin = (ProfPrivateWin*)window;
|
privatewin = (ProfPrivateWin*)window;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -405,7 +405,7 @@ sv_ev_incoming_private_message(ProfMessage *message)
|
|||||||
log_database_add_incoming(message);
|
log_database_add_incoming(message);
|
||||||
chat_log_msg_in(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);
|
free(message->plain);
|
||||||
message->plain = old_plain;
|
message->plain = old_plain;
|
||||||
@ -416,11 +416,11 @@ void
|
|||||||
sv_ev_delayed_private_message(ProfMessage *message)
|
sv_ev_delayed_private_message(ProfMessage *message)
|
||||||
{
|
{
|
||||||
char *old_plain = message->plain;
|
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) {
|
if (privatewin == NULL) {
|
||||||
ProfWin *window = wins_new_private(message->jid->fulljid);
|
ProfWin *window = wins_new_private(message->from_jid->fulljid);
|
||||||
privatewin = (ProfPrivateWin*)window;
|
privatewin = (ProfPrivateWin*)window;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -428,7 +428,7 @@ sv_ev_delayed_private_message(ProfMessage *message)
|
|||||||
privwin_incoming_msg(privatewin, message);
|
privwin_incoming_msg(privatewin, message);
|
||||||
chat_log_msg_in(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);
|
free(message->plain);
|
||||||
message->plain = old_plain;
|
message->plain = old_plain;
|
||||||
@ -437,19 +437,20 @@ sv_ev_delayed_private_message(ProfMessage *message)
|
|||||||
void
|
void
|
||||||
sv_ev_outgoing_carbon(ProfMessage *message)
|
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) {
|
if (!chatwin) {
|
||||||
chatwin = chatwin_new(message->jid->barejid);
|
chatwin = chatwin_new(message->from_jid->barejid);
|
||||||
}
|
}
|
||||||
|
|
||||||
chat_state_active(chatwin->state);
|
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->plain) {
|
||||||
if (message->type == PROF_MSG_TYPE_MUCPM) {
|
if (message->type == PROF_MSG_TYPE_MUCPM) {
|
||||||
// MUC PM, should have resource (nick) in filename
|
// 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 {
|
} 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)
|
_sv_ev_incoming_otr(ProfChatWin *chatwin, gboolean new_win, ProfMessage *message)
|
||||||
{
|
{
|
||||||
gboolean decrypted = FALSE;
|
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 (message->plain) {
|
||||||
if (decrypted) {
|
if (decrypted) {
|
||||||
message->enc = PROF_MSG_ENC_OTR;
|
message->enc = PROF_MSG_ENC_OTR;
|
||||||
@ -621,16 +622,30 @@ void
|
|||||||
sv_ev_incoming_message(ProfMessage *message)
|
sv_ev_incoming_message(ProfMessage *message)
|
||||||
{
|
{
|
||||||
gboolean new_win = FALSE;
|
gboolean new_win = FALSE;
|
||||||
ProfChatWin *chatwin = wins_get_chat(message->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) {
|
if (!chatwin) {
|
||||||
ProfWin *window = wins_new_chat(message->jid->barejid);
|
ProfWin *window = wins_new_chat(looking_for_jid);
|
||||||
chatwin = (ProfChatWin*)window;
|
chatwin = (ProfChatWin*)window;
|
||||||
new_win = TRUE;
|
new_win = TRUE;
|
||||||
|
|
||||||
#ifdef HAVE_OMEMO
|
#ifdef HAVE_OMEMO
|
||||||
if (omemo_automatic_start(message->jid->barejid)) {
|
if (!message->is_mam) {
|
||||||
omemo_start_session(message->jid->barejid);
|
if (omemo_automatic_start(message->from_jid->barejid)) {
|
||||||
chatwin->is_omemo = TRUE;
|
omemo_start_session(message->from_jid->barejid);
|
||||||
|
chatwin->is_omemo = TRUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -763,16 +778,17 @@ sv_ev_incoming_message(ProfMessage *message)
|
|||||||
void
|
void
|
||||||
sv_ev_incoming_carbon(ProfMessage *message)
|
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;
|
gboolean new_win = FALSE;
|
||||||
ProfChatWin *chatwin = wins_get_chat(message->jid->barejid);
|
ProfChatWin *chatwin = wins_get_chat(message->from_jid->barejid);
|
||||||
if (!chatwin) {
|
if (!chatwin) {
|
||||||
ProfWin *window = wins_new_chat(message->jid->barejid);
|
ProfWin *window = wins_new_chat(message->from_jid->barejid);
|
||||||
chatwin = (ProfChatWin*)window;
|
chatwin = (ProfChatWin*)window;
|
||||||
new_win = TRUE;
|
new_win = TRUE;
|
||||||
|
|
||||||
#ifdef HAVE_OMEMO
|
#ifdef HAVE_OMEMO
|
||||||
if (omemo_automatic_start(message->jid->barejid)) {
|
if (omemo_automatic_start(message->from_jid->barejid)) {
|
||||||
omemo_start_session(message->jid->barejid);
|
omemo_start_session(message->from_jid->barejid);
|
||||||
chatwin->is_omemo = TRUE;
|
chatwin->is_omemo = TRUE;
|
||||||
}
|
}
|
||||||
#endif
|
#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);
|
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->enc == PROF_MSG_ENC_NONE || (strcmp(pref_otr_log, "on") == 0)) {
|
||||||
if (message->type == PROF_MSG_TYPE_MUCPM) {
|
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 {
|
} 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) {
|
} else if (strcmp(pref_otr_log, "redact") == 0) {
|
||||||
if (message->type == PROF_MSG_TYPE_MUCPM) {
|
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 {
|
} 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);
|
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);
|
char *pref_pgp_log = prefs_get_string(PREF_PGP_LOG);
|
||||||
if (strcmp(pref_pgp_log, "on") == 0) {
|
if (strcmp(pref_pgp_log, "on") == 0) {
|
||||||
if (message->type == PROF_MSG_TYPE_MUCPM) {
|
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 {
|
} 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) {
|
} else if (strcmp(pref_pgp_log, "redact") == 0) {
|
||||||
if (message->type == PROF_MSG_TYPE_MUCPM) {
|
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 {
|
} 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);
|
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);
|
char *pref_omemo_log = prefs_get_string(PREF_OMEMO_LOG);
|
||||||
if (strcmp(pref_omemo_log, "on") == 0) {
|
if (strcmp(pref_omemo_log, "on") == 0) {
|
||||||
if (message->type == PROF_MSG_TYPE_MUCPM) {
|
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 {
|
} 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) {
|
} else if (strcmp(pref_omemo_log, "redact") == 0) {
|
||||||
if (message->type == PROF_MSG_TYPE_MUCPM) {
|
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 {
|
} 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);
|
prefs_free_string(pref_omemo_log);
|
||||||
@ -431,9 +431,9 @@ chat_log_msg_in(ProfMessage *message)
|
|||||||
Jid *jidp = jid_create(jid);
|
Jid *jidp = jid_create(jid);
|
||||||
|
|
||||||
if (message->type == PROF_MSG_TYPE_MUCPM) {
|
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 {
|
} 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);
|
jid_destroy(jidp);
|
||||||
}
|
}
|
||||||
|
@ -475,7 +475,7 @@ void
|
|||||||
api_incoming_message(const char *const barejid, const char *const resource, const char *const plain)
|
api_incoming_message(const char *const barejid, const char *const resource, const char *const plain)
|
||||||
{
|
{
|
||||||
ProfMessage *message = message_init();
|
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);
|
message->plain = strdup(plain);
|
||||||
|
|
||||||
sv_ev_incoming_message(message);
|
sv_ev_incoming_message(message);
|
||||||
|
@ -66,7 +66,7 @@ chatwin_new(const char *const barejid)
|
|||||||
ProfWin *window = wins_new_chat(barejid);
|
ProfWin *window = wins_new_chat(barejid);
|
||||||
ProfChatWin *chatwin = (ProfChatWin *)window;
|
ProfChatWin *chatwin = (ProfChatWin *)window;
|
||||||
|
|
||||||
if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) {
|
if (!prefs_get_boolean(PREF_MAM) && prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) {
|
||||||
_chatwin_history(chatwin, barejid);
|
_chatwin_history(chatwin, barejid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,6 +87,9 @@ chatwin_new(const char *const barejid)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (prefs_get_boolean(PREF_MAM)) {
|
||||||
|
iq_mam_request(chatwin);
|
||||||
|
}
|
||||||
return chatwin;
|
return chatwin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,12 +253,19 @@ chatwin_incoming_msg(ProfChatWin *chatwin, ProfMessage *message, gboolean win_cr
|
|||||||
assert(chatwin != NULL);
|
assert(chatwin != NULL);
|
||||||
char *old_plain = message->plain;
|
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(message->from_jid->barejid, message->from_jid->resourcepart, message->plain);
|
||||||
|
|
||||||
ProfWin *window = (ProfWin*)chatwin;
|
ProfWin *window = (ProfWin*)chatwin;
|
||||||
int num = wins_get_num(window);
|
int num = wins_get_num(window);
|
||||||
|
|
||||||
char *display_name = roster_get_msg_display_name(chatwin->barejid, message->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 is_current = wins_is_current(window);
|
||||||
gboolean notify = prefs_do_chat_notify(is_current);
|
gboolean notify = prefs_do_chat_notify(is_current);
|
||||||
@ -277,7 +287,12 @@ chatwin_incoming_msg(ProfChatWin *chatwin, ProfMessage *message, gboolean win_cr
|
|||||||
|
|
||||||
chatwin->unread++;
|
chatwin->unread++;
|
||||||
|
|
||||||
if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) {
|
//TODO: so far we don't ask for MAM when incoming message occurs.
|
||||||
|
//Need to figure out:
|
||||||
|
//1) only send IQ once
|
||||||
|
//2) sort incoming messages on timestamp
|
||||||
|
//for now if experimental MAM is enabled we dont show no history from sql either
|
||||||
|
if (!prefs_get_boolean(PREF_MAM) && prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) {
|
||||||
_chatwin_history(chatwin, chatwin->barejid);
|
_chatwin_history(chatwin, chatwin->barejid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -303,7 +318,7 @@ chatwin_incoming_msg(ProfChatWin *chatwin, ProfMessage *message, gboolean win_cr
|
|||||||
|
|
||||||
free(display_name);
|
free(display_name);
|
||||||
|
|
||||||
plugins_post_chat_message_display(chatwin->barejid, message->jid->resourcepart, message->plain);
|
plugins_post_chat_message_display(message->from_jid->barejid, message->from_jid->resourcepart, message->plain);
|
||||||
|
|
||||||
free(message->plain);
|
free(message->plain);
|
||||||
message->plain = old_plain;
|
message->plain = old_plain;
|
||||||
|
@ -366,7 +366,7 @@ mucwin_history(ProfMucWin *mucwin, const ProfMessage *const message)
|
|||||||
assert(mucwin != NULL);
|
assert(mucwin != NULL);
|
||||||
|
|
||||||
ProfWin *window = (ProfWin*)mucwin;
|
ProfWin *window = (ProfWin*)mucwin;
|
||||||
char *nick = message->jid->resourcepart;
|
char *nick = message->from_jid->resourcepart;
|
||||||
|
|
||||||
// 'unanimous' all in one color (like always was)
|
// 'unanimous' all in one color (like always was)
|
||||||
// 'regular' colored like new messages too
|
// '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);
|
win_insert_last_read_position_marker((ProfWin*)mucwin, mucwin->roomjid);
|
||||||
|
|
||||||
if (g_slist_length(mentions) > 0) {
|
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) {
|
} 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);
|
_mucwin_print_triggers(window, message->plain, triggers);
|
||||||
} else {
|
} else {
|
||||||
win_println_incoming_muc_msg(window, ch, flags, message);
|
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) {
|
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 {
|
} 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);
|
free(enc_char);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WIN_PRIVATE:
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
assert(FALSE);
|
assert(FALSE);
|
||||||
@ -1177,9 +1177,9 @@ void
|
|||||||
win_println_incoming_muc_msg(ProfWin *window, char *show_char, int flags, const ProfMessage *const message)
|
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) {
|
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 {
|
} 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);
|
inp_nonblocking(TRUE);
|
||||||
@ -1226,7 +1226,7 @@ win_print_history(ProfWin *window, const ProfMessage *const message)
|
|||||||
|
|
||||||
char *display_name;
|
char *display_name;
|
||||||
if (message->type == PROF_MSG_TYPE_MUC) {
|
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);
|
char *muc_history_color = prefs_get_string(PREF_HISTORY_COLOR_MUC);
|
||||||
if (g_strcmp0(muc_history_color, "unanimous") == 0) {
|
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();
|
const char *jid = connection_get_fulljid();
|
||||||
Jid *jidp = jid_create(jid);
|
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");
|
display_name = strdup("me");
|
||||||
} else {
|
} 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);
|
jid_destroy(jidp);
|
||||||
}
|
}
|
||||||
|
@ -2499,3 +2499,32 @@ _iq_free_affiliation_list(ProfAffiliationList *affiliation_list)
|
|||||||
free(affiliation_list);
|
free(affiliation_list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
iq_mam_request(ProfChatWin *win)
|
||||||
|
{
|
||||||
|
if (connection_supports(XMPP_FEATURE_MAM2) == FALSE) {
|
||||||
|
log_warning("Server doesn't advertise %s feature.", XMPP_FEATURE_PING);
|
||||||
|
cons_show_error("Server doesn't support MAM.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||||
|
char *id = connection_create_stanza_id();
|
||||||
|
|
||||||
|
GDateTime *now = g_date_time_new_now_local();
|
||||||
|
GDateTime *timestamp = g_date_time_add_days(now, -1);
|
||||||
|
g_date_time_unref(now);
|
||||||
|
gchar *datestr = g_date_time_format(timestamp,"%FT%T%:::z");
|
||||||
|
xmpp_stanza_t *iq = stanza_create_mam_iq(ctx, win->barejid, datestr);
|
||||||
|
g_free(datestr);
|
||||||
|
g_date_time_unref(timestamp);
|
||||||
|
|
||||||
|
// iq_id_handler_add(id, _http_upload_response_id_handler, NULL, upload);
|
||||||
|
free(id);
|
||||||
|
|
||||||
|
iq_send_stanza(iq);
|
||||||
|
xmpp_stanza_release(iq);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
@ -84,7 +84,8 @@ static void _handle_muc_private_message(xmpp_stanza_t *const stanza);
|
|||||||
static void _handle_conference(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_captcha(xmpp_stanza_t *const stanza);
|
||||||
static void _handle_receipt_received(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);
|
static void _send_message_stanza(xmpp_stanza_t *const stanza);
|
||||||
|
|
||||||
@ -99,13 +100,26 @@ _message_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *con
|
|||||||
size_t text_size;
|
size_t text_size;
|
||||||
xmpp_stanza_to_text(stanza, &text, &text_size);
|
xmpp_stanza_to_text(stanza, &text, &text_size);
|
||||||
gboolean cont = plugins_on_message_stanza_receive(text);
|
gboolean cont = plugins_on_message_stanza_receive(text);
|
||||||
xmpp_free(connection_get_ctx(), text);
|
|
||||||
if (!cont) {
|
if (!cont) {
|
||||||
|
xmpp_free(connection_get_ctx(), text);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *type = xmpp_stanza_get_type(stanza);
|
const char *type = xmpp_stanza_get_type(stanza);
|
||||||
|
|
||||||
|
if (type == NULL) {
|
||||||
|
if (_handle_mam(stanza)) {
|
||||||
|
xmpp_free(connection_get_ctx(), text);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
log_info("Received <message> without 'type': %s", text);
|
||||||
|
xmpp_free(connection_get_ctx(), text);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
xmpp_free(connection_get_ctx(), text);
|
||||||
|
|
||||||
if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) {
|
if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) {
|
||||||
_handle_error(stanza);
|
_handle_error(stanza);
|
||||||
}
|
}
|
||||||
@ -152,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;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -186,7 +200,8 @@ message_init(void)
|
|||||||
{
|
{
|
||||||
ProfMessage *message = malloc(sizeof(ProfMessage));
|
ProfMessage *message = malloc(sizeof(ProfMessage));
|
||||||
|
|
||||||
message->jid = NULL;
|
message->from_jid = NULL;
|
||||||
|
message->to_jid = NULL;
|
||||||
message->id = NULL;
|
message->id = NULL;
|
||||||
message->originid = NULL;
|
message->originid = NULL;
|
||||||
message->replace_id = NULL;
|
message->replace_id = NULL;
|
||||||
@ -205,8 +220,12 @@ void
|
|||||||
message_free(ProfMessage *message)
|
message_free(ProfMessage *message)
|
||||||
{
|
{
|
||||||
xmpp_ctx_t *ctx = connection_get_ctx();
|
xmpp_ctx_t *ctx = connection_get_ctx();
|
||||||
if (message->jid) {
|
if (message->from_jid) {
|
||||||
jid_destroy(message->jid);
|
jid_destroy(message->from_jid);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (message->to_jid) {
|
||||||
|
jid_destroy(message->to_jid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message->id) {
|
if (message->id) {
|
||||||
@ -787,51 +806,51 @@ _handle_groupchat(xmpp_stanza_t *const stanza)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const char *room_jid = xmpp_stanza_get_from(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
|
// handle room subject
|
||||||
xmpp_stanza_t *subject = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_SUBJECT);
|
xmpp_stanza_t *subject = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_SUBJECT);
|
||||||
if (subject) {
|
if (subject) {
|
||||||
char *subject_text;
|
char *subject_text;
|
||||||
subject_text = xmpp_stanza_get_text(subject);
|
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);
|
xmpp_free(ctx, subject_text);
|
||||||
|
|
||||||
jid_destroy(jid);
|
jid_destroy(from_jid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle room broadcasts
|
// handle room broadcasts
|
||||||
if (!jid->resourcepart) {
|
if (!from_jid->resourcepart) {
|
||||||
char *broadcast;
|
char *broadcast;
|
||||||
broadcast = xmpp_message_get_body(stanza);
|
broadcast = xmpp_message_get_body(stanza);
|
||||||
if (!broadcast) {
|
if (!broadcast) {
|
||||||
jid_destroy(jid);
|
jid_destroy(from_jid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sv_ev_room_broadcast(room_jid, broadcast);
|
sv_ev_room_broadcast(room_jid, broadcast);
|
||||||
xmpp_free(ctx, broadcast);
|
xmpp_free(ctx, broadcast);
|
||||||
|
|
||||||
jid_destroy(jid);
|
jid_destroy(from_jid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!jid_is_valid_room_form(jid)) {
|
if (!jid_is_valid_room_form(from_jid)) {
|
||||||
log_error("Invalid room JID: %s", jid->str);
|
log_error("Invalid room JID: %s", from_jid->str);
|
||||||
jid_destroy(jid);
|
jid_destroy(from_jid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// room not active in profanity
|
// room not active in profanity
|
||||||
if (!muc_active(jid->barejid)) {
|
if (!muc_active(from_jid->barejid)) {
|
||||||
log_error("Message received for inactive chat room: %s", jid->str);
|
log_error("Message received for inactive chat room: %s", from_jid->str);
|
||||||
jid_destroy(jid);
|
jid_destroy(from_jid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ProfMessage *message = message_init();
|
ProfMessage *message = message_init();
|
||||||
message->jid = jid;
|
message->from_jid = from_jid;
|
||||||
message->type = PROF_MSG_TYPE_MUC;
|
message->type = PROF_MSG_TYPE_MUC;
|
||||||
|
|
||||||
if (id) {
|
if (id) {
|
||||||
@ -861,17 +880,17 @@ _handle_groupchat(xmpp_stanza_t *const stanza)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!message->plain && !message->body) {
|
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;
|
goto out;
|
||||||
} else if (!message->plain) {
|
} else if (!message->plain) {
|
||||||
message->plain = strdup(message->body);
|
message->plain = strdup(message->body);
|
||||||
}
|
}
|
||||||
|
|
||||||
// determine if the notifications happened whilst offline (MUC history)
|
// 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) {
|
if (message->timestamp == NULL) {
|
||||||
// checking the domainpart is a workaround for some prosody versions (gh#1190)
|
// 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;
|
bool is_muc_history = FALSE;
|
||||||
@ -982,7 +1001,7 @@ _handle_muc_private_message(xmpp_stanza_t *const stanza)
|
|||||||
message->type = PROF_MSG_TYPE_MUCPM;
|
message->type = PROF_MSG_TYPE_MUCPM;
|
||||||
|
|
||||||
const gchar *from = xmpp_stanza_get_from(stanza);
|
const gchar *from = xmpp_stanza_get_from(stanza);
|
||||||
message->jid = jid_create(from);
|
message->from_jid = jid_create(from);
|
||||||
|
|
||||||
// message stanza id
|
// message stanza id
|
||||||
const char *id = xmpp_stanza_get_id(stanza);
|
const char *id = xmpp_stanza_get_id(stanza);
|
||||||
@ -1002,7 +1021,7 @@ _handle_muc_private_message(xmpp_stanza_t *const stanza)
|
|||||||
message->body = xmpp_message_get_body(stanza);
|
message->body = xmpp_message_get_body(stanza);
|
||||||
|
|
||||||
if (!message->plain && !message->body) {
|
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;
|
goto out;
|
||||||
} else if (!message->plain) {
|
} else if (!message->plain) {
|
||||||
message->plain = strdup(message->body);
|
message->plain = strdup(message->body);
|
||||||
@ -1119,17 +1138,18 @@ _handle_carbons(xmpp_stanza_t *const stanza)
|
|||||||
message->encrypted = xmpp_stanza_get_text(x);
|
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 (message->plain || message->encrypted || message->body) {
|
||||||
// if we are the recipient, treat as standard incoming message
|
// if we are the recipient, treat as standard incoming message
|
||||||
if (g_strcmp0(my_jid->barejid, jid_to->barejid) == 0) {
|
if (g_strcmp0(my_jid->barejid, jid_to->barejid) == 0) {
|
||||||
jid_destroy(jid_to);
|
jid_destroy(jid_to);
|
||||||
message->jid = jid_from;
|
message->from_jid = jid_from;
|
||||||
sv_ev_incoming_carbon(message);
|
sv_ev_incoming_carbon(message);
|
||||||
|
|
||||||
// else treat as a sent message
|
// else treat as a sent message
|
||||||
} else {
|
} else {
|
||||||
jid_destroy(jid_from);
|
jid_destroy(jid_from);
|
||||||
message->jid = jid_to;
|
message->from_jid = jid_to;
|
||||||
sv_ev_outgoing_carbon(message);
|
sv_ev_outgoing_carbon(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1141,7 +1161,7 @@ out:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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
|
// ignore if type not chat or absent
|
||||||
const char *type = xmpp_stanza_get_type(stanza);
|
const char *type = xmpp_stanza_get_type(stanza);
|
||||||
@ -1172,6 +1192,9 @@ _handle_chat(xmpp_stanza_t *const stanza)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const gchar *from = xmpp_stanza_get_from(stanza);
|
const gchar *from = xmpp_stanza_get_from(stanza);
|
||||||
|
if (!from) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Jid *jid = jid_create(from);
|
Jid *jid = jid_create(from);
|
||||||
|
|
||||||
// private message from chat room use full jid (room/nick)
|
// private message from chat room use full jid (room/nick)
|
||||||
@ -1183,8 +1206,15 @@ _handle_chat(xmpp_stanza_t *const stanza)
|
|||||||
|
|
||||||
// standard chat message, use jid without resource
|
// standard chat message, use jid without resource
|
||||||
ProfMessage *message = message_init();
|
ProfMessage *message = message_init();
|
||||||
message->jid = jid;
|
|
||||||
message->type = PROF_MSG_TYPE_CHAT;
|
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
|
// message stanza id
|
||||||
const char *id = xmpp_stanza_get_id(stanza);
|
const char *id = xmpp_stanza_get_id(stanza);
|
||||||
@ -1256,6 +1286,26 @@ _handle_chat(xmpp_stanza_t *const stanza)
|
|||||||
message_free(message);
|
message_free(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
_handle_mam(xmpp_stanza_t *const stanza)
|
||||||
|
{
|
||||||
|
xmpp_stanza_t *result = stanza_get_child_by_name_and_ns(stanza, "result", STANZA_NS_MAM2);
|
||||||
|
if (!result) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
xmpp_stanza_t *forwarded = xmpp_stanza_get_child_by_ns(result, STANZA_NS_FORWARD);
|
||||||
|
if (!forwarded) {
|
||||||
|
log_warning("MAM received with no forwarded element");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
xmpp_stanza_t *message_stanza = xmpp_stanza_get_child_by_ns(forwarded, "jabber:client");
|
||||||
|
_handle_chat(message_stanza, TRUE);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_send_message_stanza(xmpp_stanza_t *const stanza)
|
_send_message_stanza(xmpp_stanza_t *const stanza)
|
||||||
{
|
{
|
||||||
|
@ -2635,3 +2635,85 @@ stanza_attach_correction(xmpp_ctx_t *ctx, xmpp_stanza_t *stanza, const char *con
|
|||||||
|
|
||||||
return stanza;
|
return stanza;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xmpp_stanza_t*
|
||||||
|
stanza_create_mam_iq(xmpp_ctx_t *ctx, const char *const jid, const char *const startdate)
|
||||||
|
{
|
||||||
|
char *id = connection_create_stanza_id();
|
||||||
|
xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
|
||||||
|
free(id);
|
||||||
|
//xmpp_stanza_set_to(iq, jid);
|
||||||
|
|
||||||
|
xmpp_stanza_t *query = xmpp_stanza_new(ctx);
|
||||||
|
xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
|
||||||
|
xmpp_stanza_set_ns(query, STANZA_NS_MAM2);
|
||||||
|
|
||||||
|
xmpp_stanza_t *x = xmpp_stanza_new(ctx);
|
||||||
|
xmpp_stanza_set_name(x, STANZA_NAME_X);
|
||||||
|
xmpp_stanza_set_ns(x, STANZA_NS_DATA);
|
||||||
|
xmpp_stanza_set_type(x, "submit");
|
||||||
|
|
||||||
|
// field FORM_TYPE MAM2
|
||||||
|
xmpp_stanza_t *field_form_type = xmpp_stanza_new(ctx);
|
||||||
|
xmpp_stanza_set_name(field_form_type, STANZA_NAME_FIELD);
|
||||||
|
xmpp_stanza_set_attribute(field_form_type, STANZA_ATTR_VAR, "FORM_TYPE");
|
||||||
|
xmpp_stanza_set_type(field_form_type, "hidden");
|
||||||
|
|
||||||
|
xmpp_stanza_t *value_mam = xmpp_stanza_new(ctx);
|
||||||
|
xmpp_stanza_set_name(value_mam, STANZA_NAME_VALUE);
|
||||||
|
|
||||||
|
xmpp_stanza_t *mam_text = xmpp_stanza_new(ctx);
|
||||||
|
xmpp_stanza_set_text(mam_text, STANZA_NS_MAM2);
|
||||||
|
xmpp_stanza_add_child(value_mam, mam_text);
|
||||||
|
|
||||||
|
xmpp_stanza_add_child(field_form_type, value_mam);
|
||||||
|
|
||||||
|
// field 'with'
|
||||||
|
xmpp_stanza_t *field_with = xmpp_stanza_new(ctx);
|
||||||
|
xmpp_stanza_set_name(field_with, STANZA_NAME_FIELD);
|
||||||
|
xmpp_stanza_set_attribute(field_with, STANZA_ATTR_VAR, "with");
|
||||||
|
|
||||||
|
xmpp_stanza_t *value_with = xmpp_stanza_new(ctx);
|
||||||
|
xmpp_stanza_set_name(value_with, STANZA_NAME_VALUE);
|
||||||
|
|
||||||
|
xmpp_stanza_t *with_text = xmpp_stanza_new(ctx);
|
||||||
|
xmpp_stanza_set_text(with_text, jid);
|
||||||
|
xmpp_stanza_add_child(value_with, with_text);
|
||||||
|
|
||||||
|
xmpp_stanza_add_child(field_with, value_with);
|
||||||
|
|
||||||
|
// field 'start'
|
||||||
|
xmpp_stanza_t *field_start = xmpp_stanza_new(ctx);
|
||||||
|
xmpp_stanza_set_name(field_start, STANZA_NAME_FIELD);
|
||||||
|
xmpp_stanza_set_attribute(field_start, STANZA_ATTR_VAR, "start");
|
||||||
|
|
||||||
|
xmpp_stanza_t *value_start = xmpp_stanza_new(ctx);
|
||||||
|
xmpp_stanza_set_name(value_start, STANZA_NAME_VALUE);
|
||||||
|
|
||||||
|
xmpp_stanza_t *date_text = xmpp_stanza_new(ctx);
|
||||||
|
xmpp_stanza_set_text(date_text, startdate);
|
||||||
|
xmpp_stanza_add_child(value_start, date_text);
|
||||||
|
|
||||||
|
xmpp_stanza_add_child(field_start, value_start);
|
||||||
|
|
||||||
|
// add and release
|
||||||
|
xmpp_stanza_add_child(iq, query);
|
||||||
|
xmpp_stanza_add_child(query, x);
|
||||||
|
xmpp_stanza_add_child(x, field_form_type);
|
||||||
|
xmpp_stanza_add_child(x, field_with);
|
||||||
|
xmpp_stanza_add_child(x, field_start);
|
||||||
|
|
||||||
|
xmpp_stanza_release(mam_text);
|
||||||
|
xmpp_stanza_release(with_text);
|
||||||
|
xmpp_stanza_release(date_text);
|
||||||
|
xmpp_stanza_release(value_mam);
|
||||||
|
xmpp_stanza_release(value_with);
|
||||||
|
xmpp_stanza_release(value_start);
|
||||||
|
xmpp_stanza_release(field_form_type);
|
||||||
|
xmpp_stanza_release(field_with);
|
||||||
|
xmpp_stanza_release(field_start);
|
||||||
|
xmpp_stanza_release(x);
|
||||||
|
xmpp_stanza_release(query);
|
||||||
|
|
||||||
|
return iq;
|
||||||
|
}
|
||||||
|
@ -202,6 +202,7 @@
|
|||||||
#define STANZA_NS_USER_AVATAR_DATA "urn:xmpp:avatar:data"
|
#define STANZA_NS_USER_AVATAR_DATA "urn:xmpp:avatar:data"
|
||||||
#define STANZA_NS_USER_AVATAR_METADATA "urn:xmpp:avatar:metadata"
|
#define STANZA_NS_USER_AVATAR_METADATA "urn:xmpp:avatar:metadata"
|
||||||
#define STANZA_NS_LAST_MESSAGE_CORRECTION "urn:xmpp:message-correct:0"
|
#define STANZA_NS_LAST_MESSAGE_CORRECTION "urn:xmpp:message-correct:0"
|
||||||
|
#define STANZA_NS_MAM2 "urn:xmpp:mam:2"
|
||||||
|
|
||||||
#define STANZA_DATAFORM_SOFTWARE "urn:xmpp:dataforms:softwareinfo"
|
#define STANZA_DATAFORM_SOFTWARE "urn:xmpp:dataforms:softwareinfo"
|
||||||
|
|
||||||
@ -359,4 +360,6 @@ xmpp_stanza_t* stanza_get_child_by_name_and_ns(xmpp_stanza_t * const stanza, con
|
|||||||
|
|
||||||
xmpp_stanza_t* stanza_create_avatar_retrieve_data_request(xmpp_ctx_t *ctx, const char *stanza_id, const char *const item_id, const char *const jid);
|
xmpp_stanza_t* stanza_create_avatar_retrieve_data_request(xmpp_ctx_t *ctx, const char *stanza_id, const char *const item_id, const char *const jid);
|
||||||
|
|
||||||
|
xmpp_stanza_t* stanza_create_mam_iq(xmpp_ctx_t *ctx, const char *const jid, const char *const startdate);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -69,6 +69,7 @@
|
|||||||
#define XMPP_FEATURE_PUBSUB_PUBLISH_OPTIONS "http://jabber.org/protocol/pubsub#publish-options"
|
#define XMPP_FEATURE_PUBSUB_PUBLISH_OPTIONS "http://jabber.org/protocol/pubsub#publish-options"
|
||||||
#define XMPP_FEATURE_USER_AVATAR_METADATA_NOTIFY "urn:xmpp:avatar:metadata+notify"
|
#define XMPP_FEATURE_USER_AVATAR_METADATA_NOTIFY "urn:xmpp:avatar:metadata+notify"
|
||||||
#define XMPP_FEATURE_LAST_MESSAGE_CORRECTION "urn:xmpp:message-correct:0"
|
#define XMPP_FEATURE_LAST_MESSAGE_CORRECTION "urn:xmpp:message-correct:0"
|
||||||
|
#define XMPP_FEATURE_MAM2 "urn:xmpp:mam:2"
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
JABBER_CONNECTING,
|
JABBER_CONNECTING,
|
||||||
@ -137,7 +138,8 @@ typedef enum {
|
|||||||
} prof_msg_type_t;
|
} prof_msg_type_t;
|
||||||
|
|
||||||
typedef struct prof_message_t {
|
typedef struct prof_message_t {
|
||||||
Jid *jid;
|
Jid *from_jid;
|
||||||
|
Jid *to_jid;
|
||||||
/* regular <message id=""> */
|
/* regular <message id=""> */
|
||||||
char *id;
|
char *id;
|
||||||
/* </origin-id> XEP-0359 */
|
/* </origin-id> XEP-0359 */
|
||||||
@ -154,6 +156,7 @@ typedef struct prof_message_t {
|
|||||||
GDateTime *timestamp;
|
GDateTime *timestamp;
|
||||||
prof_enc_t enc;
|
prof_enc_t enc;
|
||||||
gboolean trusted;
|
gboolean trusted;
|
||||||
|
gboolean is_mam;
|
||||||
prof_msg_type_t type;
|
prof_msg_type_t type;
|
||||||
} ProfMessage;
|
} ProfMessage;
|
||||||
|
|
||||||
@ -237,6 +240,7 @@ void iq_autoping_check(void);
|
|||||||
void iq_http_upload_request(HTTPUpload *upload);
|
void iq_http_upload_request(HTTPUpload *upload);
|
||||||
void iq_command_list(const char *const target);
|
void iq_command_list(const char *const target);
|
||||||
void iq_command_exec(const char *const target, const char *const command);
|
void iq_command_exec(const char *const target, const char *const command);
|
||||||
|
void iq_mam_request(ProfChatWin *win);
|
||||||
|
|
||||||
EntityCapabilities* caps_lookup(const char *const jid);
|
EntityCapabilities* caps_lookup(const char *const jid);
|
||||||
void caps_close(void);
|
void caps_close(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user