Merge MAM improvements from #1724
I think this PR already solves and improves the MAM situation a lot. What's @MarcoPolo-PasTonMolo still wanted to do in this branch is: * MAM for mucs * Check if url and quotes autocompletion works fine * Check if the api still works fine * Resolve conflicts Conflicts are solved with this commit. MAM for mucs can be another feature PR. The rest we can check while being on master. And more people can help testing.
This commit is contained in:
@@ -96,7 +96,7 @@ chatwin_new(const char* const barejid)
|
||||
ProfWin* window = wins_new_chat(barejid);
|
||||
ProfChatWin* chatwin = (ProfChatWin*)window;
|
||||
|
||||
if (!prefs_get_boolean(PREF_MAM) && 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);
|
||||
}
|
||||
|
||||
@@ -146,7 +146,8 @@ chatwin_new(const char* const barejid)
|
||||
}
|
||||
|
||||
if (prefs_get_boolean(PREF_MAM)) {
|
||||
iq_mam_request(chatwin);
|
||||
iq_mam_request(chatwin, NULL);
|
||||
win_print_loading_history(window);
|
||||
}
|
||||
|
||||
return chatwin;
|
||||
@@ -333,7 +334,7 @@ chatwin_incoming_msg(ProfChatWin* chatwin, ProfMessage* message, gboolean win_cr
|
||||
free(mybarejid);
|
||||
|
||||
gboolean is_current = wins_is_current(window);
|
||||
gboolean notify = prefs_do_chat_notify(is_current);
|
||||
gboolean notify = prefs_do_chat_notify(is_current) && !message->is_mam;
|
||||
|
||||
// currently viewing chat window with sender
|
||||
if (wins_is_current(window)) {
|
||||
@@ -344,14 +345,17 @@ chatwin_incoming_msg(ProfChatWin* chatwin, ProfMessage* message, gboolean win_cr
|
||||
// not currently viewing chat window with sender
|
||||
} else {
|
||||
status_bar_new(num, WIN_CHAT, chatwin->barejid);
|
||||
cons_show_incoming_message(display_name, num, chatwin->unread, window);
|
||||
|
||||
if (prefs_get_boolean(PREF_FLASH)) {
|
||||
flash();
|
||||
if (!message->is_mam) {
|
||||
cons_show_incoming_message(display_name, num, chatwin->unread, window);
|
||||
|
||||
if (prefs_get_boolean(PREF_FLASH)) {
|
||||
flash();
|
||||
}
|
||||
|
||||
chatwin->unread++;
|
||||
}
|
||||
|
||||
chatwin->unread++;
|
||||
|
||||
// TODO: so far we don't ask for MAM when incoming message occurs.
|
||||
// Need to figure out:
|
||||
// 1) only send IQ once
|
||||
@@ -379,7 +383,7 @@ chatwin_incoming_msg(ProfChatWin* chatwin, ProfMessage* message, gboolean win_cr
|
||||
wins_add_urls_ac(window, message);
|
||||
wins_add_quotes_ac(window, message->plain);
|
||||
|
||||
if (prefs_get_boolean(PREF_BEEP)) {
|
||||
if (prefs_get_boolean(PREF_BEEP) && !message->is_mam) {
|
||||
beep();
|
||||
}
|
||||
|
||||
@@ -572,7 +576,7 @@ static void
|
||||
_chatwin_history(ProfChatWin* chatwin, const char* const contact_barejid)
|
||||
{
|
||||
if (!chatwin->history_shown) {
|
||||
GSList* history = log_database_get_previous_chat(contact_barejid);
|
||||
GSList* history = log_database_get_previous_chat(contact_barejid, NULL, NULL, FALSE, FALSE);
|
||||
GSList* curr = history;
|
||||
|
||||
while (curr) {
|
||||
@@ -591,6 +595,41 @@ _chatwin_history(ProfChatWin* chatwin, const char* const contact_barejid)
|
||||
}
|
||||
}
|
||||
|
||||
// Print history starting from start_time to end_time if end_time is null the
|
||||
// first entry's timestamp in the buffer is used. Flip true to prepend to buffer.
|
||||
// Timestamps should be in iso8601
|
||||
gboolean
|
||||
chatwin_db_history(ProfChatWin* chatwin, char* start_time, char* end_time, gboolean flip)
|
||||
{
|
||||
if (!end_time) {
|
||||
end_time = buffer_size(((ProfWin*)chatwin)->layout->buffer) == 0 ? NULL : g_date_time_format_iso8601(buffer_get_entry(((ProfWin*)chatwin)->layout->buffer, 0)->time);
|
||||
}
|
||||
|
||||
GSList* history = log_database_get_previous_chat(chatwin->barejid, start_time, end_time, !flip, flip);
|
||||
gboolean has_items = g_slist_length(history) != 0;
|
||||
GSList* curr = history;
|
||||
|
||||
while (curr) {
|
||||
ProfMessage* msg = curr->data;
|
||||
char* msg_plain = msg->plain;
|
||||
msg->plain = plugins_pre_chat_message_display(msg->from_jid->barejid, msg->from_jid->resourcepart, msg->plain);
|
||||
// This is dirty workaround for memory leak. We reassign msg->plain above so have to free previous object
|
||||
// TODO: Make a better solution, for example, pass msg object to the function and it will replace msg->plain properly if needed.
|
||||
free(msg_plain);
|
||||
if (flip) {
|
||||
win_print_old_history((ProfWin*)chatwin, msg);
|
||||
} else {
|
||||
win_print_history((ProfWin*)chatwin, msg);
|
||||
}
|
||||
curr = g_slist_next(curr);
|
||||
}
|
||||
|
||||
g_slist_free_full(history, (GDestroyNotify)message_free);
|
||||
win_redraw((ProfWin*)chatwin);
|
||||
|
||||
return has_items;
|
||||
}
|
||||
|
||||
static void
|
||||
_chatwin_set_last_message(ProfChatWin* chatwin, const char* const id, const char* const message)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user