1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Initial work on last-read-position feature

Print dashes on the position we last left off in a chat window.
So far the number of dashes is hardcoded, and the feature only works in
chat windows.

Regards https://github.com/profanity-im/profanity/issues/1238
This commit is contained in:
Michael Vetter 2019-12-13 12:05:24 +01:00
parent 9bb2d7f95e
commit 14f25992c3
6 changed files with 59 additions and 0 deletions

View File

@ -106,6 +106,19 @@ buffer_append(ProfBuff buffer, const char show_char, int pad_indent, GDateTime *
buffer->entries = g_slist_append(buffer->entries, e);
}
void
buffer_remove_entry_by_id(ProfBuff buffer, const char *const id)
{
GSList *entries = buffer->entries;
while (entries) {
ProfBuffEntry *entry = entries->data;
if (entry->id && (g_strcmp0(entry->id, id) == 0)) {
buffer->entries = g_slist_delete_link(buffer->entries, entries);
}
entries = g_slist_next(entries);
}
}
gboolean
buffer_mark_received(ProfBuff buffer, const char *const id)
{

View File

@ -64,6 +64,7 @@ ProfBuff buffer_create();
void buffer_free(ProfBuff buffer);
void buffer_append(ProfBuff buffer, const char show_char, int pad_indent, GDateTime *time,
int flags, theme_item_t theme_item, const char *const from, const char *const message, DeliveryReceipt *receipt, const char *const id);
void buffer_remove_entry_by_id(ProfBuff buffer, const char *const id);
int buffer_size(ProfBuff buffer);
ProfBuffEntry* buffer_get_entry(ProfBuff buffer, int entry);
ProfBuffEntry* buffer_get_entry_by_id(ProfBuff buffer, const char *const id);

View File

@ -286,6 +286,7 @@ chatwin_incoming_msg(ProfChatWin *chatwin, ProfMessage *message, gboolean win_cr
}
}
win_insert_last_read_position_marker((ProfWin*)chatwin, chatwin->barejid);
win_print_incoming(window, display_name, message);
}

View File

@ -656,6 +656,14 @@ ui_focus_win(ProfWin *window)
cmd_ac_remove_form_fields(confwin->form);
}
// TODO: if old win is chatwin; and has lastreadline; then remove that line
if (old_current->type == WIN_CHAT) {
ProfChatWin *chatwin = (ProfChatWin*)old_current;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
//win_update_entry_message_real(old_current, chatwin->barejid, "$$$");
win_remove_entry_message(old_current, chatwin->barejid);
}
if (window->type == WIN_CONFIG) {
ProfConfWin *confwin = (ProfConfWin*)window;
cmd_ac_add_form_fields(confwin->form);

View File

@ -1354,6 +1354,13 @@ win_update_entry_message(ProfWin *window, const char *const id, const char *cons
}
}
void
win_remove_entry_message(ProfWin *window, const char *const id)
{
buffer_remove_entry_by_id(window->layout->buffer, id);
win_redraw(window);
}
void
win_newline(ProfWin *window)
{
@ -1809,3 +1816,29 @@ win_handle_command_exec_result_note(ProfWin *window, const char *const type, con
assert(window != NULL);
win_println(window, THEME_DEFAULT, '!', value);
}
void
win_print_separator(ProfWin *window)
{
int cols = getmaxx(window->layout->win);
int i;
for (i=1; i<cols; i++) {
wprintw(window->layout->win, "-");
}
}
void
win_insert_last_read_position_marker(ProfWin *window, char* id)
{
GDateTime *time = g_date_time_new_now_local();
buffer_append(window->layout->buffer, ' ', 0, time, 0, THEME_TEXT, NULL, "-----", NULL, id);
// can we leave this? TODO
// win_print_separator(window);
//_win_print(window, '-', 0, time, 0, THEME_TEXT, NULL, "---", NULL);
win_redraw(window);
g_date_time_unref(time);
}

View File

@ -90,4 +90,7 @@ void win_page_down(ProfWin *window);
void win_sub_page_down(ProfWin *window);
void win_sub_page_up(ProfWin *window);
void win_insert_last_read_position_marker(ProfWin *window, char* id);
void win_remove_entry_message(ProfWin *window, const char *const id);
#endif