From 07c8a8f1d469672be5196570608cf0d14b4d5b21 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 9 Feb 2021 10:38:39 +0100 Subject: Matrix: test: only show m.room.message types in room list description, sort room list by activity, improve initial sync time --- src/QuickMedia.cpp | 42 ++++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 24 deletions(-) (limited to 'src/QuickMedia.cpp') diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 551da5e..552ceae 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -3740,11 +3740,28 @@ namespace QuickMedia { }; // TODO: How about instead fetching all messages we have, not only the visible ones? also fetch with multiple threads. - tabs[MESSAGES_TAB_INDEX].body->body_item_render_callback = [this, ¤t_room, &me, &fetch_message_future, &tabs, &fetch_message, &find_body_item_by_event_id, &fetch_body_item, &fetch_message_tab](BodyItem *body_item) { + tabs[MESSAGES_TAB_INDEX].body->body_item_render_callback = [this, ¤t_room, &me, &fetch_message_future, &tabs, &is_window_focused, &chat_state, &setting_read_marker, &read_marker_timer, &read_marker_timeout_ms, &set_read_marker_future, &find_body_item_by_event_id, &fetch_body_item, &fetch_message_tab](BodyItem *body_item) { Message *message = static_cast(body_item->userdata); if(!message) return; + if(message->type >= MessageType::TEXT && message->type <= MessageType::FILE && is_window_focused && chat_state != ChatState::URL_SELECTION && !setting_read_marker && read_marker_timer.getElapsedTime().asMilliseconds() >= read_marker_timeout_ms) { + // TODO: What if two messages have the same timestamp? + if(message && !message->event_id.empty() && message->timestamp > current_room->last_read_message_timestamp) { + //read_marker_timeout_ms = read_marker_timeout_ms_default; + current_room->last_read_message_timestamp = message->timestamp; + // TODO: What if the message is no longer valid? + setting_read_marker = true; + RoomData *room = current_room; + std::string event_id = message->event_id; + set_read_marker_future = [this, room, event_id]() mutable { + if(matrix->set_read_marker(room, event_id) != PluginResult::OK) { + fprintf(stderr, "Warning: failed to set read marker to %s\n", event_id.c_str()); + } + }; + } + } + #if 0 if(message->user->resolve_state == UserResolveState::NOT_RESOLVED) { fetch_message = message; @@ -4745,29 +4762,6 @@ namespace QuickMedia { } } - if(selected_tab == MESSAGES_TAB_INDEX && current_room && matrix->is_initial_sync_finished()) { - BodyItem *last_visible_item = tabs[selected_tab].body->get_last_fully_visible_item(); - if(last_visible_item && tabs[selected_tab].body->is_last_item_fully_visible() && !tabs[selected_tab].body->items.empty()) - last_visible_item = tabs[selected_tab].body->items.back().get(); - if(is_window_focused && chat_state != ChatState::URL_SELECTION && current_room && last_visible_item && !setting_read_marker && read_marker_timer.getElapsedTime().asMilliseconds() >= read_marker_timeout_ms) { - Message *message = (Message*)last_visible_item->userdata; - // TODO: What if two messages have the same timestamp? - if(message && !message->event_id.empty() && message->timestamp > current_room->last_read_message_timestamp) { - //read_marker_timeout_ms = read_marker_timeout_ms_default; - current_room->last_read_message_timestamp = message->timestamp; - // TODO: What if the message is no longer valid? - setting_read_marker = true; - RoomData *room = current_room; - std::string event_id = message->event_id; - set_read_marker_future = [this, room, event_id]() mutable { - if(matrix->set_read_marker(room, event_id) != PluginResult::OK) { - fprintf(stderr, "Warning: failed to set read marker to %s\n", event_id.c_str()); - } - }; - } - } - } - if(selected_tab == MESSAGES_TAB_INDEX && current_room) { window.draw(chat_input_shade); chat_input.draw(window); //chat_input.draw(window, false); -- cgit v1.2.3