diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/QuickMedia.cpp | 31 | ||||
-rw-r--r-- | src/plugins/Matrix.cpp | 12 |
2 files changed, 27 insertions, 16 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 1caf831..373970a 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -1365,9 +1365,6 @@ namespace QuickMedia { } if(matrix && !matrix->is_initial_sync_finished()) { - load_sprite.setPosition(body_pos.x + body_size.x * 0.5f, body_pos.y + body_size.y * 0.5f); - load_sprite.setRotation(load_sprite_timer.getElapsedTime().asSeconds() * 400.0); - window.draw(load_sprite); std::string err_msg; if(matrix->did_initial_sync_fail(err_msg)) { show_notification("QuickMedia", "Initial matrix sync failed, error: " + err_msg, Urgency::CRITICAL); @@ -3455,12 +3452,24 @@ namespace QuickMedia { tabs[MESSAGES_TAB_INDEX].body->set_page_scroll(window_size.y); + std::unordered_set<Message*> fetched_messages_set; + auto filter_existing_messages = [&fetched_messages_set](Messages &messages) { + for(auto it = messages.begin(); it != messages.end();) { + auto res = fetched_messages_set.insert(it->get()); + if(!res.second) + it = messages.erase(it); + else + ++it; + } + }; + + bool fetch_latest_messages = !matrix->is_initial_sync_finished(); bool initial_prev_messages_fetch = false; - if(num_messages_in_room < 10 && matrix->is_initial_sync_finished()) { + if(num_messages_in_room < 10) { initial_prev_messages_fetch = true; - previous_messages_future = [this, ¤t_room]() { + previous_messages_future = [this, ¤t_room, fetch_latest_messages]() { Messages messages; - if(matrix->get_previous_room_messages(current_room, messages) != PluginResult::OK) + if(matrix->get_previous_room_messages(current_room, messages, fetch_latest_messages) != PluginResult::OK) fprintf(stderr, "Failed to get previous matrix messages in room: %s\n", current_room->id.c_str()); return messages; }; @@ -3619,8 +3628,10 @@ namespace QuickMedia { unreferenced_event_by_room.clear(); - for(auto &body_item : tabs[PINNED_TAB_INDEX].body->items) { - delete (PinnedEventData*)body_item->userdata; + if(!tabs.empty()) { + for(auto &body_item : tabs[PINNED_TAB_INDEX].body->items) { + delete (PinnedEventData*)body_item->userdata; + } } tabs.clear(); @@ -4026,6 +4037,7 @@ namespace QuickMedia { if(previous_messages_future.ready()) { Messages new_messages = previous_messages_future.get(); + filter_existing_messages(new_messages); fprintf(stderr, "Finished fetching older messages, num new messages: %zu\n", new_messages.size()); bool move_to_bottom = false; if(initial_prev_messages_fetch) @@ -4223,9 +4235,6 @@ namespace QuickMedia { } if(matrix && !matrix->is_initial_sync_finished()) { - load_sprite.setPosition(body_pos.x + body_size.x * 0.5f, body_pos.y + body_size.y * 0.5f); - load_sprite.setRotation(load_sprite_timer.getElapsedTime().asSeconds() * 400.0); - window.draw(load_sprite); std::string err_msg; if(matrix->did_initial_sync_fail(err_msg)) { show_notification("QuickMedia", "Initial matrix sync failed, error: " + err_msg, Urgency::CRITICAL); diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp index 2736421..6d0e095 100644 --- a/src/plugins/Matrix.cpp +++ b/src/plugins/Matrix.cpp @@ -20,7 +20,7 @@ static const char* SERVICE_NAME = "matrix"; static const char* OTHERS_ROOM_TAG = "tld.name.others"; -static const char* FILTER = "{\"presence\":{\"limit\":0,\"types\":[\"\"]},\"account_data\":{\"limit\":0,\"types\":[\"\"]},\"room\":{\"state\":{\"not_types\":[\"m.room.related_groups\",\"m.room.power_levels\",\"m.room.join_rules\",\"m.room.history_visibility\"],\"lazy_load_members\":true},\"timeline\":{\"limit\":3,\"lazy_load_members\":true},\"ephemeral\":{\"limit\":0,\"types\":[\"\"],\"lazy_load_members\":true},\"account_data\":{\"limit\":1,\"types\":[\"m.fully_read\",\"m.tag\"],\"lazy_load_members\":true}}}"; +static const char* FILTER = "{\"presence\":{\"limit\":0,\"types\":[\"\"]},\"account_data\":{\"limit\":0,\"types\":[\"\"]},\"room\":{\"state\":{\"not_types\":[\"m.room.related_groups\",\"m.room.power_levels\",\"m.room.join_rules\",\"m.room.history_visibility\"],\"lazy_load_members\":true},\"timeline\":{\"limit\":1,\"lazy_load_members\":true},\"ephemeral\":{\"limit\":0,\"types\":[\"\"],\"lazy_load_members\":true},\"account_data\":{\"limit\":1,\"types\":[\"m.fully_read\",\"m.tag\"],\"lazy_load_members\":true}}}"; static rapidjson::Value nullValue(rapidjson::kNullType); static const rapidjson::Value& GetMember(const rapidjson::Value &obj, const char *key) { @@ -1021,11 +1021,11 @@ namespace QuickMedia { room->release_room_lock(); } - PluginResult Matrix::get_previous_room_messages(RoomData *room, Messages &messages) { + PluginResult Matrix::get_previous_room_messages(RoomData *room, Messages &messages, bool latest_messages) { room->acquire_room_lock(); size_t num_messages_before = room->get_messages_thread_unsafe().size(); room->release_room_lock(); - PluginResult result = get_previous_room_messages(room); + PluginResult result = get_previous_room_messages(room, latest_messages); if(result != PluginResult::OK) return result; @@ -2150,9 +2150,11 @@ namespace QuickMedia { } } - PluginResult Matrix::get_previous_room_messages(RoomData *room_data) { + PluginResult Matrix::get_previous_room_messages(RoomData *room_data, bool latest_messages) { std::string from = room_data->get_prev_batch(); - if(from.empty()) { + if(latest_messages) + from = "END"; + else if(from.empty()) { fprintf(stderr, "Info: missing previous batch for room: %s, using /sync next batch\n", room_data->id.c_str()); // TODO: When caching /sync, remember to add lock around getting next_batch! from = get_next_batch(); |