aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Body.cpp6
-rw-r--r--src/QuickMedia.cpp41
-rw-r--r--src/plugins/Matrix.cpp9
3 files changed, 43 insertions, 13 deletions
diff --git a/src/Body.cpp b/src/Body.cpp
index 9eb3c98..b21012d 100644
--- a/src/Body.cpp
+++ b/src/Body.cpp
@@ -1649,19 +1649,19 @@ namespace QuickMedia {
if(item->author_text) {
item->author_text->set_position(text_pos);
item->author_text->draw(window);
- text_offset_y += item->author_text->getHeight() + std::floor(5.0f * get_config().scale);
+ text_offset_y += item->author_text->getHeight() + std::floor(3.0f * get_config().scale);
}
if(item->title_text) {
item->title_text->set_position(text_pos + mgl::vec2f(0.0f, text_offset_y));
item->title_text->draw(window);
- text_offset_y += item->title_text->getHeight() + std::floor(5.0f * get_config().scale);
+ text_offset_y += item->title_text->getHeight() + std::floor(3.0f * get_config().scale);
}
if(item->description_text) {
item->description_text->set_position(text_pos + mgl::vec2f(0.0f, text_offset_y));
item->description_text->draw(window);
- text_offset_y += item->description_text->getHeight() + std::floor(5.0f * get_config().scale);
+ text_offset_y += item->description_text->getHeight() + std::floor(3.0f * get_config().scale);
}
const float gradient_height = 5.0f;
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 74cd4a1..ea74c09 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -6214,6 +6214,7 @@ namespace QuickMedia {
Messages messages;
MessageDirection message_dir;
bool reached_end = false;
+ bool success = true;
};
AsyncTask<FetchMessagesResult> fetch_messages_future;
MessageDirection fetch_messages_dir = MessageDirection::BEFORE;
@@ -6739,49 +6740,68 @@ namespace QuickMedia {
move_room = true;
};
- std::function<void()> on_top_reached = [this, &fetch_messages_future, &fetch_messages_dir, &ui_tabs, &MESSAGES_TAB_INDEX, &gradient_inc, current_room, &before_token, &after_token, &fetched_enough_messages_top] {
+ mgl::Clock fetch_previous_messages_retry_timer;
+ double fetch_previous_messages_timeout = 0.0;
+
+ std::function<void()> on_top_reached = [&] {
const int selected_tab = ui_tabs.get_selected();
if(fetched_enough_messages_top || fetch_messages_future.valid() || selected_tab != MESSAGES_TAB_INDEX)
return;
+ if(fetch_previous_messages_retry_timer.get_elapsed_time_seconds() < fetch_previous_messages_timeout)
+ return;
+
+ fetch_previous_messages_retry_timer.restart();
gradient_inc = 0;
if(before_token.empty() && after_token.empty()) {
fetch_messages_dir = MessageDirection::BEFORE;
- fetch_messages_future = AsyncTask<FetchMessagesResult>([this, current_room]() {
+ fetch_messages_future = AsyncTask<FetchMessagesResult>([&]() {
FetchMessagesResult messages;
messages.message_dir = MessageDirection::BEFORE;
messages.reached_end = false;
- if(matrix->get_previous_room_messages(current_room, messages.messages, false, &messages.reached_end) != PluginResult::OK)
+ if(matrix->get_previous_room_messages(current_room, messages.messages, false, &messages.reached_end) != PluginResult::OK) {
fprintf(stderr, "Failed to get previous matrix messages in room: %s\n", current_room->id.c_str());
+ messages.success = false;
+ } else {
+ messages.success = true;
+ }
return messages;
});
} else if(!before_token.empty()) {
fetch_messages_dir = MessageDirection::BEFORE;
- fetch_messages_future = AsyncTask<FetchMessagesResult>([this, current_room, &before_token]() {
+ fetch_messages_future = AsyncTask<FetchMessagesResult>([&]() {
std::string token = before_token;
FetchMessagesResult messages;
messages.message_dir = MessageDirection::BEFORE;
messages.reached_end = false;
- if(matrix->get_messages_in_direction(current_room, token, MessageDirection::BEFORE, messages.messages, before_token) != PluginResult::OK)
+ if(matrix->get_messages_in_direction(current_room, token, MessageDirection::BEFORE, messages.messages, before_token) != PluginResult::OK) {
fprintf(stderr, "Failed to get previous matrix messages in room: %s\n", current_room->id.c_str());
+ messages.success = false;
+ } else {
+ messages.success = true;
+ }
messages.reached_end = before_token.empty();
return messages;
});
}
};
- std::function<void()> on_bottom_reached = [this, &fetch_messages_future, &fetch_messages_dir, &ui_tabs, &MESSAGES_TAB_INDEX, &gradient_inc, current_room, &after_token, &fetched_enough_messages_bottom] {
+ std::function<void()> on_bottom_reached = [&] {
const int selected_tab = ui_tabs.get_selected();
if(!fetched_enough_messages_bottom && !after_token.empty() && !fetch_messages_future.valid() && selected_tab == MESSAGES_TAB_INDEX) {
fetch_messages_dir = MessageDirection::AFTER;
gradient_inc = 0;
- fetch_messages_future = AsyncTask<FetchMessagesResult>([this, current_room, &after_token]() {
+ fetch_messages_future = AsyncTask<FetchMessagesResult>([&]() {
std::string token = after_token;
FetchMessagesResult messages;
messages.message_dir = MessageDirection::AFTER;
messages.reached_end = false;
- if(matrix->get_messages_in_direction(current_room, token, MessageDirection::AFTER, messages.messages, after_token) != PluginResult::OK)
+ if(matrix->get_messages_in_direction(current_room, token, MessageDirection::AFTER, messages.messages, after_token) != PluginResult::OK) {
fprintf(stderr, "Failed to get next matrix messages in room: %s\n", current_room->id.c_str());
+ messages.success = false;
+ } else {
+ messages.success = true;
+ }
messages.reached_end = after_token.empty();
return messages;
});
@@ -7425,6 +7445,11 @@ namespace QuickMedia {
FetchMessagesResult new_messages_result = fetch_messages_future.get();
all_messages.insert(all_messages.end(), new_messages_result.messages.begin(), new_messages_result.messages.end());
+ if(new_messages_result.success)
+ fetch_previous_messages_timeout = 0.0;
+ else
+ fetch_previous_messages_timeout = 4.0;
+
if(new_messages_result.message_dir == MessageDirection::BEFORE)
fetched_enough_messages_top = new_messages_result.reached_end;
if(new_messages_result.message_dir == MessageDirection::AFTER)
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index 6e6264f..75e293a 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -3719,7 +3719,7 @@ namespace QuickMedia {
const rapidjson::Value &end_json = GetMember(json_root, "end");
if(!end_json.IsString()) {
- room_data->set_prev_batch("invalid");
+ room_data->set_prev_batch("");
fprintf(stderr, "Warning: matrix messages response is missing 'end', this could happen if we received the very first messages in the room\n");
if(reached_end)
*reached_end = true;
@@ -4970,7 +4970,12 @@ namespace QuickMedia {
}
const rapidjson::Value &errcode_json = GetMember(json_root, "errcode");
- if(errcode_json.IsString() && strcmp(errcode_json.GetString(), "M_NOT_FOUND") != 0) {
+ if(errcode_json.IsString()) {
+ // This is the case if the room has never set pinned events.
+ // After a pinned event has added and then removed so the list is empty then an empty list is returned instead.
+ if(strcmp(errcode_json.GetString(), "M_NOT_FOUND") == 0)
+ return PluginResult::OK;
+
const rapidjson::Value &error_json = GetMember(json_root, "error");
if(error_json.IsString()) {
show_notification("QuickMedia", "Failed to get pinned events for room " + room->id + ", error: " + std::string(error_json.GetString(), error_json.GetStringLength()), Urgency::CRITICAL);