diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/QuickMedia.cpp | 12 | ||||
-rw-r--r-- | src/plugins/Matrix.cpp | 55 |
2 files changed, 42 insertions, 25 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index db17982..0c3bb09 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -4144,16 +4144,28 @@ namespace QuickMedia { if(event.type == sf::Event::KeyPressed && event.key.control && event.key.alt && (chat_state == ChatState::NAVIGATING || chat_state == ChatState::URL_SELECTION)) { if(event.key.code == sf::Keyboard::Up || (event.key.control && event.key.code == sf::Keyboard::K)) { room_tabs[room_selected_tab].body->select_previous_item(); + move_room = true; + goto chat_page_end; } else if(event.key.code == sf::Keyboard::Down || (event.key.control && event.key.code == sf::Keyboard::J)) { room_tabs[room_selected_tab].body->select_next_item(); + move_room = true; + goto chat_page_end; } else if(event.key.code == sf::Keyboard::PageUp) { room_tabs[room_selected_tab].body->select_previous_page(); + move_room = true; + goto chat_page_end; } else if(event.key.code == sf::Keyboard::PageDown) { room_tabs[room_selected_tab].body->select_next_page(); + move_room = true; + goto chat_page_end; } else if(event.key.code == sf::Keyboard::Home) { room_tabs[room_selected_tab].body->select_first_item(); + move_room = true; + goto chat_page_end; } else if(event.key.code == sf::Keyboard::End) { room_tabs[room_selected_tab].body->select_last_item(); + move_room = true; + goto chat_page_end; } else if(event.key.code == sf::Keyboard::Escape) { move_room = false; goto chat_page_end; diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp index cc6f673..4b980a0 100644 --- a/src/plugins/Matrix.cpp +++ b/src/plugins/Matrix.cpp @@ -387,24 +387,6 @@ namespace QuickMedia { unread_notifications[room].push_back(std::move(notification)); } - static int find_top_body_position_for_unread_room(const BodyItems &room_body_items, BodyItem *item_to_swap) { - for(int i = 0; i < (int)room_body_items.size(); ++i) { - const auto &body_item = room_body_items[i]; - if(static_cast<RoomData*>(body_item->userdata)->last_message_read || body_item.get() == item_to_swap) - return i; - } - return -1; - } - - static int find_top_body_position_for_mentioned_room(const BodyItems &room_body_items, BodyItem *item_to_swap) { - for(int i = 0; i < (int)room_body_items.size(); ++i) { - const auto &body_item = room_body_items[i]; - if(static_cast<RoomData*>(body_item->userdata)->unread_notification_count == 0 || body_item.get() == item_to_swap) - return i; - } - return -1; - } - static void sort_room_body_items(std::vector<std::shared_ptr<BodyItem>> &room_body_items) { #if 0 std::sort(room_body_items.begin(), room_body_items.end(), [](const std::shared_ptr<BodyItem> &body_item1, const std::shared_ptr<BodyItem> &body_item2) { @@ -500,16 +482,19 @@ namespace QuickMedia { } void MatrixQuickMedia::update_room_description(RoomData *room, Messages &new_messages, bool is_initial_sync, bool sync_is_cache) { - time_t read_marker_message_timestamp = room->read_marker_event_timestamp; + time_t read_marker_message_timestamp = 0; std::shared_ptr<UserInfo> me = matrix->get_me(room); std::string my_user_read_marker; - if(me && read_marker_message_timestamp == 0) { + if(me) { my_user_read_marker = room->get_user_read_marker(me); auto read_marker_message = room->get_message_by_id(my_user_read_marker); if(read_marker_message) read_marker_message_timestamp = read_marker_message->timestamp; } + if(read_marker_message_timestamp == 0 || read_marker_message_timestamp < room->read_marker_event_timestamp) + read_marker_message_timestamp = room->read_marker_event_timestamp; + std::shared_ptr<Message> last_new_message = get_last_message_by_timestamp(new_messages); if(!last_new_message) return; @@ -549,8 +534,8 @@ namespace QuickMedia { room->body_item->set_title_color(sf::Color(255, 100, 100)); room->last_message_read = false; - rooms_page->sort_rooms(); - room_tags_page->sort_rooms(); + rooms_page->move_room_to_top(room); + room_tags_page->move_room_to_top(room); } else if(is_initial_sync) { room->body_item->set_description(matrix->message_get_author_displayname(last_new_message.get()) + ": " + message_to_room_description_text(last_new_message.get())); } @@ -660,7 +645,7 @@ namespace QuickMedia { // Swap order of rooms in body list to put rooms with mentions at the top and then unread messages and then all the other rooms // TODO: Optimize with hash map instead of linear search? or cache the index std::lock_guard<std::mutex> lock(mutex); -#if 1 +#if 0 int room_body_index = body->get_index_by_body_item(room->body_item.get()); if(room_body_index != -1) { std::shared_ptr<BodyItem> body_item = body->items[room_body_index]; @@ -671,14 +656,34 @@ namespace QuickMedia { body_swap_index = find_top_body_position_for_unread_room(body->items, body_item.get()); if(body_swap_index != -1 && body_swap_index != room_body_index) { body->items.erase(body->items.begin() + room_body_index); - if(body_swap_index < room_body_index) + if(body_swap_index <= room_body_index) body->items.insert(body->items.begin() + body_swap_index, std::move(body_item)); else body->items.insert(body->items.begin() + (body_swap_index - 1), std::move(body_item)); } } #else - sort_on_update = true; + int room_body_index = body->get_index_by_body_item(room->body_item.get()); + if(room_body_index == -1) + return; + + //sort_on_update = true; + int selected_item = body->get_selected_item(); + if(room_body_index == selected_item) + return; + + for(size_t i = 0; i < body->items.size(); ++i) { + RoomData *room_i = static_cast<RoomData*>(body->items[i]->userdata); + if((int)i != selected_item && room_i && room->last_message_timestamp > room_i->last_message_timestamp) { + auto body_item_to_insert = body->items[room_body_index]; + body->items.erase(body->items.begin() + room_body_index); + if((int)i <= room_body_index) + body->items.insert(body->items.begin() + i, std::move(body_item_to_insert)); + else + body->items.insert(body->items.begin() + (i - 1), std::move(body_item_to_insert)); + return; + } + } #endif } |